@antora/document-converter
Advanced tools
Comparing version 2.3.0-alpha.2 to 2.3.0-beta.1
'use strict' | ||
const loadAsciiDoc = require('@antora/asciidoc-loader') | ||
const { loadAsciiDoc, extractAsciiDocMetadata } = require('@antora/asciidoc-loader') | ||
const COMMA_DELIMITER_RX = /\s*,\s*/ | ||
/** | ||
@@ -29,7 +27,6 @@ * Converts the contents on the specified file from AsciiDoc to embeddable HTML. | ||
const doc = loadAsciiDoc(file, contentCatalog, asciidocConfig) | ||
const attributes = doc.getAttributes() | ||
registerAliases(attributes['page-aliases'], file, contentCatalog) | ||
// Q: should we backup the AsciiDoc contents for all pages? what's the impact? | ||
file.asciidoc = doc.hasHeader() ? { attributes, doctitle: doc.getDocumentTitle() } : { attributes } | ||
if ('page-partial' in attributes) file.src.contents = file.contents.toString() | ||
if (!file.asciidoc) { | ||
file.asciidoc = extractAsciiDocMetadata(doc) | ||
if (doc.hasAttribute('page-partial')) file.src.contents = file.contents | ||
} | ||
file.contents = Buffer.from(doc.convert()) | ||
@@ -40,9 +37,2 @@ file.mediaType = 'text/html' | ||
function registerAliases (aliases, targetFile, contentCatalog) { | ||
if (!aliases) return | ||
aliases | ||
.split(COMMA_DELIMITER_RX) | ||
.forEach((aliasSpec) => aliasSpec && contentCatalog.registerPageAlias(aliasSpec, targetFile)) | ||
} | ||
module.exports = convertDocument |
'use strict' | ||
const convertDocument = require('./convert-document') | ||
const { loadAsciiDoc, extractAsciiDocMetadata } = require('@antora/asciidoc-loader') | ||
const COMMA_DELIMITER_RX = /\s*,\s*/ | ||
/** | ||
@@ -21,21 +24,50 @@ * Converts the contents of AsciiDoc files in the content catalog to embeddable HTML. | ||
function convertDocuments (contentCatalog, siteAsciiDocConfig = {}) { | ||
const asciidocConfigs = new Map( | ||
contentCatalog.getComponents().reduce((accum, { name, versions }) => { | ||
return accum.concat(versions.map(({ version, asciidocConfig }) => [name + '@' + version, asciidocConfig])) | ||
}, []) | ||
) | ||
const mainAsciiDocConfigs = new Map() | ||
contentCatalog.getComponents().forEach(({ name: component, versions }) => { | ||
versions.forEach(({ version, asciidoc }) => { | ||
mainAsciiDocConfigs.set(buildCacheKey({ component, version }), asciidoc) | ||
}) | ||
}) | ||
const headerAsciiDocConfigs = new Map() | ||
const headerOverrides = { extensions: [], headerOnly: true } | ||
for (const [cacheKey, mainAsciiDocConfig] of mainAsciiDocConfigs) { | ||
headerAsciiDocConfigs.set(cacheKey, Object.assign({}, mainAsciiDocConfig, headerOverrides)) | ||
} | ||
return contentCatalog | ||
.getPages() | ||
.filter((page) => page.out) | ||
.getPages((page) => page.out) | ||
.map((page) => { | ||
if (page.mediaType === 'text/asciidoc') { | ||
const asciidocConfig = asciidocConfigs.get(page.src.component + '@' + page.src.version) || siteAsciiDocConfig | ||
return convertDocument(page, contentCatalog, asciidocConfig) | ||
const asciidocConfig = headerAsciiDocConfigs.get(buildCacheKey(page.src)) | ||
const { attributes } = (page.asciidoc = extractAsciiDocMetadata( | ||
loadAsciiDoc(page, contentCatalog, asciidocConfig || Object.assign({}, siteAsciiDocConfig, headerOverrides)) | ||
)) | ||
Object.defineProperty(page, 'title', { | ||
get () { | ||
return this.asciidoc.doctitle | ||
}, | ||
}) | ||
registerPageAliases(attributes['page-aliases'], page, contentCatalog) | ||
if ('page-partial' in attributes) page.src.contents = page.contents | ||
} | ||
return page | ||
}) | ||
.map((page) => | ||
page.asciidoc | ||
? convertDocument(page, contentCatalog, mainAsciiDocConfigs.get(buildCacheKey(page.src)) || siteAsciiDocConfig) | ||
: page | ||
) | ||
.map((page) => delete page.src.contents && page) | ||
} | ||
module.exports = convertDocuments | ||
module.exports.convertDocument = convertDocument | ||
function buildCacheKey ({ component, version }) { | ||
return version + '@' + component | ||
} | ||
function registerPageAliases (aliases, targetFile, contentCatalog) { | ||
if (!aliases) return | ||
return aliases | ||
.split(COMMA_DELIMITER_RX) | ||
.forEach((aliasSpec) => aliasSpec && contentCatalog.registerPageAlias(aliasSpec, targetFile)) | ||
} | ||
module.exports = Object.assign(convertDocuments, { convertDocuments, convertDocument }) |
{ | ||
"name": "@antora/document-converter", | ||
"version": "2.3.0-alpha.2", | ||
"version": "2.3.0-beta.1", | ||
"description": "Converts AsciiDoc documents to embeddable HTML for use in an Antora documentation pipeline.", | ||
@@ -20,3 +20,3 @@ "license": "MPL-2.0", | ||
"dependencies": { | ||
"@antora/asciidoc-loader": "2.3.0-alpha.2" | ||
"@antora/asciidoc-loader": "2.3.0-beta.1" | ||
}, | ||
@@ -23,0 +23,0 @@ "engines": { |
6565
110
+ Added@antora/asciidoc-loader@2.3.0-beta.1(transitive)
- Removed@antora/asciidoc-loader@2.3.0-alpha.2(transitive)