@antora/document-converter 3.0.0-beta.1 → 3.0.0-beta.5

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.
@@ -1,22 +1,16 @@
1
1
  'use strict'
2
2
 
3
- const {
4
- loadAsciiDoc: _loadAsciiDoc,
5
- extractAsciiDocMetadata: _extractAsciiDocMetadata,
6
- } = require('@antora/asciidoc-loader')
7
-
8
3
  /**
9
4
  * Converts the contents on the specified file from AsciiDoc to embedded HTML.
10
5
  *
11
- * It first delegates to the AsciiDoc Loader to load the AsciiDoc contents on
12
- * the specified virtual file to a Document object. It then grabs the document
13
- * attributes from that Document and assigns them to the asciidoc.attributes
14
- * property on the file. If the document has a document header, it assigns the
15
- * doctitle, xreftext, and navtitle to the asciidoc property on that file. If
16
- * the page-partial attributes is set, it backs up the AsciiDoc source on the
17
- * src.contents property. It then converts the Document to embedded HTML, wraps
18
- * it in a Buffer, and assigns it to the contents property on the file. Finally,
19
- * the mediaType property is updated to 'text/html'.
6
+ * This function first delegates to the AsciiDoc loader to load the AsciiDoc contents on the
7
+ * specified virtual file to a Document object. If the asciidoc property is not set on the virtual
8
+ * file, it then extracts the metadata from that document and assigns it to the asciidoc property.
9
+ * This metadata includes the document attributes, doctitle, xreftext, and navtitle. If the
10
+ * keepSource option on the AsciiDoc config is true or the page-partial attributes is set, it backs
11
+ * up the AsciiDoc source to the src.contents property. It then converts the Document to embedded
12
+ * HTML, wraps it in a Buffer, and assigns it to the contents property on the file. Finally, it
13
+ * updates the mediaType property on the file to 'text/html'.
20
14
  *
21
15
  * @memberof document-converter
22
16
  *
@@ -27,17 +21,22 @@ const {
27
21
  * @returns {File} The virtual file that was converted.
28
22
  */
29
23
  function convertDocument (file, contentCatalog = undefined, asciidocConfig = {}) {
30
- const { extractAsciiDocMetadata = _extractAsciiDocMetadata, loadAsciiDoc = _loadAsciiDoc } = this
31
- ? this.getFunctions(false)
32
- : {}
24
+ const {
25
+ extractAsciiDocMetadata = requireAsciiDocLoader().extractAsciiDocMetadata,
26
+ loadAsciiDoc = requireAsciiDocLoader(),
27
+ } = this ? this.getFunctions(false) : {}
33
28
  const doc = loadAsciiDoc(file, contentCatalog, asciidocConfig)
34
29
  if (!file.asciidoc) {
35
30
  file.asciidoc = extractAsciiDocMetadata(doc)
36
- if (doc.hasAttribute('page-partial')) file.src.contents = file.contents
31
+ if (asciidocConfig.keepSource || 'page-partial' in file.asciidoc.attributes) file.src.contents = file.contents
37
32
  }
38
33
  file.contents = Buffer.from(doc.convert())
39
34
  file.mediaType = 'text/html'
40
35
  return file
41
36
  }
42
37
 
38
+ function requireAsciiDocLoader () {
39
+ return requireAsciiDocLoader.cache || (requireAsciiDocLoader.cache = require('@antora/asciidoc-loader'))
40
+ }
41
+
43
42
  module.exports = convertDocument
@@ -1,10 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  const _convertDocument = require('./convert-document')
4
- const {
5
- loadAsciiDoc: _loadAsciiDoc,
6
- extractAsciiDocMetadata: _extractAsciiDocMetadata,
7
- } = require('@antora/asciidoc-loader')
8
4
 
