@antora/document-converter 3.0.0-alpha.9 → 3.0.0-beta.4
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 +1 -1
- package/lib/convert-document.js +8 -2
- package/lib/convert-documents.js +31 -20
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
The Document Converter is a component in Antora responsible for converting AsciiDoc documents to embeddable HTML for use in an Antora documentation pipeline.
|
|
4
4
|
|
|
5
5
|
[Antora](https://antora.org) is a modular static site generator designed for creating documentation sites from AsciiDoc documents.
|
|
6
|
-
Its site generator
|
|
6
|
+
Its site generator aggregates documents from versioned content repositories and processes them using [Asciidoctor](https://asciidoctor.org).
|
|
7
7
|
|
|
8
8
|
## Copyright and License
|
|
9
9
|
|
package/lib/convert-document.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
loadAsciiDoc: _loadAsciiDoc,
|
|
5
|
+
extractAsciiDocMetadata: _extractAsciiDocMetadata,
|
|
6
|
+
} = require('@antora/asciidoc-loader')
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* Converts the contents on the specified file from AsciiDoc to embedded HTML.
|
|
@@ -24,10 +27,13 @@ const { loadAsciiDoc, extractAsciiDocMetadata } = require('@antora/asciidoc-load
|
|
|
24
27
|
* @returns {File} The virtual file that was converted.
|
|
25
28
|
*/
|
|
26
29
|
function convertDocument (file, contentCatalog = undefined, asciidocConfig = {}) {
|
|
30
|
+
const { extractAsciiDocMetadata = _extractAsciiDocMetadata, loadAsciiDoc = _loadAsciiDoc } = this
|
|
31
|
+
? this.getFunctions(false)
|
|
32
|
+
: {}
|
|
27
33
|
const doc = loadAsciiDoc(file, contentCatalog, asciidocConfig)
|
|
28
34
|
if (!file.asciidoc) {
|
|
29
35
|
file.asciidoc = extractAsciiDocMetadata(doc)
|
|
30
|
-
if (
|
|
36
|
+
if (asciidocConfig.keepSource || 'page-partial' in file.asciidoc.attributes) file.src.contents = file.contents
|
|
31
37
|
}
|
|
32
38
|
file.contents = Buffer.from(doc.convert())
|
|
33
39
|
file.mediaType = 'text/html'
|
package/lib/convert-documents.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const {
|
|
3
|
+
const _convertDocument = require('./convert-document')
|
|
4
|
+
const {
|
|
5
|
+
loadAsciiDoc: _loadAsciiDoc,
|
|
6
|
+
extractAsciiDocMetadata: _extractAsciiDocMetadata,
|
|
7
|
+
} = require('@antora/asciidoc-loader')
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Converts the contents of publishable pages with the media type text/asciidoc
|
|
@@ -26,6 +29,11 @@ const { loadAsciiDoc, extractAsciiDocMetadata } = require('@antora/asciidoc-load
|
|
|
26
29
|
* @returns {Array<File>} The publishable virtual files in the page family taken from the content catalog.
|
|
27
30
|
*/
|
|
28
31
|
function convertDocuments (contentCatalog, siteAsciiDocConfig = {}) {
|
|
32
|
+
const {
|
|
33
|
+
convertDocument = _convertDocument,
|
|
34
|
+
extractAsciiDocMetadata = _extractAsciiDocMetadata,
|
|
35
|
+
loadAsciiDoc = _loadAsciiDoc,
|
|
36
|
+
} = this ? this.getFunctions(false) : {}
|
|
29
37
|
const mainAsciiDocConfigs = new Map()
|
|
30
38
|
contentCatalog.getComponents().forEach(({ name: component, versions }) => {
|
|
31
39
|
versions.forEach(({ version, asciidoc }) => {
|
|
@@ -37,30 +45,33 @@ function convertDocuments (contentCatalog, siteAsciiDocConfig = {}) {
|
|
|
37
45
|
for (const [cacheKey, mainAsciiDocConfig] of mainAsciiDocConfigs) {
|
|
38
46
|
headerAsciiDocConfigs.set(cacheKey, Object.assign({}, mainAsciiDocConfig, headerOverrides))
|
|
39
47
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.
|
|
43
|
-
if (page.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
const keepSource = siteAsciiDocConfig.keepSource
|
|
49
|
+
const pages = contentCatalog
|
|
50
|
+
.getPages((page) => {
|
|
51
|
+
if (page.out) {
|
|
52
|
+
if (page.mediaType === 'text/asciidoc') {
|
|
53
|
+
const asciidocConfig = headerAsciiDocConfigs.get(buildCacheKey(page.src))
|
|
54
|
+
const { attributes } = (page.asciidoc = extractAsciiDocMetadata(
|
|
55
|
+
loadAsciiDoc(page, contentCatalog, asciidocConfig || Object.assign({}, siteAsciiDocConfig, headerOverrides))
|
|
56
|
+
))
|
|
57
|
+
Object.defineProperty(page, 'title', {
|
|
58
|
+
get () {
|
|
59
|
+
return this.asciidoc.doctitle
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
registerPageAliases(attributes['page-aliases'], page, contentCatalog)
|
|
63
|
+
if (keepSource || 'page-partial' in attributes) page.src.contents = page.contents
|
|
64
|
+
}
|
|
65
|
+
return true
|
|
55
66
|
}
|
|
56
|
-
return page
|
|
57
67
|
})
|
|
58
68
|
.map((page) =>
|
|
59
69
|
page.mediaType === 'text/asciidoc'
|
|
60
70
|
? convertDocument(page, contentCatalog, mainAsciiDocConfigs.get(buildCacheKey(page.src)) || siteAsciiDocConfig)
|
|
61
71
|
: page
|
|
62
72
|
)
|
|
63
|
-
|
|
73
|
+
if (!keepSource) pages.forEach((page) => delete page.src.contents)
|
|
74
|
+
return pages
|
|
64
75
|
}
|
|
65
76
|
|
|
66
77
|
function buildCacheKey ({ component, version }) {
|
|
@@ -74,4 +85,4 @@ function registerPageAliases (aliases, targetFile, contentCatalog) {
|
|
|
74
85
|
.forEach((spec) => (spec = spec.trim()) && contentCatalog.registerPageAlias(spec, targetFile))
|
|
75
86
|
}
|
|
76
87
|
|
|
77
|
-
module.exports = Object.assign(convertDocuments, { convertDocuments, convertDocument })
|
|
88
|
+
module.exports = Object.assign(convertDocuments, { convertDocuments, convertDocument: _convertDocument })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/document-converter",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.4",
|
|
4
4
|
"description": "Converts AsciiDoc documents to embeddable HTML for use in an Antora documentation pipeline.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "OpenDevise Inc. (https://opendevise.com)",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
},
|
|
18
18
|
"main": "lib/index.js",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@antora/asciidoc-loader": "3.0.0-
|
|
20
|
+
"@antora/asciidoc-loader": "3.0.0-beta.4"
|
|
21
21
|
},
|
|
22
22
|
"engines": {
|
|
23
|
-
"node": ">=
|
|
23
|
+
"node": ">=12.21.0"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
26
|
"lib/"
|
|
@@ -35,5 +35,6 @@
|
|
|
35
35
|
"static site",
|
|
36
36
|
"web publishing"
|
|
37
37
|
],
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "8a142499e9f1a9e0631777796e06dd6c010d3a90",
|
|
39
|
+
"readmeFilename": "README.md"
|
|
39
40
|
}
|