@neo4j-antora/pdf-generator 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neo4j-antora/pdf-generator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Generates a PDF export from an Antora docset, styled to match the real Neo4j docs site, via @antora/assembler + @antora/pdf-extension and asciidoctor-web-pdf",
|
|
5
5
|
"main": "extension.js",
|
|
6
6
|
"files": [
|
package/pdf-theme/print.css
CHANGED
package/scripts/convert.js
CHANGED
|
@@ -144,18 +144,29 @@ const PUPPETEER_TIMEOUT_ENV = {
|
|
|
144
144
|
// this can't just be a relative value in the playbook/assembler config.
|
|
145
145
|
const args = process.argv.slice(2)
|
|
146
146
|
const stdinMarkerIdx = args.lastIndexOf('-')
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
147
|
+
// reusable-docs-pdf-build.yml sets DOCS_PUBLISH_URL as this job's own env - the
|
|
148
|
+
// exact same value reusable-docs-build.yml's own HTML build resolves (dev
|
|
149
|
+
// sandbox vs prod) - which reaches this child process for free (plain env var
|
|
150
|
+
// inheritance), rather than needing to round-trip it through Antora's own CLI
|
|
151
|
+
// args: Antora's top-level command has no generic attribute-override flag the
|
|
152
|
+
// way plain asciidoctor does, so there's no "-a" to read it back out of here.
|
|
153
|
+
//
|
|
154
|
+
// A root-relative href (from neo4j-docs-base-uri - see
|
|
155
|
+
// absolute-links-postprocessor.js's own comment) always starts with the literal
|
|
156
|
+
// "/docs" - true site-root-relative on production, where DOCS_PUBLISH_URL's own
|
|
157
|
+
// path is just "/docs", but not on a sandbox/dev deployment, whose
|
|
158
|
+
// DOCS_PUBLISH_URL has a longer path that merely *ends* in that same "/docs"
|
|
159
|
+
// segment (e.g. ".../sandbox/restructure/docs"). Stripping that one trailing
|
|
160
|
+
// segment before prepending gives the prefix that's correct in both cases - the
|
|
161
|
+
// href's own "/docs" fills back in whichever one was removed:
|
|
162
|
+
// prod: https://neo4j.com/docs -> https://neo4j.com
|
|
163
|
+
// sandbox: https://development.neo4j.dev/docs/sandbox/restructure/docs
|
|
164
|
+
// -> https://development.neo4j.dev/docs/sandbox/restructure
|
|
165
|
+
function linkPrefix () {
|
|
166
|
+
if (!process.env.DOCS_PUBLISH_URL) return null
|
|
157
167
|
try {
|
|
158
|
-
|
|
168
|
+
const url = new URL(process.env.DOCS_PUBLISH_URL)
|
|
169
|
+
return url.origin + url.pathname.replace(/\/docs\/?$/, '')
|
|
159
170
|
} catch {
|
|
160
171
|
return null
|
|
161
172
|
}
|
|
@@ -176,8 +187,8 @@ const extraArgs = [
|
|
|
176
187
|
'--extension', COLOPHON_POSTPROCESSOR,
|
|
177
188
|
'--extension', ABSOLUTE_LINKS_POSTPROCESSOR,
|
|
178
189
|
]
|
|
179
|
-
const
|
|
180
|
-
if (
|
|
190
|
+
const prefix = linkPrefix()
|
|
191
|
+
if (prefix) extraArgs.push('-a', `absolute-link-prefix=${prefix}`)
|
|
181
192
|
if (mathjaxAvailable()) extraArgs.push('--extension', MATHJAX_ADAPTER)
|
|
182
193
|
// Reading from stdin (this is piped the merged .adoc, not a real file - see
|
|
183
194
|
// below), asciidoctor-web-pdf invents a fictive input path rooted at
|
|
@@ -29,13 +29,13 @@ const { Postprocessor } = require('asciidoctor')
|
|
|
29
29
|
class AbsoluteLinksPostprocessor extends Postprocessor {
|
|
30
30
|
process (document, output) {
|
|
31
31
|
if (!output.includes('href="/')) return output
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
// comment
|
|
36
|
-
//
|
|
37
|
-
// downloaded, standalone PDF.
|
|
38
|
-
const
|
|
32
|
+
// reusable-docs-pdf-build.yml passes DOCS_PUBLISH_URL through (the exact
|
|
33
|
+
// value its HTML build equivalent resolves - dev sandbox vs prod), and
|
|
34
|
+
// convert.js turns it into this attribute - see its own linkPrefix()
|
|
35
|
+
// comment for why this is more than just an origin. Falls back to the
|
|
36
|
+
// real production origin if that ever isn't available, rather than
|
|
37
|
+
// leaving a root-relative, unusable link in a downloaded, standalone PDF.
|
|
38
|
+
const prefix = document.getAttribute('absolute-link-prefix') || 'https://neo4j.com'
|
|
39
39
|
const root = parseHTML(output)
|
|
40
40
|
root.querySelectorAll('a[href]').forEach((a) => {
|
|
41
41
|
const href = a.getAttribute('href')
|
|
@@ -43,7 +43,7 @@ class AbsoluteLinksPostprocessor extends Postprocessor {
|
|
|
43
43
|
// a different origin entirely) and everything else (full URLs,
|
|
44
44
|
// same-page "#fragment"s, "mailto:", ...) untouched.
|
|
45
45
|
if (href.startsWith('/') && !href.startsWith('//')) {
|
|
46
|
-
a.setAttribute('href',
|
|
46
|
+
a.setAttribute('href', prefix + href)
|
|
47
47
|
}
|
|
48
48
|
})
|
|
49
49
|
return root.toString()
|