-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Set document title, author(s) and date for Maven site integration fixes #763 --------- Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
- Loading branch information
1 parent
8aae0db
commit 2821df1
Showing
12 changed files
with
495 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
* Maven Site Integration | ||
** xref:introduction.adoc[] | ||
** xref:setup-and-configuration.adoc[] | ||
** xref:exposed-metadata.adoc[] | ||
** xref:compatibility-matrix.adoc[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 collaborates with Doxia to expose some of its information. | ||
|
||
== Document Header metadata | ||
|
||
The following elements from the {asciidoctor-docs-url}/document/header/[header] are integrated: | ||
|
||
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. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/it/maven-site-plugin/src/site/asciidoc/file-with-toc.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
= File with TOC | ||
The Author | ||
:docdatetime: 2024-02-07 23:36:29 | ||
:toc: | ||
|
||
[.lead] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import java.nio.charset.StandardCharsets | ||
import java.nio.file.Files | ||
import java.util.regex.Pattern | ||
|
||
File outputDir = new File(basedir, "target/site") | ||
|
||
String[] expectedFiles = [ | ||
"file-with-toc.html" | ||
] | ||
|
||
String[] unexpectedFiles = [ | ||
"_include.html" | ||
] | ||
|
||
class PatternCapturer { | ||
|
||
private final Pattern pattern | ||
private final List<String> hits | ||
|
||
PatternCapturer(String pattern) { | ||
this.pattern = Pattern.compile(pattern) | ||
this.hits = new ArrayList() | ||
} | ||
|
||
|
||
String tryMatches(String text) { | ||
def matcher = pattern.matcher(text) | ||
if (matcher.matches()) { | ||
def group = matcher.group(1) | ||
hits.add(group) | ||
return group | ||
} | ||
return null | ||
} | ||
|
||
void remove(String text) { | ||
hits.remove(text) | ||
} | ||
|
||
int size() { | ||
return hits.size() | ||
} | ||
|
||
List<String> getHits() { | ||
return hits | ||
} | ||
} | ||
|
||
for (String expectedFile : expectedFiles) { | ||
File file = new File(outputDir, expectedFile) | ||
System.out.println("Checking for presence of $file") | ||
if (!file.exists() || !file.isFile()) { | ||
throw new Exception("Missing file $file") | ||
} | ||
|
||
def lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8) | ||
System.out.println("Ensuring IDs match TOC links") | ||
|
||
// == Assert TOC == | ||
def tocEntryCapturer = new PatternCapturer("<li><a href=\"#(.*?)\">.*") | ||
def elementIdCapturer = new PatternCapturer(".* id=\"(.*?)\".*") | ||
|
||
for (String line : lines) { | ||
tocEntryCapturer.tryMatches(line) | ||
|
||
String match = elementIdCapturer.tryMatches(line) | ||
if (match != null) { | ||
tocEntryCapturer.remove(match) | ||
} | ||
} | ||
if (tocEntryCapturer.size() != 0) { | ||
throw new Exception("Couldn't find matching IDs for the following TOC entries: ${tocEntryCapturer.getHits()}") | ||
} | ||
|
||
// == Assert includes == | ||
boolean includeResolved = false | ||
boolean sourceHighlighted = false | ||
|
||
for (String line : lines) { | ||
if (!includeResolved && line.contains("Content included from the file ")) { | ||
includeResolved = true | ||
} else if (!sourceHighlighted && line.contains("<span style=\"color:#070;font-weight:bold\"><plugin></span>")) { | ||
sourceHighlighted = true; | ||
} | ||
} | ||
if (!includeResolved) { | ||
throw new Exception("Include file was not resolved") | ||
} | ||
if (!sourceHighlighted) { | ||
throw new Exception("Source code was not highlighted") | ||
} | ||
|
||
// validate that maven properties are replaced same as attributes | ||
boolean foundReplacement = false | ||
for (String line : lines) { | ||
if (line.contains("v1.2.3")) { | ||
foundReplacement = true | ||
break | ||
} | ||
} | ||
if (!foundReplacement) { | ||
throw new Exception("Maven properties not replaced") | ||
} | ||
|
||
// == Assert header metadata == | ||
def metaPattern = Pattern.compile( "<meta name=\"(author|date)\" content=\"(.*)\" />") | ||
boolean headFound = false | ||
Map<String,String> metaTags = new HashMap<>() | ||
|
||
for (String line : lines) { | ||
if (!headFound) { | ||
headFound = line.endsWith("<head>") | ||
continue | ||
} | ||
if (line.endsWith("</head>")) break | ||
def matcher = metaPattern.matcher(line.trim()) | ||
if (matcher.matches()) { | ||
metaTags.put(matcher.group(1), matcher.group(2)) | ||
} | ||
} | ||
|
||
if (metaTags['author'] != 'The Author') | ||
throw new RuntimeException("Author not found in $metaTags") | ||
if (metaTags['date'] != '2024-02-07 23:36:29') | ||
throw new RuntimeException("docdatetime not found in: $metaTags") | ||
|
||
// assert breadcrumbs | ||
boolean breadcrumbTagFound = false | ||
boolean breadcrumbFound = false | ||
final String docTitle = "File with TOC" | ||
|
||
for (String line : lines) { | ||
if (!breadcrumbTagFound) { | ||
breadcrumbTagFound = line.endsWith("<div id=\"breadcrumbs\">") | ||
continue | ||
} | ||
if (line.endsWith("</div>")) break | ||
breadcrumbFound = line.trim().equals(docTitle) | ||
} | ||
|
||
if (!breadcrumbFound) | ||
throw new RuntimeException("No breadcrumb found: expected title: $docTitle") | ||
} | ||
|
||
for (String unexpectedFile : unexpectedFiles) { | ||
File file = new File(outputDir, unexpectedFile) | ||
System.out.println("Checking for absence of $file") | ||
if (file.isFile()) { | ||
throw new Exception("Unexpected file $file") | ||
} | ||
} | ||
|
||
return true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.