@antora/assembler 1.0.0-beta.19 → 1.0.0-beta.20
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/lib/assemble-content.js
CHANGED
|
@@ -40,7 +40,7 @@ async function assembleContent (playbook, contentCatalog, converter, { configSou
|
|
|
40
40
|
const { loadAsciiDoc = require('@antora/asciidoc-loader') } = generatorFunctions
|
|
41
41
|
const { assembly: assemblyConfig, build: buildConfig } = assemblerConfig
|
|
42
42
|
assemblyConfig.embedReferenceStyle = embedReferenceStyle
|
|
43
|
-
const
|
|
43
|
+
const profile = (assemblyConfig.profile ??= targetBackend)
|
|
44
44
|
const intrinsicAttributes = { 'loader-assembler': '' }
|
|
45
45
|
buildConfig.cwd ??= process.cwd()
|
|
46
46
|
if (profile) {
|
|
@@ -131,56 +131,72 @@ async function assembleContent (playbook, contentCatalog, converter, { configSou
|
|
|
131
131
|
* the keys from the profile as well as any inherited shared keys, builds the navigation for the assembly, and
|
|
132
132
|
* returns the initialized assembly model. The assembly model is further populated after the call to this function.
|
|
133
133
|
*/
|
|
134
|
-
function generateSelectAssemblyProfile (context, contentCatalog,
|
|
134
|
+
function generateSelectAssemblyProfile (context, contentCatalog, baseModel, intrinsicAttributes, navigationCatalog) {
|
|
135
135
|
const logger = context.getLogger?.(PACKAGE_NAME)
|
|
136
136
|
const { assemblerProfiles } = context.getVariables()
|
|
137
137
|
if (!assemblerProfiles) {
|
|
138
138
|
return (componentVersion) => {
|
|
139
139
|
const navigation =
|
|
140
140
|
navigationCatalog?.getNavigation(componentVersion.name, componentVersion.version) ?? componentVersion.navigation
|
|
141
|
-
return Object.assign({},
|
|
141
|
+
return Object.assign({}, baseModel, { attributes: Object.assign({}, baseModel.attributes), navigation, logger })
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
const boundSendToLog = sendToLog.bind(logger)
|
|
145
|
-
const {
|
|
145
|
+
const {
|
|
146
|
+
buildNavigation = require('@antora/navigation-builder'),
|
|
147
|
+
buildAlternateNavigation = buildNavigation.buildAlternateNavigation ??
|
|
148
|
+
buildAlternateNavigationShim.bind(null, buildNavigation),
|
|
149
|
+
} = context.getFunctions()
|
|
146
150
|
return (componentVersion) => {
|
|
147
|
-
const attributes = Object.assign({},
|
|
151
|
+
const attributes = Object.assign({}, baseModel.attributes)
|
|
148
152
|
const componentVersionProfiles = assemblerProfiles.get(componentVersion.version + '@' + componentVersion.name)
|
|
149
|
-
const overrides =
|
|
150
|
-
componentVersionProfiles?.get(intrinsicAttributes['assembler-profile']) ?? componentVersionProfiles?.get() ?? {}
|
|
153
|
+
const overrides = componentVersionProfiles?.get(baseModel.profile) ?? componentVersionProfiles?.get() ?? {}
|
|
151
154
|
const { navFiles, messages } = overrides
|
|
152
|
-
Object.entries(overrides.attributes ?? {}).forEach(([name, val]) =>
|
|
153
|
-
|
|
154
|
-
})
|
|
155
|
-
const model = Object.assign({}, base, overrides, { attributes, logger })
|
|
155
|
+
Object.entries(overrides.attributes ?? {}).forEach(([name, val]) => (attributes[name] = val))
|
|
156
|
+
const model = Object.assign({}, baseModel, overrides, { attributes, logger })
|
|
156
157
|
delete model.navFiles
|
|
157
158
|
delete model.messages
|
|
158
159
|
const navigationOverride = navigationCatalog?.getNavigation(componentVersion.name, componentVersion.version)
|
|
159
160
|
if (navigationOverride) return Object.assign(model, { navigation: navigationOverride })
|
|
160
161
|
messages?.forEach(boundSendToLog)
|
|
161
|
-
model
|
|
162
|
-
if (!navFiles) return model
|
|
162
|
+
if (!navFiles) return Object.assign(model, { navigation: componentVersion.navigation })
|
|
163
163
|
if (!navFiles.length) return Object.assign(model, { navigation: [] })
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
componentVersion.asciidoc = Object.assign({}, asciidoc_, {
|
|
167
|
-
attributes: Object.assign({}, asciidoc_.attributes, intrinsicAttributes),
|
|
164
|
+
model.navigation = buildAlternateNavigation(contentCatalog, componentVersion, navFiles, {
|
|
165
|
+
attributes: intrinsicAttributes,
|
|
168
166
|
})
|
|
169
|
-
buildNavigation(
|
|
170
|
-
new Proxy(contentCatalog, {
|
|
171
|
-
get (target, property) {
|
|
172
|
-
const method = target[property]
|
|
173
|
-
if (property !== 'findBy') return method
|
|
174
|
-
return (criteria) => (toJSON(criteria) === '{"family":"nav"}' ? navFiles : method.call(target, criteria))
|
|
175
|
-
},
|
|
176
|
-
})
|
|
177
|
-
)
|
|
178
|
-
model.navigation = componentVersion.navigation
|
|
179
|
-
Object.assign(componentVersion, { asciidoc: asciidoc_, navigation: navigation_ })
|
|
180
167
|
return model
|
|
181
168
|
}
|
|
182
169
|
}
|
|
183
170
|
|
|
171
|
+
function buildAlternateNavigationShim (
|
|
172
|
+
buildNavigation,
|
|
173
|
+
contentCatalog,
|
|
174
|
+
componentVersion,
|
|
175
|
+
navFiles,
|
|
176
|
+
asciidocConfigOverrides
|
|
177
|
+
) {
|
|
178
|
+
const { asciidoc: asciidoc_, navigation: navigation_ } = componentVersion
|
|
179
|
+
const asciidocConfig = (componentVersion.asciidoc = Object.assign({}, asciidoc_))
|
|
180
|
+
if (asciidocConfigOverrides) {
|
|
181
|
+
const attributesOverrides =
|
|
182
|
+
'attributes' in asciidocConfigOverrides
|
|
183
|
+
? { attributes: Object.assign({}, asciidocConfig.attributes, asciidocConfigOverrides.attributes) }
|
|
184
|
+
: undefined
|
|
185
|
+
Object.assign(asciidocConfig, asciidocConfigOverrides, attributesOverrides)
|
|
186
|
+
}
|
|
187
|
+
const contentCatalogProxy = new Proxy(contentCatalog, {
|
|
188
|
+
get (target, property) {
|
|
189
|
+
const method = target[property]
|
|
190
|
+
if (property !== 'findBy') return method
|
|
191
|
+
return (criteria) => (toJSON(criteria) === '{"family":"nav"}' ? navFiles : method.call(target, criteria))
|
|
192
|
+
},
|
|
193
|
+
})
|
|
194
|
+
buildNavigation(contentCatalogProxy)
|
|
195
|
+
const navigation = componentVersion.navigation
|
|
196
|
+
Object.assign(componentVersion, { asciidoc: asciidoc_, navigation: navigation_ })
|
|
197
|
+
return navigation
|
|
198
|
+
}
|
|
199
|
+
|
|
184
200
|
function prepareConvertAttributes (doc, targetExtname, relativeToOutput, assemblerConfig) {
|
|
185
201
|
const {
|
|
186
202
|
asciidoc: { attributes: docAttributes } = { attributes: {} },
|
|
@@ -193,14 +209,13 @@ function prepareConvertAttributes (doc, targetExtname, relativeToOutput, assembl
|
|
|
193
209
|
const docfile = ospath.join(dir, reldocfile)
|
|
194
210
|
const outdir = ospath.dirname(docfile)
|
|
195
211
|
const docdir = relativeToOutput ? dir : outdir
|
|
196
|
-
const imagesdir = ''
|
|
197
212
|
const outfile = docfile.slice(0, docfile.length - docfilesuffix.length) + targetExtname
|
|
198
213
|
const attributes = Object.assign({ revdate: `${assemblerConfig.assembly.revdate}@` }, docAttributes, {
|
|
199
214
|
docdir,
|
|
200
215
|
docfile,
|
|
201
216
|
docfilesuffix,
|
|
202
217
|
'docname@': docname,
|
|
203
|
-
imagesdir,
|
|
218
|
+
imagesdir: '',
|
|
204
219
|
outdir,
|
|
205
220
|
outfile,
|
|
206
221
|
outfilesuffix: targetExtname,
|
package/lib/configure.js
CHANGED
|
@@ -44,7 +44,8 @@ function getAssemblerProfiles (contentCatalog, assemblerProfiles = new Map()) {
|
|
|
44
44
|
contentCatalog.getComponents().forEach((component) => {
|
|
45
45
|
component.versions.forEach((componentVersion) => {
|
|
46
46
|
const source =
|
|
47
|
-
componentVersion.nav?.origin ??
|
|
47
|
+
componentVersion.nav?.origin ??
|
|
48
|
+
[...(componentVersion.origins ?? [])].find((it) => it.descriptor?.ext?.assembler)
|
|
48
49
|
const assemblerConfig = getAssemblerConfigFromDescriptor(source?.descriptor)
|
|
49
50
|
if (!assemblerConfig) return
|
|
50
51
|
const componentVersionRef = `${componentVersion.version}@${componentVersion.name}`
|
|
@@ -36,12 +36,13 @@ function compilePatterns (patterns) {
|
|
|
36
36
|
})
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
function filterComponentVersions (components, patterns) {
|
|
39
|
+
function filterComponentVersions (components, { names: patterns, prereleases = true }) {
|
|
40
40
|
if (!patterns.length) return []
|
|
41
41
|
const rxs = compilePatterns(patterns)
|
|
42
42
|
return components.reduce((accum, { latest, versions }) => {
|
|
43
43
|
accum.push(
|
|
44
44
|
...versions.filter((version) => {
|
|
45
|
+
if (!prereleases && version.prerelease && version !== latest) return false
|
|
45
46
|
let matched
|
|
46
47
|
for (const rx of rxs) {
|
|
47
48
|
let voteIfMatched
|
|
@@ -22,6 +22,7 @@ const DISCARD_ATTRIBUTE_NAMES = [
|
|
|
22
22
|
'leveloffset',
|
|
23
23
|
'assembly-header-attributes',
|
|
24
24
|
'assembly-navtitle',
|
|
25
|
+
'assembly-slug',
|
|
25
26
|
'assembly-style',
|
|
26
27
|
'underscore',
|
|
27
28
|
]
|
|
@@ -76,8 +77,8 @@ function produceAssemblyFile (
|
|
|
76
77
|
mutableAttributes,
|
|
77
78
|
assemblyModel
|
|
78
79
|
)
|
|
79
|
-
const stem = rootLevel === 0 ? 'index' :
|
|
80
|
-
const downloadStem = [component, version,
|
|
80
|
+
const stem = buffer.slug ? sanitizeSlug(buffer.slug) : generateSlug(rootLevel === 0 ? 'index' : buffer.navtitle)
|
|
81
|
+
const downloadStem = [component, version, stem === 'index' ? '' : stem].filter((it) => it).join('-')
|
|
81
82
|
return createAsciiDocFile(contentCatalog, {
|
|
82
83
|
asciidoc: asciidocConfig,
|
|
83
84
|
assembler: { assembled: pagesInOutline.assembled, downloadStem, rootLevel },
|
|
@@ -204,6 +205,7 @@ function mergeAsciiDoc (
|
|
|
204
205
|
})
|
|
205
206
|
: doc.getLogger()
|
|
206
207
|
doc.source_header_attributes ??= doc.parent.$to_h()
|
|
208
|
+
if (isRootPage && doc.hasAttribute('assembly-slug')) buffer.slug = doc.getAttribute('assembly-slug')
|
|
207
209
|
if (doc.hasAttribute('assembly-navtitle')) {
|
|
208
210
|
navtitleAsciiDoc = doc.getAttribute('assembly-navtitle')
|
|
209
211
|
navtitlePlain = sanitize((navtitle = doc.$apply_reftext_subs(navtitleAsciiDoc)))
|
|
@@ -731,8 +733,9 @@ function processDocumentHeader (doc, lines, ignoreLines, isRootPage) {
|
|
|
731
733
|
return entries
|
|
732
734
|
}
|
|
733
735
|
|
|
734
|
-
function generateSlug (
|
|
735
|
-
return
|
|
736
|
+
function generateSlug (string) {
|
|
737
|
+
if (string === 'index') return string
|
|
738
|
+
return string
|
|
736
739
|
.toLowerCase()
|
|
737
740
|
.replace(/<[^>]+>/g, '')
|
|
738
741
|
.replace(CHAR_REF_RX, (_, name, dec, hex) => {
|
|
@@ -744,6 +747,10 @@ function generateSlug (title) {
|
|
|
744
747
|
.replace(/^-+|-+$|(-)-+/g, '$1')
|
|
745
748
|
}
|
|
746
749
|
|
|
750
|
+
function sanitizeSlug (slug) {
|
|
751
|
+
return slug.replace(/ /g, '-').replace(/[^\p{Alpha}0-9_.-]/gu, '-')
|
|
752
|
+
}
|
|
753
|
+
|
|
747
754
|
function fixSectionLevels (sections, expectedLevel) {
|
|
748
755
|
sections.forEach((sect) => {
|
|
749
756
|
const forceLevel = expectedLevel ?? Math.min(1, sect.getLevel())
|
|
@@ -28,7 +28,7 @@ function produceAssemblyFiles (loadAsciiDoc, contentCatalog, assemblerConfig, se
|
|
|
28
28
|
const publishableFiles = contentCatalog.getFiles().filter((file) => file.out)
|
|
29
29
|
let siteRoot
|
|
30
30
|
const configMdc = assemblerConfig.file ? { file: { path: assemblerConfig.file } } : {}
|
|
31
|
-
return filterComponentVersions(contentCatalog.getComponents(), assemblerConfig.componentVersionFilter
|
|
31
|
+
return filterComponentVersions(contentCatalog.getComponents(), assemblerConfig.componentVersionFilter).reduce(
|
|
32
32
|
(accum, componentVersion) => {
|
|
33
33
|
const assemblyModel = selectAssemblyProfile(componentVersion)
|
|
34
34
|
const { attributes: assemblyAttributes, logger, navigation, rootLevel } = assemblyModel
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/assembler",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.20",
|
|
4
4
|
"description": "A JavaScript library that merges AsciiDoc content from multiple pages in an Antora site into assembly files and delegates to an exporter to convert those files to another format, such as PDF.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "OpenDevise Inc. (https://opendevise.com)",
|