asciidoctor / asciidoctor-maven-plugin

A Maven plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
http://asciidoctor.org
Apache License 2.0
318 stars 122 forks source link

Missing breadcrumb name in maven site module #763

Closed abelsromero closed 8 months ago

abelsromero commented 8 months ago

Thank you for taking your time to talk with us!

What is this issue about?

Description

When enabling breadcumbs in a maven site, the name for the current page is not present. image

The expected behauviour should be similar to:

image

Environment information

abelsromero commented 8 months ago

Some reverse engineering from the maven-site-plugin documentation shows, that information must come from the metadata encoded in the same document. For the site plugin the APT module uses the document title which is the document header https://github.com/apache/maven-site-plugin/blob/d78b8da70fd186738707f14166812d721064b766/src/site/apt/examples/adding-deploy-protocol.apt.vm#L2.

Note that the breadcrumb configuration is inherited from https://github.com/apache/maven-parent/blob/e1bc57ba6a9b1ac220d810af9d7301b8a95f0806/src/site/site.xml#L65-L68. To test in isolation those elements and fluido config need to be added to a local project.

We can take the opportunity to also add the other metadata https://github.com/apache/maven-doxia/blob/4eda5adb3c9010131ac1f9118d8ed6c262883762/doxia-sink-api/src/main/java/org/apache/maven/doxia/sink/Sink.java#L162-L176.

abelsromero commented 8 months ago

For a possible approach for the asciidoctor plugin we can use asciidoctor.load() to obtain the source metadata and pass it to the sink, the issue is that we'll be effectively parsing the documents twice with a significant performance cost.

sink.head();
sink.title();
sink.text("Example Manual");
sink.title_();
sink.head_();
mojavelinux commented 8 months ago

Fortunately, there is a trick to avoid this overhead. First, you can set the :parse_header_only option to restrict the parsing to the document header. (See https://docs.asciidoctor.org/asciidoctor/latest/api/options/). Another trick you can use is to try to detect the end of the header and split the source so the parser only has to read the lines from the header. We use this trick in Antora. See https://gitlab.com/antora/antora/-/blob/main/packages/asciidoc-loader/lib/load-asciidoc.js?ref_type=heads#L72-77 However, that trick does impose some restrictions on how the document is formatted and may not be appropriate. You'll need to decide whether it is worth it.

abelsromero commented 8 months ago

You'll need to decide whether it is worth it.

I like the idea of splitting the header. The issue is the parse receives an InputStreamReader so we'd need to see how to extract the data without impacting the conversion or duplicating buffers.

Also, note to future self, we'd need to pass options and attributes to load in case the user is composing that data into other attributes like title.

abelsromero commented 8 months ago

PR is ready https://github.com/asciidoctor/asciidoctor-maven-plugin/pull/769. Still on plan to release tomorrow.

abelsromero commented 8 months ago

@kriegaex v2.2.6 is out, thanks for the report and the research.

kriegaex commented 8 months ago

I upgraded, and it works. Thank you so much.

abelsromero commented 8 months ago

Moving this to 3.0.0. The fix for 2.2.6 was already done in a way that can be easily ported.