简体   繁体   English

如何在site.vm中检索“mvn site”正在呈现的文件的名称?

[英]How to retrieve the name of the file being rendered by "mvn site" in site.vm?

I'm creating a Maven Skin (see https://maven.apache.org/doxia/doxia-sitetools/doxia-site-renderer/ ).我正在创建一个 Maven 皮肤(参见https://maven.apache.org/doxia/doxia-sitetools/doxia-site-renderer/ )。

My site.vm needs to highlight links in a nav bar if the link is the current file being rendered.如果链接是正在呈现的当前文件,我的site.vm需要突出显示导航栏中的链接。

I therefore need to know the name of the HTML file that site.vm is rendering.因此,我需要知道site.vm正在呈现的 HTML 文件的名称。

The $currentFileName and $alignedFileName macros work just fine for regular documents (from Markdown source, for example). $currentFileName$alignedFileName宏适用于常规文档(例如,来自 Markdown 源)。 But for multi-pages documents, like a Maven Report plugin would generate, these macros keep returning the name of main page of the report, rather than the page being rendered.但是对于多页文档,就像 Maven 报告插件会生成的那样,这些宏会不断返回报告主页面的名称,而不是正在呈现的页面。

How to retrieve the actual name of the file being rendered, and not just the name of the main HTML page of a Maven Report plugin?如何检索正在呈现的文件的实际名称,而不仅仅是 Maven 报告插件的主 HTML 页面的名称?

I tried the following macros with no luck:我尝试了以下宏但没有运气:

  • $alignedFileName
  • $currentFileName
  • $docRenderingContext.getInputName()
  • $docRenderingContext.getOutputName()

They all return the same value, which is the HTML filename of the main page of the Maven Report plugin.它们都返回相同的值,即 Maven Report 插件主页的 HTML 文件名。

KmReference.java (Maven Report plugin, creating several pages with getSinkFactory().createSink(outputDirectory, pageFilename) ): 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 (Velocity): site.vm (速度):

alignedFileName = $alignedFileName

currentFileName = $currentFileName

getDoxiaSourcePath() = $docRenderingContext.getDoxiaSourcePath()

getGenerator() = $docRenderingContext.getGenerator()

getInputName() = $docRenderingContext.getInputName()

getOutputName() = $docRenderingContext.getOutputName()

getParserId() = $docRenderingContext.getParserId()

getRelativePath() = $docRenderingContext.getRelativePath()

In all HTML files generated by my Maven Report plugin, I will get the exact same values:在我的 Maven 报告插件生成的所有 HTML 文件中,我将获得完全相同的值:

another-page.html (not km-reference.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() = .

I would expect at least $alignedFileName to return the value another-page.html .我希望至少$alignedFileName返回值another-page.html

这个问题 ( https://issues.apache.org/jira/browse/MSITE-842 ) 已经通过 OP 提供的 PR 解决了。

This was a bug in the maven-site-plugin Maven plugin (the one that runs when you execute "mvn site").这是maven-site-plugin Maven 插件(执行“mvn site”时运行的插件)中的一个错误。

It has been fixed in version 3.8 of the plugin (which hasn't been released yet, at the time of writing).它已在插件的 3.8 版中得到修复(在撰写本文时尚未发布)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM