[英]How to retrieve the name of the file being rendered by "mvn site" in site.vm?
我正在创建一个 Maven 皮肤(参见https://maven.apache.org/doxia/doxia-sitetools/doxia-site-renderer/ )。
如果链接是正在呈现的当前文件,我的site.vm需要突出显示导航栏中的链接。
因此,我需要知道site.vm正在呈现的 HTML 文件的名称。
$currentFileName和$alignedFileName宏适用于常规文档(例如,来自 Markdown 源)。 但是对于多页文档,就像 Maven 报告插件会生成的那样,这些宏会不断返回报告主页面的名称,而不是正在呈现的页面。
如何检索正在呈现的文件的实际名称,而不仅仅是 Maven 报告插件的主 HTML 页面的名称?
我尝试了以下宏但没有运气:
$alignedFileName
$currentFileName
$docRenderingContext.getInputName()
$docRenderingContext.getOutputName()
它们都返回相同的值,即 Maven Report 插件主页的 HTML 文件名。
KmReference.java (Maven 报告插件,使用getSinkFactory().createSink(outputDirectory, pageFilename)创建多个页面):
public class KmReference extends AbstractMavenReport {
public String getOutputName() {
return "km-reference";
}
…
@Override
protected void executeReport(Locale locale) throws MavenReportException {
…
// Create a new sink!
Sink kmSink;
try {
kmSink = getSinkFactory().createSink(outputDirectory, pageFilename);
} catch (IOException e) {
throw new MavenReportException("Could not create sink for " + pageFilename + " in " + outputDirectory.getAbsolutePath(), e);
}
site.vm (速度):
alignedFileName = $alignedFileName
currentFileName = $currentFileName
getDoxiaSourcePath() = $docRenderingContext.getDoxiaSourcePath()
getGenerator() = $docRenderingContext.getGenerator()
getInputName() = $docRenderingContext.getInputName()
getOutputName() = $docRenderingContext.getOutputName()
getParserId() = $docRenderingContext.getParserId()
getRelativePath() = $docRenderingContext.getRelativePath()
在我的 Maven 报告插件生成的所有 HTML 文件中,我将获得完全相同的值:
another-page.html (不是 km-reference.html):
alignedFileName = km-reference.html
currentFileName = km-reference.html
getDoxiaSourcePath() = $docRenderingContext.getDoxiaSourcePath()
getGenerator() = com.sentrysoftware.maven:patrolreport-maven-plugin:2.0:km-reference
getInputName() = km-reference.html
getOutputName() = km-reference.html
getParserId() = $docRenderingContext.getParserId()
getRelativePath() = .
我希望至少$alignedFileName返回值another-page.html 。
这个问题 ( https://issues.apache.org/jira/browse/MSITE-842 ) 已经通过 OP 提供的 PR 解决了。
这是maven-site-plugin Maven 插件(执行“mvn site”时运行的插件)中的一个错误。
它已在插件的 3.8 版中得到修复(在撰写本文时尚未发布)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.