@neo4j-antora/pdf-generator 0.1.13 → 0.1.15
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/README.adoc +4 -0
- package/extension.js +31 -1
- package/package.json +1 -1
- package/scripts/convert.js +8 -2
- package/scripts/setup-vendor.js +19 -0
package/README.adoc
CHANGED
|
@@ -34,6 +34,10 @@ antora publish.yml --extension @neo4j-antora/pdf-generator
|
|
|
34
34
|
npm run verify:publish -- --extension @neo4j-antora/pdf-generator
|
|
35
35
|
----
|
|
36
36
|
|
|
37
|
+
A PDF contains a single version: the one being built. When the playbook is built, every local content
|
|
38
|
+
source (the repository being built) is limited to `branches: [HEAD]`, so the other versions the
|
|
39
|
+
playbook lists are not collected or rendered. Remote content sources are left as they are.
|
|
40
|
+
|
|
37
41
|
Generating a PDF this way always regenerates the full HTML site alongside
|
|
38
42
|
it in the same Antora run (`@antora/assembler`/`@antora/pdf-extension` hook
|
|
39
43
|
into normal site generation rather than replacing it) - there's no way to
|
package/extension.js
CHANGED
|
@@ -23,7 +23,37 @@ const DEFAULT_CONFIG_FILE = path.join(__dirname, 'antora-assembler-pdf.yml')
|
|
|
23
23
|
// as the one argument - confirmed directly against the installed Antora,
|
|
24
24
|
// including that @antora/pdf-extension's own optional second `providers`
|
|
25
25
|
// parameter is never actually populated by a real Antora invocation either.
|
|
26
|
+
// A PDF contains a single version: the one being built. The playbook of a docset usually lists
|
|
27
|
+
// its other versions as branches of the same repository (HEAD, 5.x, 4.4, ...), and building them
|
|
28
|
+
// would render a PDF for each one, only to throw all but one away. A local content source is the
|
|
29
|
+
// repository being built, and HEAD is the branch that is checked out, so those sources are limited
|
|
30
|
+
// to HEAD, before any content is collected. Remote sources are left as they are.
|
|
31
|
+
const REMOTE_URL = /^(?:[a-z][a-z0-9+.-]*:\/\/|git@)/i
|
|
32
|
+
|
|
33
|
+
function limitLocalSourcesToHead ({ playbook }) {
|
|
34
|
+
const logger = this.getLogger?.('neo4j-pdf-generator')
|
|
35
|
+
for (const source of playbook?.content?.sources ?? []) {
|
|
36
|
+
if (REMOTE_URL.test(source.url ?? '')) continue
|
|
37
|
+
const branches = [].concat(source.branches ?? [])
|
|
38
|
+
if (branches.length === 1 && branches[0] === 'HEAD') continue
|
|
39
|
+
source.branches = ['HEAD']
|
|
40
|
+
logger?.info({ source: { url: source.url } }, 'Building HEAD only (was: %s)', branches.join(', ') || 'the playbook default')
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// When the renderer fails, the assembler logs nothing, adds no PDF and Antora still exits 0, so the
|
|
45
|
+
// failure only shows up later, when the workflow cannot find a PDF. Registered after
|
|
46
|
+
// @antora/pdf-extension, this runs once the assembler has added its PDFs to the content catalog,
|
|
47
|
+
// and fails the build if there are none.
|
|
48
|
+
function requirePdf ({ contentCatalog }) {
|
|
49
|
+
const pdfs = contentCatalog.findBy({ family: 'export' }).filter((file) => file.out?.path?.endsWith('.pdf'))
|
|
50
|
+
if (!pdfs.length) throw new Error('@neo4j-antora/pdf-generator: no PDF was generated (see the renderer output above)')
|
|
51
|
+
}
|
|
52
|
+
|
|
26
53
|
module.exports.register = function ({ config = {} } = {}) {
|
|
54
|
+
this.once('playbookBuilt', limitLocalSourcesToHead.bind(this))
|
|
27
55
|
const resolvedConfig = Object.assign({ configFile: DEFAULT_CONFIG_FILE }, config)
|
|
28
|
-
|
|
56
|
+
const result = pdfExtension.register.call(this, { config: resolvedConfig })
|
|
57
|
+
this.once('navigationBuilt', requirePdf)
|
|
58
|
+
return result
|
|
29
59
|
}
|
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.15",
|
|
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/scripts/convert.js
CHANGED
|
@@ -218,10 +218,16 @@ function readStdin () {
|
|
|
218
218
|
// asciidoctor-web-pdf only reads these from the environment (no -a attribute or
|
|
219
219
|
// CLI flag equivalent - see lib/browser.js) and defaults to 30s, which a large
|
|
220
220
|
// docset can easily exceed. Give it more headroom here rather than relying on
|
|
221
|
-
// whoever runs the build to remember to export these.
|
|
221
|
+
// whoever runs the build to remember to export these. Rendering, printing and
|
|
222
|
+
// protocol calls (PUPPETEER_PROTOCOL_TIMEOUT, added by setup-vendor.js) all run
|
|
223
|
+
// for as long as the whole layout takes, about 40 minutes for the Cypher Manual,
|
|
224
|
+
// so they get 2 hours. Values already set in the environment win.
|
|
225
|
+
const TWO_HOURS = String(2 * 60 * 60 * 1000)
|
|
222
226
|
const PUPPETEER_TIMEOUT_ENV = {
|
|
223
227
|
PUPPETEER_NAVIGATION_TIMEOUT: '180000',
|
|
224
|
-
PUPPETEER_RENDERING_TIMEOUT:
|
|
228
|
+
PUPPETEER_RENDERING_TIMEOUT: TWO_HOURS,
|
|
229
|
+
PUPPETEER_PRINT_TIMEOUT: TWO_HOURS,
|
|
230
|
+
PUPPETEER_PROTOCOL_TIMEOUT: TWO_HOURS,
|
|
225
231
|
}
|
|
226
232
|
|
|
227
233
|
// antora-assembler-pdf.yml deliberately does NOT set a `stylesheet` attribute
|
package/scripts/setup-vendor.js
CHANGED
|
@@ -63,3 +63,22 @@ if (result.error || result.status !== 0) {
|
|
|
63
63
|
console.error('@neo4j-antora/pdf-generator: failed to install its isolated asciidoctor-pdf renderer (see vendor/package.json)')
|
|
64
64
|
process.exit(result.status || 1)
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
// asciidoctor-web-pdf launches Chromium without a protocolTimeout, so every call Puppeteer makes
|
|
68
|
+
// to the page is limited to the Puppeteer default of 180 seconds. While Vivliostyle lays out a
|
|
69
|
+
// large document, the page cannot answer the call that checks whether layout has finished, and
|
|
70
|
+
// the conversion fails with "Waiting failed" (the Cypher Manual needs about 40 minutes). None of
|
|
71
|
+
// the PUPPETEER_*_TIMEOUT variables that asciidoctor-web-pdf reads change this, so the launch
|
|
72
|
+
// options are patched here to read PUPPETEER_PROTOCOL_TIMEOUT as well.
|
|
73
|
+
const browserJs = path.join(vendorDir, 'node_modules/asciidoctor-pdf/lib/browser.js')
|
|
74
|
+
const LAUNCH_OPTION = ' headless: !preview,\n'
|
|
75
|
+
const PROTOCOL_TIMEOUT_OPTION =
|
|
76
|
+
' protocolTimeout: process.env.PUPPETEER_PROTOCOL_TIMEOUT ? Number(process.env.PUPPETEER_PROTOCOL_TIMEOUT) : undefined,\n'
|
|
77
|
+
const browserSource = fs.readFileSync(browserJs, 'utf8')
|
|
78
|
+
if (!browserSource.includes('protocolTimeout')) {
|
|
79
|
+
if (!browserSource.includes(LAUNCH_OPTION)) {
|
|
80
|
+
console.error(`@neo4j-antora/pdf-generator: cannot add protocolTimeout to ${browserJs}: launch options not found`)
|
|
81
|
+
process.exit(1)
|
|
82
|
+
}
|
|
83
|
+
fs.writeFileSync(browserJs, browserSource.replace(LAUNCH_OPTION, LAUNCH_OPTION + PROTOCOL_TIMEOUT_OPTION))
|
|
84
|
+
}
|