diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 259588ffa77370c36ac98a4d0ef8b24b79a0dc8e..9ee7adf1f30f5c28a1be25652d9ebfbda22bbc48 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -23,6 +23,7 @@ For a detailed view of what's changed, refer to the {url-repo}/commits[commit hi * add default text to link that points to page outside of the aggregate document * scope IDs for pages not from current component (#37) * don't insert start page if it points outside current component version (#44) +* convert reference to attachment in nav to external link if site URL is specified (#45) === Changed diff --git a/packages/assembler/lib/produce-aggregate-document.js b/packages/assembler/lib/produce-aggregate-document.js index 0baaba3bcf9ee84adc8469e7550dbb3007e236f6..002f95f410c6a2d0a15c3036daadb53dadd6d9b6 100644 --- a/packages/assembler/lib/produce-aggregate-document.js +++ b/packages/assembler/lib/produce-aggregate-document.js @@ -460,6 +460,7 @@ function aggregateAsciiDoc ( } else { buffer.push('') // NOTE: try to toggle sectids; otherwise, fallback to globally unique synthetic ID + // Q: should we unset docname, page-module, etc? let toggleSectids, syntheticId if (!('sectids' in asciidocConfig.attributes)) { buffer.push(':!sectids:') @@ -472,11 +473,16 @@ function aggregateAsciiDoc ( syntheticId = `__object-id-${global.Opal.hash(outlineEntry).$object_id()}` } } - // Q: should we unset docname, page-module, etc? - const sectionTitle = - urlType === 'external' - ? `${url}[${navtitlePass ? navtitleAsciiDoc : navtitleAsciiDoc.replace(/\]/g, '\\]')}]` - : navtitleAsciiDoc + let sectionTitle = navtitleAsciiDoc + if (urlType === 'external') { + sectionTitle = `${url}[${navtitlePass ? navtitleAsciiDoc : navtitleAsciiDoc.replace(/\]/g, '\\]')}]` + } else if (urlType === 'internal' && !unresolved && siteUrl) { + const resource = contentCatalog.getFiles().find((it) => it.pub.url === url) + if (resource?.out) { + sectionTitle = navtitlePass ? navtitleAsciiDoc : navtitleAsciiDoc.replace(/\]/g, '\\]') + sectionTitle = `${siteUrl}${resource.pub.url}[${sectionTitle}]` + } + } let hlevel = level + 1 if (hlevel > 6) { hlevel = 6 diff --git a/packages/assembler/test/produce-aggregate-documents-test.js b/packages/assembler/test/produce-aggregate-documents-test.js index 3cf2341b71d65267f06d77ac6239f1c1f1741be4..8bcc52391e0d96de15c1d13b1251f93a23ed58cb 100644 --- a/packages/assembler/test/produce-aggregate-documents-test.js +++ b/packages/assembler/test/produce-aggregate-documents-test.js @@ -27,6 +27,10 @@ describe('produceAggregateDocuments()', () => { await runScenario('ignore-duplicate-nav-entry', __dirname) }) + it('should handle navigation entry with attachment reference', async () => { + await runScenario('attachment-reference', __dirname) + }) + it('should handle navigation entry with external link', async () => { await runScenario('external-link', __dirname) }) diff --git a/packages/assembler/test/scenarios/attachment-reference/data.yml b/packages/assembler/test/scenarios/attachment-reference/data.yml new file mode 100644 index 0000000000000000000000000000000000000000..35d34757bcc8d4b03ed5d9b8cc991a249a186ad1 --- /dev/null +++ b/packages/assembler/test/scenarios/attachment-reference/data.yml @@ -0,0 +1,19 @@ +name: the-component +version: '1.0' +title: The Component +navigation: + items: + - content: xref:the-page.adoc[] + - content: xref:attachment$form.pdf[Form Title] +files: +- relative: the-page.adoc + contents: |- + = The Page Title + + contents +- relative: form.pdf + family: attachment +assembler: + asciidoc: + attributes: + site-url: https://docs.example.org diff --git a/packages/assembler/test/scenarios/attachment-reference/expects/the-component.adoc b/packages/assembler/test/scenarios/attachment-reference/expects/the-component.adoc new file mode 100644 index 0000000000000000000000000000000000000000..ad3803939f6ac474da4b876e68a7863d0ddd370f --- /dev/null +++ b/packages/assembler/test/scenarios/attachment-reference/expects/the-component.adoc @@ -0,0 +1,26 @@ += The Component +:revnumber: 1.0 +:doctype: book +:underscore: _ +:page-component-name: the-component +:page-component-version: 1.0 +:page-version: {page-component-version} +:page-component-display-version: 1.0 +:page-component-title: The Component + +:docname: the-page +:page-module: ROOT +:page-relative-src-path: the-page.adoc +:page-origin-url: https://github.com/acme/the-component +:page-origin-start-path: +:page-origin-refname: v1.0 +:page-origin-reftype: branch +:page-origin-refhash: a00000000000000000000000000000000000000z +[#the-page:::] +== The Page Title + +contents + +:!sectids: +== https://docs.example.org/the-component/1.0/_attachments/form.pdf[Form Title] +:sectids: