UNPKG

@antora/assembler

Version:

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.

37 lines (34 loc) 1.46 kB
'use strict' function parseResourceRef (ref, ctx = {}, family = undefined, contentCatalog = undefined) { const atIdx = ref.indexOf('@') let firstColonIdx = ref.indexOf(':') let component, version, module_ if (~atIdx && (~firstColonIdx ? atIdx < firstColonIdx : true)) { if ((version = ref.slice(0, atIdx)) === '_') version = '' ref = ref.slice(atIdx + 1) if (~firstColonIdx) firstColonIdx -= atIdx + 1 } const addColons = ~firstColonIdx ? (~ref.indexOf(':', firstColonIdx + 1) ? '' : ':') : '::' const segments = (addColons + ref).split(':') if ((component = segments[0])) { module_ = segments[1] || 'ROOT' version ??= contentCatalog?.getComponent(component)?.latest.version } else { component = ctx.component version ??= ctx.version module_ = segments[1] || ctx.module || 'ROOT' } let relative = segments.length > 3 ? segments.slice(2).join(':') : segments[2] const dollarIdx = relative.indexOf('$') if (~dollarIdx) { family = relative.slice(0, dollarIdx) || family relative = relative.slice(dollarIdx + 1) } if (relative.charAt() === '.' && relative.charAt(1) === '/') { const ctxRelative = ctx.relative const topic = ctxRelative ? ctxRelative.slice(0, (ctxRelative.lastIndexOf('/') + 1 || 1) - 1) : undefined relative = (topic ? topic + '/' : '') + relative.slice(2) } return { component, version, module: module_, family, relative } } module.exports = parseResourceRef