9
5
  /**
10
6
  * Converts the contents of publishable pages with the media type text/asciidoc
@@ -31,8 +27,8 @@ const {
31
27
  function convertDocuments (contentCatalog, siteAsciiDocConfig = {}) {
32
28
  const {
33
29
  convertDocument = _convertDocument,
34
- extractAsciiDocMetadata = _extractAsciiDocMetadata,
35
- loadAsciiDoc = _loadAsciiDoc,
30
+ extractAsciiDocMetadata = requireAsciiDocLoader().extractAsciiDocMetadata,
31
+ loadAsciiDoc = requireAsciiDocLoader(),
36
32
  } = this ? this.getFunctions(false) : {}
37
33
  const mainAsciiDocConfigs = new Map()
38
34
  contentCatalog.getComponents().forEach(({ name: component, versions }) => {
@@ -45,30 +41,33 @@ function convertDocuments (contentCatalog, siteAsciiDocConfig = {}) {
45
41
  for (const [cacheKey, mainAsciiDocConfig] of mainAsciiDocConfigs) {
46
42
  headerAsciiDocConfigs.set(cacheKey, Object.assign({}, mainAsciiDocConfig, headerOverrides))
47
43
  }
48
- return contentCatalog
49
- .getPages((page) => page.out)
50
- .map((page) => {
51
- if (page.mediaType === 'text/asciidoc') {
52
- const asciidocConfig = headerAsciiDocConfigs.get(buildCacheKey(page.src))
53
- const { attributes } = (page.asciidoc = extractAsciiDocMetadata(
54
- loadAsciiDoc(page, contentCatalog, asciidocConfig || Object.assign({}, siteAsciiDocConfig, headerOverrides))
55
- ))
56
- Object.defineProperty(page, 'title', {
57
- get () {
58
- return this.asciidoc.doctitle
59
- },
60
- })
61
- registerPageAliases(attributes['page-aliases'], page, contentCatalog)
62
- if ('page-partial' in attributes) page.src.contents = page.contents
44
+ const keepSource = siteAsciiDocConfig.keepSource
45
+ const pages = contentCatalog
46
+ .getPages((page) => {
47
+ if (page.out) {
48
+ if (page.mediaType === 'text/asciidoc') {
49
+ const asciidocConfig = headerAsciiDocConfigs.get(buildCacheKey(page.src))
50
+ const { attributes } = (page.asciidoc = extractAsciiDocMetadata(
51
+ loadAsciiDoc(page, contentCatalog, asciidocConfig || Object.assign({}, siteAsciiDocConfig, headerOverrides))
52
+ ))
53
+ Object.defineProperty(page, 'title', {
54
+ get () {
55
+ return this.asciidoc.doctitle
56
+ },
57
+ })
58
+ registerPageAliases(attributes['page-aliases'], page, contentCatalog)
59
+ if (keepSource || 'page-partial' in attributes) page.src.contents = page.contents
60
+ }
61
+ return true
63
62
  }
64
- return page
65
63
  })
66
64
  .map((page) =>
67
65
  page.mediaType === 'text/asciidoc'
68
66
  ? convertDocument(page, contentCatalog, mainAsciiDocConfigs.get(buildCacheKey(page.src)) || siteAsciiDocConfig)
69
67
  : page
70
68
  )
71
- .map((page) => delete page.src.contents && page)
69
+ if (!keepSource) pages.forEach((page) => delete page.src.contents)
70
+ return pages
72
71
  }
73
72
 
74
73
  function buildCacheKey ({ component, version }) {
@@ -82,4 +81,8 @@ function registerPageAliases (aliases, targetFile, contentCatalog) {
82
81
  .forEach((spec) => (spec = spec.trim()) && contentCatalog.registerPageAlias(spec, targetFile))
83
82
  }
84
83
 
84
+ function requireAsciiDocLoader () {
85
+ return requireAsciiDocLoader.cache || (requireAsciiDocLoader.cache = require('@antora/asciidoc-loader'))
86
+ }
87
+
85
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-beta.1",
3
+ "version": "3.0.0-beta.5",
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,7 +17,7 @@
17
17
  },
18
18
  "main": "lib/index.js",
19
19
  "dependencies": {
20
- "@antora/asciidoc-loader": "3.0.0-beta.1"
20
+ "@antora/asciidoc-loader": "3.0.0-beta.5"
21
21
  },
22
22
  "engines": {
23
23
  "node": ">=12.21.0"
@@ -35,5 +35,5 @@
35
35
  "static site",
36
36
  "web publishing"
37
37
  ],
38
- "gitHead": "7c5ef1ea93dd489af533c80a936c736013c41769"
38
+ "gitHead": "a13d03df41654d4deb78211a5a54953ce2a35fb8"
39
39
  }