@antora/html-single-extension 1.0.0-beta.18
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 +29 -0
- package/lib/converter.js +57 -0
- package/lib/index.js +15 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Antora HTML Single Extension
|
|
2
|
+
|
|
3
|
+
The Antora HTML Single extension is an Antora extension and exporter for Assembler.
|
|
4
|
+
It configures and invokes Assembler and provides the converter function and metadata Assembler uses to export content to standalone HTML documents.
|
|
5
|
+
|
|
6
|
+
This extension first delegates to Assembler, passing in the converter metadata, to construct assembly files from pages per component version using the navigation as a model.
|
|
7
|
+
Assembler then iterates over those assembly files and, using the converter provided by this extension, converts them to standalone HTML documents using Asciidoctor.js (or the specified command).
|
|
8
|
+
Finally, Assembler adds those HTML documents to the content catalog as exports, which Antora publishes alongside the other files in the site.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
Once this package is installed in the playbook project, register it in the Antora playbook as follows:
|
|
13
|
+
|
|
14
|
+
**antora-playbook.yml**
|
|
15
|
+
|
|
16
|
+
```yaml
|
|
17
|
+
antora:
|
|
18
|
+
extensions:
|
|
19
|
+
- '@antora/html-single-extension'
|
|
20
|
+
# ...
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
You can configure the behavior of the extension using the optional _antora-assembler.yml_ file.
|
|
24
|
+
|
|
25
|
+
## Copyright and License
|
|
26
|
+
|
|
27
|
+
Copyright (C) 2022-present by OpenDevise Inc. and the individual contributors of this project.
|
|
28
|
+
|
|
29
|
+
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).
|
package/lib/converter.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const fsp = require('node:fs/promises')
|
|
4
|
+
const ospath = require('node:path')
|
|
5
|
+
|
|
6
|
+
const DEFAULT_COMMAND = 'asciidoctor'
|
|
7
|
+
|
|
8
|
+
async function convert (runCommand, file, convertAttributes, buildConfig) {
|
|
9
|
+
const { command } = buildConfig
|
|
10
|
+
if (command === false) {
|
|
11
|
+
const Asciidoctor = this.require('@asciidoctor/core')()
|
|
12
|
+
const Extensions = Asciidoctor.Extensions
|
|
13
|
+
const exts = this.getVariables().siteAsciiDocConfig?.extensions || []
|
|
14
|
+
let extRegistry, extDslTypes
|
|
15
|
+
try {
|
|
16
|
+
if (exts.length) {
|
|
17
|
+
const contentCatalog = this.getVariables().contentCatalog
|
|
18
|
+
extDslTypes = Extensions.$constants(false).filter((name) => name.endsWith('Dsl'))
|
|
19
|
+
extRegistry = Extensions.create()
|
|
20
|
+
exts.forEach((ext) => ext.register(extRegistry, { file, contentCatalog }))
|
|
21
|
+
}
|
|
22
|
+
Asciidoctor.convert(file.contents, {
|
|
23
|
+
attributes: convertAttributes,
|
|
24
|
+
extension_registry: extRegistry,
|
|
25
|
+
mkdirs: true,
|
|
26
|
+
safe: 'safe',
|
|
27
|
+
sourcemap: true,
|
|
28
|
+
to_file: convertAttributes.outfile,
|
|
29
|
+
})
|
|
30
|
+
} finally {
|
|
31
|
+
if (exts.length) extDslTypes.forEach((type) => (Opal.const_get_local(Extensions, type).$$iclasses.length = 0))
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
const { cwd = process.cwd(), stderr = 'print' } = buildConfig
|
|
35
|
+
const args = convertAttributes.toArgs('-a', command).concat('-o', convertAttributes.outfile, '-')
|
|
36
|
+
return await runCommand(command, args, { parse: true, cwd, stdin: file.contents, stdout: 'print', stderr })
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getDefaultCommand (cwd) {
|
|
41
|
+
return fsp.access(ospath.join(cwd, 'Gemfile.lock')).then(
|
|
42
|
+
() => `bundle exec ${DEFAULT_COMMAND}`,
|
|
43
|
+
() => DEFAULT_COMMAND
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
bind (thisArg, runCommand) {
|
|
49
|
+
return Object.assign({}, this, { convert: convert.bind(thisArg, runCommand) })
|
|
50
|
+
},
|
|
51
|
+
convert,
|
|
52
|
+
backend: 'html',
|
|
53
|
+
getDefaultCommand,
|
|
54
|
+
extname: '.html',
|
|
55
|
+
mediaType: 'text/html',
|
|
56
|
+
loggerName: require('../package.json').name,
|
|
57
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const converter = require('./converter')
|
|
4
|
+
const runCommand = require('@antora/run-command-helper')
|
|
5
|
+
|
|
6
|
+
module.exports.register = function ({ config }, providers) {
|
|
7
|
+
requireAssembler(this).configure(this, converter.bind(this, runCommand), config, providers)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function requireAssembler (context, packageName = '@antora/assembler') {
|
|
11
|
+
try {
|
|
12
|
+
return context.require(packageName) // when installed with Antora
|
|
13
|
+
} catch {}
|
|
14
|
+
return require(packageName) // when installed separate from Antora, perhaps in project
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@antora/html-single-extension",
|
|
3
|
+
"version": "1.0.0-beta.18",
|
|
4
|
+
"description": "An Antora extension that uses Assembler to merge pages into assembly files, export them to standalone HTML documents, and publish 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": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://gitlab.com/antora/antora-assembler.git",
|
|
15
|
+
"directory": "packages/html-single-extension"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://gitlab.com/antora/antora-assembler/issues"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "node --test test/*-test.js",
|
|
22
|
+
"prepublishOnly": "npx -y downdoc --prepublish",
|
|
23
|
+
"postpublish": "npx -y downdoc --postpublish"
|
|
24
|
+
},
|
|
25
|
+
"main": "lib/index.js",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./lib/index.js",
|
|
28
|
+
"./converter": "./lib/converter.js",
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"imports": {
|
|
32
|
+
"#package": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@antora/assembler": "1.0.0-beta.18",
|
|
36
|
+
"@antora/run-command-helper": "~1.0"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=16.0.0"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"lib/"
|
|
43
|
+
],
|
|
44
|
+
"keywords": [
|
|
45
|
+
"antora",
|
|
46
|
+
"antora-extension",
|
|
47
|
+
"asciidoc",
|
|
48
|
+
"asciidoctor",
|
|
49
|
+
"html",
|
|
50
|
+
"generator",
|
|
51
|
+
"documentation"
|
|
52
|
+
]
|
|
53
|
+
}
|