Skip to content

Commit

Permalink
Refactor Head Parsing to ease porting to main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero committed Feb 9, 2024
1 parent 589b744 commit 4683ee3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 27 deletions.
11 changes: 6 additions & 5 deletions docs/modules/site-integration/pages/exposed-metadata.adoc
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
= Exposed metadata
:asciidoctor-docs-url: https://docs.asciidoctor.org/asciidoc/latest
:maven-site-plugin-docs-url: https://maven.apache.org/plugins/maven-site-plugin

The Asciidoctor Maven Site integration integrates with Doxia to expose some of its information.
The Asciidoctor Maven Site integration collaborates with Doxia to expose some of its information.

== Document Header metadata

The following information from the {asciidoctor-docs-url}/document/header/[header] is extracted:
The following elements from the {asciidoctor-docs-url}/document/header/[header] are integrated:

document title:: used to inform the breadcrumb line when these are enabled.
document title:: used to inform the {maven-site-plugin-docs-url}/examples/sitedescriptor.html#Breadcrumbs[breadcrumb] line when these are enabled.

author(s):: full representation (full name and email) will be present as HTML `<meta name="author" ... >` tags inside the HTML `<head>`.
In case of multiple authors, each one will appear in a distinct meta element.
In case of multiple authors, each one will appear in a distinct `meta` element.

revision date:: the header revision date value wll be presented as-is in a `<meta name="date" ... >` element.
revision date:: the header revision date value will be presented as-is in a `<meta name="date" ... >` element.
Alternatively, if not set, the generated value of `docdatetime` will be used.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import org.apache.maven.doxia.parser.Parser;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.project.MavenProject;
import org.asciidoctor.*;
import org.asciidoctor.ast.Author;
import org.asciidoctor.Asciidoctor;
import org.asciidoctor.AttributesBuilder;
import org.asciidoctor.OptionsBuilder;
import org.asciidoctor.SafeMode;
import org.asciidoctor.maven.log.LogHandler;
import org.asciidoctor.maven.log.LogRecordFormatter;
import org.asciidoctor.maven.log.LogRecordsProcessors;
import org.asciidoctor.maven.log.MemoryLogHandler;
import org.asciidoctor.maven.site.SiteConverter.HeaderMetadata;
import org.asciidoctor.maven.site.SiteConverter.Result;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.IOUtil;
Expand All @@ -22,7 +23,6 @@
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.Optional;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -90,28 +90,12 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept
throw new ParseException(exception.getMessage(), exception);
}

sinkHeader(sink, headerMetadata.getHeaderMetadata());
new HeadParser(sink)
.parse(headerMetadata.getHeaderMetadata());

sink.rawText(headerMetadata.getHtml());
}

private static void sinkHeader(Sink sink, HeaderMetadata headerMetadata) {
sink.head();
sink.title();
sink.text(Optional.ofNullable(headerMetadata.getTitle()).orElse("[Untitled]"));
sink.title_();

for (String author : headerMetadata.getAuthors()) {
sink.author();
sink.text(author.toString());
sink.author_();
}

sink.date();
sink.text(headerMetadata.getDateTime());
sink.date_();
sink.head_();
}

private MemoryLogHandler asciidoctorLoggingSetup(Asciidoctor asciidoctor, LogHandler logHandler, File siteDirectory) {

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/org/asciidoctor/maven/site/HeadParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.asciidoctor.maven.site;

import org.apache.maven.doxia.sink.Sink;

import java.util.Optional;

class HeadParser {

private final Sink sink;

HeadParser(Sink sink) {
this.sink = sink;
}

void parse(SiteConverter.HeaderMetadata headerMetadata) {
sink.head();
sink.title();
sink.text(Optional.ofNullable(headerMetadata.getTitle()).orElse("[Untitled]"));
sink.title_();

for (String author : headerMetadata.getAuthors()) {
sink.author();
sink.text(author.toString());
sink.author_();
}

sink.date();
sink.text(headerMetadata.getDateTime());
sink.date_();
sink.head_();
}
}

0 comments on commit 4683ee3

Please sign in to comment.