@antora/assembler 1.0.0-beta.9 → 1.0.0-rc.1
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/adapters/asciidoctor/jsonl-logger.rb +25 -0
- package/lib/assemble-content.js +93 -70
- package/lib/configure.js +31 -7
- package/lib/constants.js +22 -0
- package/lib/filter-component-versions.js +25 -62
- package/lib/load-config.js +74 -39
- package/lib/log-command.js +20 -0
- package/lib/produce-assembly-file.js +374 -403
- package/lib/produce-assembly-files.js +51 -60
- package/lib/select-mutable-attributes.js +1 -0
- package/lib/util/create-resource-key.js +7 -0
- package/lib/util/generate-scoped-id.js +25 -0
- package/lib/util/matcher.js +150 -0
- package/lib/util/parse-resource-ref.js +36 -0
- package/lib/util/resolver.js +36 -0
- package/lib/util/rewriter.js +206 -0
- package/lib/util/rx.js +5 -0
- package/lib/util/unconvert-inline-asciidoc.js +22 -14
- package/package.json +14 -12
- package/lib/util/compute-out.js +0 -57
- package/lib/util/create-asciidoc-file.js +0 -17
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const createResourceKey = require('./create-resource-key')
|
|
4
|
+
const generateScopedId = require('./generate-scoped-id')
|
|
5
|
+
const parseResourceRef = require('./parse-resource-ref')
|
|
6
|
+
const { resolveEmbedTarget, resolveLinkTarget } = require('./resolver')
|
|
7
|
+
|
|
8
|
+
const { NAMED_ID_ATTR_RX } = require('./rx')
|
|
9
|
+
|
|
10
|
+
function rewriteXrefs (
|
|
11
|
+
line,
|
|
12
|
+
contentCatalog,
|
|
13
|
+
assemblyModel,
|
|
14
|
+
ctx,
|
|
15
|
+
escapeForInline,
|
|
16
|
+
pagesInOutline,
|
|
17
|
+
idSeparators,
|
|
18
|
+
idLeader,
|
|
19
|
+
doc,
|
|
20
|
+
sourceLocation
|
|
21
|
+
) {
|
|
22
|
+
return line.replace(/(?<![\\+])xref:((?:\.\/)?[\p{Alpha}0-9_/.{#].*?)\[(|[\s\S]*?[^\\])\]/gu, (_, target, text) =>
|
|
23
|
+
rewriteXref(
|
|
24
|
+
target,
|
|
25
|
+
text,
|
|
26
|
+
contentCatalog,
|
|
27
|
+
assemblyModel,
|
|
28
|
+
ctx,
|
|
29
|
+
escapeForInline,
|
|
30
|
+
pagesInOutline,
|
|
31
|
+
idSeparators,
|
|
32
|
+
idLeader,
|
|
33
|
+
doc,
|
|
34
|
+
sourceLocation
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function rewriteXref (
|
|
40
|
+
target,
|
|
41
|
+
text,
|
|
42
|
+
contentCatalog,
|
|
43
|
+
assemblyModel,
|
|
44
|
+
ctx,
|
|
45
|
+
escapeForInline,
|
|
46
|
+
pagesInOutline,
|
|
47
|
+
idSeparators,
|
|
48
|
+
idLeader,
|
|
49
|
+
doc,
|
|
50
|
+
sourceLocation
|
|
51
|
+
) {
|
|
52
|
+
const rawTarget = target
|
|
53
|
+
if (doc && ~target.indexOf('{')) target = doc.$sub_attributes(target, global.Opal.hash({ attribute_missing: 'skip' }))
|
|
54
|
+
let fragment, resourceRef
|
|
55
|
+
const hashIdx = target.indexOf('#')
|
|
56
|
+
if (~hashIdx) {
|
|
57
|
+
resourceRef = target.substring(0, hashIdx)
|
|
58
|
+
fragment = target.substring(hashIdx + 1)
|
|
59
|
+
} else if (target.endsWith('.adoc') || ~target.indexOf('$')) {
|
|
60
|
+
resourceRef = target
|
|
61
|
+
fragment = ''
|
|
62
|
+
} else {
|
|
63
|
+
fragment = target
|
|
64
|
+
}
|
|
65
|
+
if (!resourceRef) return `xref:${idLeader == null ? rawTarget : idLeader + fragment}[${text}]`
|
|
66
|
+
let resourceId = parseResourceRef(resourceRef, ctx, 'page', contentCatalog)
|
|
67
|
+
const family = resourceId.family
|
|
68
|
+
let resource
|
|
69
|
+
if (family === 'page' && !contentCatalog.getById(resourceId)) {
|
|
70
|
+
if ((resource = contentCatalog.getById(Object.assign({}, resourceId, { family: 'alias' })))) {
|
|
71
|
+
resourceId = resource.rel.src
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (family !== 'page' || !(resource = pagesInOutline?.get(createResourceKey(resourceId)))) {
|
|
75
|
+
if ((resource = contentCatalog.getById(resourceId))?.pub) {
|
|
76
|
+
const { linkReferenceStyle, pubRoot, siteRoot } = assemblyModel
|
|
77
|
+
text ||= resource.asciidoc?.xreftext || rawTarget
|
|
78
|
+
if (siteRoot || linkReferenceStyle === 'relative') {
|
|
79
|
+
const hash = fragment && !(family === 'page' && fragment === resource.asciidoc.id) ? '#' + fragment : ''
|
|
80
|
+
return `${resolveLinkTarget(resource, siteRoot, pubRoot, linkReferenceStyle, escapeForInline)}${hash}[${text}]`
|
|
81
|
+
}
|
|
82
|
+
if (doc) {
|
|
83
|
+
const msg = `Cannot create external ${family} reference in assembly because site URL is unknown: ${rawTarget}`
|
|
84
|
+
doc.logger.warn(doc.createLogMessage(msg, { source_location: sourceLocation }))
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const linkAttrlist = text
|
|
88
|
+
? (~text.indexOf(',') ? `"${text}"` : text) + ',role=unresolved'
|
|
89
|
+
: (~target.indexOf(':') ? `${rawTarget},` : '') + 'role=unresolved'
|
|
90
|
+
return `link:${rawTarget}[${linkAttrlist}]`
|
|
91
|
+
}
|
|
92
|
+
if (fragment === resource.asciidoc.id) fragment = ''
|
|
93
|
+
if (
|
|
94
|
+
text &&
|
|
95
|
+
(assemblyModel.dropExplicitXrefText === 'always' ||
|
|
96
|
+
(assemblyModel.dropExplicitXrefText === 'if-redundant' && text === resource.title))
|
|
97
|
+
) {
|
|
98
|
+
text = ''
|
|
99
|
+
}
|
|
100
|
+
const componentVersionCtx = { name: ctx.component, version: ctx.version }
|
|
101
|
+
const refid = generateScopedId(
|
|
102
|
+
resource.src,
|
|
103
|
+
componentVersionCtx,
|
|
104
|
+
idSeparators,
|
|
105
|
+
assemblyModel.filetype,
|
|
106
|
+
text.length > 0
|
|
107
|
+
)
|
|
108
|
+
return `xref:${fragment ? refid + idSeparators.scope + fragment : refid}[${text}]`
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function rewriteImageAttr (val, contentCatalog, assemblyModel, ctx, assets) {
|
|
112
|
+
const match = val.startsWith('image:') && /^image::?(.+?)\[(.*?)\](@|)$/.exec(val)
|
|
113
|
+
if (!match) return
|
|
114
|
+
const newTarget = rewriteImageRef(match[1], contentCatalog, assemblyModel, ctx, assets)
|
|
115
|
+
return newTarget ? `image:${newTarget}[${match[2]}]${match[3]}` : val
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function rewriteInlineImages (line, contentCatalog, assemblyModel, ctx, assets, escapeForInline, doc) {
|
|
119
|
+
return line.replace(/(?<![\\+])image:([^:\s[](?:[^[]*[^\s[])?)\[(|[\s\S]*?[^\\])\]/g, (m, target, attrlist) => {
|
|
120
|
+
const newTarget = rewriteImageRef(target, contentCatalog, assemblyModel, ctx, assets, escapeForInline, doc)
|
|
121
|
+
return newTarget ? `image:${newTarget}[${attrlist}]` : m
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function rewriteImageRef (target, contentCatalog, assemblyModel, ctx, assets, escapeForInline, doc) {
|
|
126
|
+
if (doc && ~target.indexOf('{')) target = doc.$sub_attributes(target, global.Opal.hash({ attribute_missing: 'skip' }))
|
|
127
|
+
const image = isResourceRef(target) && contentCatalog.resolveResource(target, ctx, 'image', ['image'])
|
|
128
|
+
if (!image?.out) return
|
|
129
|
+
let newTarget
|
|
130
|
+
const { filetype, embedReferenceStyle, linkReferenceStyle, outDirname, pubRoot, siteRoot } = assemblyModel
|
|
131
|
+
if (filetype !== 'html') {
|
|
132
|
+
newTarget = resolveEmbedTarget(image, outDirname, embedReferenceStyle, escapeForInline ?? false)
|
|
133
|
+
assets.add(image)
|
|
134
|
+
} else if (siteRoot || linkReferenceStyle === 'relative') {
|
|
135
|
+
newTarget = resolveLinkTarget(image, siteRoot, pubRoot, linkReferenceStyle, escapeForInline ?? false, false)
|
|
136
|
+
if (linkReferenceStyle === 'relative') assets.add(image)
|
|
137
|
+
}
|
|
138
|
+
if (!newTarget) return
|
|
139
|
+
return newTarget
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function rewriteStyleAttribute (block, lines, idx, idLeader, replacementStyle = '') {
|
|
143
|
+
let prevLine = lines[idx - 1]
|
|
144
|
+
const char0 = prevLine?.charAt()
|
|
145
|
+
if (char0) {
|
|
146
|
+
if (
|
|
147
|
+
(char0 === '.' && /^\.\.?[^ \t.]/.test(prevLine)) ||
|
|
148
|
+
(char0 === '[' &&
|
|
149
|
+
prevLine.charAt(1) === '[' &&
|
|
150
|
+
/^\[\[(?:|[\p{Alpha}_:][\p{Alpha}0-9_\-:.]*(?:, *.+)?)\]\]$/u.test(prevLine))
|
|
151
|
+
) {
|
|
152
|
+
return rewriteStyleAttribute(block, lines, idx - 1, idLeader, replacementStyle)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
let cellSpec
|
|
156
|
+
const blockId = block.getId()
|
|
157
|
+
if (
|
|
158
|
+
char0 &&
|
|
159
|
+
(char0 === '[' || (block.getDocument().isNested() && (cellSpec = prevLine.match(/^([^[|]*)\| *(\[.+)/)))) &&
|
|
160
|
+
prevLine.charAt(prevLine.length - 1) === ']'
|
|
161
|
+
) {
|
|
162
|
+
if (cellSpec) {
|
|
163
|
+
prevLine = cellSpec[2]
|
|
164
|
+
cellSpec = cellSpec[1]
|
|
165
|
+
} else if (~prevLine.indexOf('id=')) {
|
|
166
|
+
prevLine = `[${prevLine.substring(1, prevLine.length - 1).replace(NAMED_ID_ATTR_RX, '')}]`
|
|
167
|
+
}
|
|
168
|
+
let rawStyle
|
|
169
|
+
const commaIdx = prevLine.indexOf(',')
|
|
170
|
+
if (~commaIdx) {
|
|
171
|
+
rawStyle = prevLine.substring(1, commaIdx)
|
|
172
|
+
if (~rawStyle.indexOf('=')) rawStyle = undefined
|
|
173
|
+
} else if (!~prevLine.indexOf('=')) {
|
|
174
|
+
rawStyle = prevLine.substring(1, prevLine.length - 1)
|
|
175
|
+
}
|
|
176
|
+
if (rawStyle) {
|
|
177
|
+
if (~rawStyle.indexOf('#')) {
|
|
178
|
+
prevLine = prevLine.replace(/#[^.%,\]]+/, `#${idLeader}${blockId}`)
|
|
179
|
+
if (replacementStyle) prevLine = prevLine.replace(/^[^#.%,\]]+/, `[${replacementStyle}`)
|
|
180
|
+
} else {
|
|
181
|
+
prevLine = `[${
|
|
182
|
+
replacementStyle ? rawStyle.replace(/^[^.%]*/, replacementStyle) : rawStyle
|
|
183
|
+
}#${idLeader}${blockId}${prevLine.substring(rawStyle.length + 1)}`
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
prevLine = `[${replacementStyle}#${idLeader}${blockId}${rawStyle == null ? ',' : ''}${prevLine.substring(1)}`
|
|
187
|
+
}
|
|
188
|
+
if (cellSpec) prevLine = `${cellSpec}|${prevLine}`
|
|
189
|
+
lines[idx - 1] = prevLine
|
|
190
|
+
} else {
|
|
191
|
+
lines.splice(idx, 0, `[${replacementStyle}#${idLeader}${blockId}]`)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function isResourceRef (str) {
|
|
196
|
+
return !(~str.indexOf(':') && (~str.indexOf('://') || (str.startsWith('data:') && ~str.indexOf(','))))
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
module.exports = {
|
|
200
|
+
rewriteXref,
|
|
201
|
+
rewriteXrefs,
|
|
202
|
+
rewriteImageAttr,
|
|
203
|
+
rewriteImageRef,
|
|
204
|
+
rewriteInlineImages,
|
|
205
|
+
rewriteStyleAttribute,
|
|
206
|
+
}
|
package/lib/util/rx.js
ADDED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const ATTRIBUTE_REFERENCE_RX = /\{[a-z0-9_][a-z0-9_-]*\}/g
|
|
4
4
|
const STRICT_WORD_CHAR_RX = /[\p{L}\d_]/u
|
|
5
5
|
const WORD_CHAR_RX = /[\p{L}\d_;}:<>]/u
|
|
6
|
+
const XML_SPECIAL_CHARS = { '<': '<', '>': '>', '&': '&' }
|
|
7
|
+
const XML_SPECIAL_CHARS_RX = /&(?:[lg]t|amp);/g
|
|
6
8
|
|
|
7
9
|
const MARK_FOR_TAG = { code: '`', em: '_', mark: '#', span: '#', strong: '*' }
|
|
8
10
|
const SKIP_SPAN = { icon: '<i ', image: '<img ' }
|
|
@@ -10,17 +12,17 @@ const SKIP_SPAN = { icon: '<i ', image: '<img ' }
|
|
|
10
12
|
module.exports = (str) => {
|
|
11
13
|
if (!str) return str
|
|
12
14
|
let matchIndex = str.indexOf('<')
|
|
13
|
-
if (!~matchIndex) return
|
|
15
|
+
if (!~matchIndex) return unconvertNonTag(str)
|
|
14
16
|
let current = { contents: '' }
|
|
15
17
|
const stack = [current]
|
|
16
18
|
let lastIndex = 0
|
|
17
19
|
do {
|
|
18
20
|
if (matchIndex > lastIndex) {
|
|
19
|
-
const matched = str.
|
|
20
|
-
current.contents +=
|
|
21
|
+
const matched = str.substring(lastIndex, matchIndex)
|
|
22
|
+
current.contents += unconvertNonTag(matched)
|
|
21
23
|
}
|
|
22
24
|
const isCloseTag = str[++matchIndex] === '/' ? ++matchIndex : false
|
|
23
|
-
let tagName = str.
|
|
25
|
+
let tagName = str.substring(matchIndex, (lastIndex = str.indexOf('>', matchIndex) + 1) - 1)
|
|
24
26
|
if (isCloseTag) {
|
|
25
27
|
const parent = current // TODO expect tagName to equal current.tagName
|
|
26
28
|
stack.pop()
|
|
@@ -43,13 +45,13 @@ module.exports = (str) => {
|
|
|
43
45
|
} else {
|
|
44
46
|
let attrs, attrlistIndex, role
|
|
45
47
|
if (~(attrlistIndex = tagName.indexOf(' '))) {
|
|
46
|
-
role = (attrs = parseAttrlist(tagName.
|
|
47
|
-
tagName = tagName.
|
|
48
|
+
role = (attrs = parseAttrlist(tagName.substring(attrlistIndex))).class
|
|
49
|
+
tagName = tagName.substring(0, attrlistIndex)
|
|
48
50
|
}
|
|
49
51
|
if (tagName === 'img') {
|
|
50
52
|
current.contents += 'image:' + attrs.src + '[' + attrs.alt + ']'
|
|
51
53
|
} else if (tagName === 'i' && current.tagName === 'span' && current.role === 'icon') {
|
|
52
|
-
current.contents += 'icon:' + role.
|
|
54
|
+
current.contents += 'icon:' + role.substring(6) + '[]'
|
|
53
55
|
lastIndex += 4
|
|
54
56
|
} else {
|
|
55
57
|
let check, mark
|
|
@@ -61,8 +63,8 @@ module.exports = (str) => {
|
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
} while (~(matchIndex = str.indexOf('<', lastIndex)))
|
|
64
|
-
const rest = str.
|
|
65
|
-
if (rest) current.contents +=
|
|
66
|
+
const rest = str.substring(lastIndex)
|
|
67
|
+
if (rest) current.contents += unconvertNonTag(rest)
|
|
66
68
|
return current.contents
|
|
67
69
|
}
|
|
68
70
|
|
|
@@ -73,16 +75,16 @@ function parseAttrlist (str) {
|
|
|
73
75
|
const spaceIndex = str.indexOf(' ', lastIndex)
|
|
74
76
|
const equalsIndex = str.indexOf('=', lastIndex)
|
|
75
77
|
if (~spaceIndex && spaceIndex < equalsIndex) {
|
|
76
|
-
attrs[str.
|
|
78
|
+
attrs[str.substring(lastIndex, (lastIndex = spaceIndex))] = true
|
|
77
79
|
} else if (~equalsIndex) {
|
|
78
|
-
const name = str.
|
|
80
|
+
const name = str.substring(lastIndex, equalsIndex)
|
|
79
81
|
const valueIndex = equalsIndex + 1
|
|
80
82
|
attrs[name] =
|
|
81
83
|
str.charAt(valueIndex) === '"'
|
|
82
|
-
? str.
|
|
83
|
-
: str.
|
|
84
|
+
? str.substring(valueIndex + 1, (lastIndex = str.indexOf('"', valueIndex + 1) + 1) - 1)
|
|
85
|
+
: str.substring(valueIndex, (lastIndex = ~spaceIndex ? spaceIndex : str.length))
|
|
84
86
|
} else {
|
|
85
|
-
attrs[str.
|
|
87
|
+
attrs[str.substring(lastIndex)] = true
|
|
86
88
|
break
|
|
87
89
|
}
|
|
88
90
|
}
|
|
@@ -93,3 +95,9 @@ function isWordChar (str, strict) {
|
|
|
93
95
|
if (!str) return false
|
|
94
96
|
return (strict ? STRICT_WORD_CHAR_RX : WORD_CHAR_RX).test(str)
|
|
95
97
|
}
|
|
98
|
+
|
|
99
|
+
function unconvertNonTag (str) {
|
|
100
|
+
if (~str.indexOf('{')) str = str.replace(ATTRIBUTE_REFERENCE_RX, '\\$&')
|
|
101
|
+
if (~str.indexOf('&')) str = str.replace(XML_SPECIAL_CHARS_RX, (m) => XML_SPECIAL_CHARS[m])
|
|
102
|
+
return str
|
|
103
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/assembler",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
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)",
|
|
@@ -19,38 +19,40 @@
|
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "node --test test/*-test.js",
|
|
22
|
-
"prepublishOnly": "npx -y downdoc --prepublish",
|
|
23
|
-
"postpublish": "npx -y downdoc --postpublish"
|
|
22
|
+
"prepublishOnly": "npx -y downdoc@latest --prepublish",
|
|
23
|
+
"postpublish": "npx -y downdoc@latest --postpublish"
|
|
24
24
|
},
|
|
25
25
|
"main": "lib/index.js",
|
|
26
26
|
"exports": {
|
|
27
27
|
".": "./lib/index.js",
|
|
28
28
|
"./filter-component-versions": "./lib/filter-component-versions.js",
|
|
29
29
|
"./load-config": "./lib/load-config.js",
|
|
30
|
+
"./log-command": "./lib/log-command.js",
|
|
30
31
|
"./produce-assembly-file": "./lib/produce-assembly-file.js",
|
|
31
32
|
"./produce-assembly-files": "./lib/produce-assembly-files.js",
|
|
32
|
-
"./select-mutable-attributes": "./lib/select-mutable-attributes.js"
|
|
33
|
+
"./select-mutable-attributes": "./lib/select-mutable-attributes.js",
|
|
34
|
+
"./package.json": "./package.json"
|
|
33
35
|
},
|
|
34
36
|
"imports": {
|
|
35
|
-
"#
|
|
37
|
+
"#asciidoctor-log-adapter": "./adapters/asciidoctor/jsonl-logger.rb",
|
|
36
38
|
"#unconvert-inline-asciidoc": "./lib/util/unconvert-inline-asciidoc.js"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
41
|
"@asciidoctor/reducer": "~1.1",
|
|
40
42
|
"@antora/expand-path-helper": "~3.0",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"js-yaml": "~4.1"
|
|
43
|
+
"@antora/run-command-helper": "~1.1",
|
|
44
|
+
"js-yaml": "~4.2"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@antora/asciidoc-loader": "
|
|
47
|
-
"@antora/navigation-builder": "
|
|
48
|
-
"@antora/site-publisher": "
|
|
47
|
+
"@antora/asciidoc-loader": "3.2.0-rc.2",
|
|
48
|
+
"@antora/navigation-builder": "3.2.0-rc.2",
|
|
49
|
+
"@antora/site-publisher": "3.2.0-rc.2"
|
|
49
50
|
},
|
|
50
51
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
52
|
+
"node": ">=20.0.0"
|
|
52
53
|
},
|
|
53
54
|
"files": [
|
|
55
|
+
"adapters/",
|
|
54
56
|
"lib/"
|
|
55
57
|
],
|
|
56
58
|
"keywords": [
|
package/lib/util/compute-out.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { posix: path } = require('node:path')
|
|
4
|
-
|
|
5
|
-
function computeOut (src) {
|
|
6
|
-
const { component, version, module: module_ = 'ROOT', family, relative } = src
|
|
7
|
-
const outRelative = family === 'page' ? relative.replace(/\.adoc$/, '.html') : relative
|
|
8
|
-
const { dir: dirname, base: basename } = path.parse(outRelative)
|
|
9
|
-
const componentVersion = this.getComponentVersion(component, version)
|
|
10
|
-
const versionSegment =
|
|
11
|
-
'activeVersionSegment' in componentVersion
|
|
12
|
-
? componentVersion.activeVersionSegment
|
|
13
|
-
: resolveActiveVersionSegment.call(this, component, version)
|
|
14
|
-
const outDirSegments = []
|
|
15
|
-
const moduleRootPathSegments = []
|
|
16
|
-
if (component !== 'ROOT') outDirSegments.push(component)
|
|
17
|
-
if (versionSegment) outDirSegments.push(versionSegment)
|
|
18
|
-
if (module_ !== 'ROOT') outDirSegments.push(module_)
|
|
19
|
-
const outModuleDirSegments = outDirSegments.slice()
|
|
20
|
-
if (family !== 'page') {
|
|
21
|
-
outDirSegments.push(`_${family}s`)
|
|
22
|
-
moduleRootPathSegments.push('..')
|
|
23
|
-
}
|
|
24
|
-
if (dirname) {
|
|
25
|
-
outDirSegments.push(dirname)
|
|
26
|
-
for (const _ of dirname.split('/')) moduleRootPathSegments.push('..')
|
|
27
|
-
}
|
|
28
|
-
const rootPathSegments = moduleRootPathSegments.slice()
|
|
29
|
-
for (const _ of outModuleDirSegments) rootPathSegments.push('..')
|
|
30
|
-
const outDirname = outDirSegments.join('/')
|
|
31
|
-
const result = {
|
|
32
|
-
dirname: outDirname,
|
|
33
|
-
basename,
|
|
34
|
-
path: outDirname + '/' + basename,
|
|
35
|
-
moduleRootPath: moduleRootPathSegments.length ? moduleRootPathSegments.join('/') : '.',
|
|
36
|
-
rootPath: rootPathSegments.length ? rootPathSegments.join('/') : '.',
|
|
37
|
-
}
|
|
38
|
-
return result
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function resolveActiveVersionSegment (component, version) {
|
|
42
|
-
let startPage = this.resolvePage('index.adoc', { component, version })
|
|
43
|
-
let startPageSrc
|
|
44
|
-
if (startPage) {
|
|
45
|
-
startPageSrc = startPage.src
|
|
46
|
-
} else {
|
|
47
|
-
startPageSrc = { component, version, module: 'ROOT', family: 'page', relative: 'index.adoc' }
|
|
48
|
-
this.removeFile((startPage = this.addFile({ src: startPageSrc })))
|
|
49
|
-
}
|
|
50
|
-
const outPathSegments = startPage.out.path.split('/')
|
|
51
|
-
for (const _ of startPage.out.moduleRootPath.split('/')) outPathSegments.pop()
|
|
52
|
-
if (startPageSrc.module !== 'ROOT') outPathSegments.pop()
|
|
53
|
-
if (startPageSrc.component !== 'ROOT') outPathSegments.shift()
|
|
54
|
-
return outPathSegments.length ? outPathSegments[0] : ''
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
module.exports = computeOut
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const computeOut = require('./compute-out')
|
|
4
|
-
|
|
5
|
-
function createAsciiDocFile (contentCatalog, file) {
|
|
6
|
-
file.mediaType = 'text/asciidoc'
|
|
7
|
-
const src = file.src
|
|
8
|
-
const out = computeOut.call(contentCatalog, src)
|
|
9
|
-
if (src.family === 'export') {
|
|
10
|
-
contentCatalog.removeFile((file = contentCatalog.addFile(Object.assign(file, { path: out.path, out: null }))))
|
|
11
|
-
return file
|
|
12
|
-
}
|
|
13
|
-
const pub = { url: '/' + out.path, moduleRootPath: out.moduleRootPath, rootPath: out.rootPath }
|
|
14
|
-
return { contents: src.contents ?? Buffer.alloc(0), src, out, pub }
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = createAsciiDocFile
|