@antora/pdf-extension 1.0.0-alpha.1

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.md ADDED
@@ -0,0 +1,30 @@
1
+ # Antora PDF Extension
2
+
3
+ The Antora PDF Extension is the official extension for producing PDFs of an Antora site.
4
+ Specifically, it generates and publishes PDFs of aggregate pages in the site.
5
+
6
+ This extension is based on Antora Assembler.
7
+ It calls Assembler to construct aggregate AsciiDoc documents from pages based on the navigation tree per component version.
8
+ It then iterates over those aggregate documents and converts them to PDF using Asciidoctor PDF or the specified command.
9
+ Finally, it pushes those PDFs into the site catalog so they are published as attachments alongside the other files in the site.
10
+
11
+ ## Usage
12
+
13
+ Once this package is installed in the playbook project, register it in the Antora playbook as follows:
14
+
15
+ **antora-playbook.yml**
16
+
17
+ ```yaml
18
+ antora:
19
+ extensions:
20
+ - '@antora/pdf-extension'
21
+ # ...
22
+ ```
23
+
24
+ You can configure the behavior of the extension using the optional *antora-assembler.yml* file.
25
+
26
+ ## Copyright and License
27
+
28
+ Copyright (C) 2022-present by OpenDevise Inc. and the individual contributors of this project.
29
+
30
+ Use of this software is granted under the terms of the [Mozilla Public License Version 2.0](https://www.mozilla.org/en-US/MPL/2.0/) (MPL-2.0).
@@ -0,0 +1,43 @@
1
+ 'use strict'
2
+
3
+ const { runCommand } = (() => {
4
+ try {
5
+ return require('@antora/assembler')
6
+ } catch {
7
+ return require('../../assembler')
8
+ }
9
+ })()
10
+ const ospath = require('path')
11
+
12
+ // Q: how can we simplify this to avoid redundant code?
13
+ // Q: rename to convertDocumentToPDF?
14
+ function convertDocumentToPdf (doc, buildConfig) {
15
+ const {
16
+ asciidoc: { attributes: baseAttributes } = { attributes: {} },
17
+ contents: input,
18
+ src: { component, version, basename, extname: docfilesuffix },
19
+ } = doc
20
+ const { command = 'asciidoctor-pdf', cwd, dir } = buildConfig
21
+ const docfile = `${version}@${component}::pdf$${basename}`
22
+ const docname = basename.substr(0, basename.length - docfilesuffix.length)
23
+ const convertAttributes = Object.assign({}, baseAttributes, {
24
+ docfile,
25
+ docfilesuffix,
26
+ 'docname@': docname,
27
+ imagesdir: dir,
28
+ })
29
+ Object.assign(doc, { contents: null, extname: '.pdf', mediaType: 'application/pdf' })
30
+ const argv = Object.entries(convertAttributes).reduce(
31
+ (accum, [name, val]) =>
32
+ accum.push('-a', val ? `${name}=${val}` : val === '' ? name : `!${name}${val === false ? '=@' : ''}`) && accum,
33
+ []
34
+ )
35
+ const output = ospath.join(dir, doc.path)
36
+ argv.push('-o', output)
37
+ // Q: should runCommand accept outputFlag and automatically append to argv?
38
+ return runCommand(command, argv, { cwd, input, output }).then((contents) =>
39
+ Object.assign(doc, { contents, out: { path: doc.path } })
40
+ )
41
+ }
42
+
43
+ module.exports = convertDocumentToPdf
package/lib/index.js ADDED
@@ -0,0 +1,26 @@
1
+ 'use strict'
2
+
3
+ const convertDocumentToPdf = require('./convert-document-to-pdf')
4
+ const { assembleContent } = (() => {
5
+ try {
6
+ return require('@antora/assembler')
7
+ } catch {
8
+ return require('../../assembler')
9
+ }
10
+ })()
11
+
12
+ module.exports.register = function () {
13
+ //this.on('beforeProcess', ({ asciidocConfig }) => {
14
+ // asciidocConfig.keepSource = true
15
+ //})
16
+ this.on('contentClassified', ({ contentCatalog }) => {
17
+ contentCatalog.getPages((page) => {
18
+ if (!page.out) return
19
+ page.src.contents = page.contents
20
+ page.src = new Proxy(page.src, { deleteProperty: (o, p) => (p === 'contents' ? true : delete o[p]) })
21
+ })
22
+ })
23
+ this.on('beforePublish', ({ playbook, contentCatalog, siteCatalog }) =>
24
+ assembleContent.call(this, playbook, contentCatalog, convertDocumentToPdf, { siteCatalog })
25
+ )
26
+ }
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@antora/pdf-extension",
3
+ "version": "1.0.0-alpha.1",
4
+ "description": "An Antora extension that assembles content pages into PDF files by version and publishes them with the site.",
5
+ "license": "MPL-2.0",
6
+ "author": "OpenDevise Inc. (https://opendevise.com)",
7
+ "contributors": [
8
+ "Dan Allen <dan@opendevise.com>",
9
+ "Sarah White <sarah@opendevise.com>"
10
+ ],
11
+ "homepage": "https://antora.org",
12
+ "repository": "gitlab:antora/antora-assembler",
13
+ "bugs": {
14
+ "url": "https://gitlab.com/antora/antora-assembler/issues"
15
+ },
16
+ "scripts": {
17
+ "prepublishOnly": "node $npm_config_local_prefix/npm/prepublishOnly.js",
18
+ "postpublish": "node $npm_config_local_prefix/npm/postpublish.js"
19
+ },
20
+ "main": "lib/index.js",
21
+ "exports": {
22
+ ".": "./lib/index.js"
23
+ },
24
+ "dependencies": {
25
+ "@antora/assembler": "1.0.0-alpha.1"
26
+ },
27
+ "engines": {
28
+ "node": ">=16.0.0"
29
+ },
30
+ "files": [
31
+ "lib/"
32
+ ],
33
+ "keywords": [
34
+ "antora",
35
+ "antora-extension",
36
+ "asciidoc",
37
+ "asciidoctor",
38
+ "pdf",
39
+ "generator",
40
+ "documentation"
41
+ ],
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }