From 2ba4972417d1aec9298cf7ec21d17dfb279d3513 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 20 Jun 2024 17:50:13 -0700 Subject: [PATCH] Page layout support --- README.adoc | 17 +++++++++++ .../lib/index.js | 3 +- .../zip-contents-collector-extension-test.js | 30 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 62239aa..8a5e33b 100644 --- a/README.adoc +++ b/README.adoc @@ -326,6 +326,23 @@ ext: path: api/java ---- +By default, content will be added using a 'bare' page layout which is supported regardless of the UI bundle you use. +To specify a different page layout, you can use the `layout` attribute: + +.antora.yml +[,yaml] +---- +name: my-project +version: true +# ... +ext: + zip_contents_collector: + include: + - name: api + destination: content_catalog + layout: custom +---- + === Using the Playbook to Include Content diff --git a/packages/antora-zip-contents-collector-extension/lib/index.js b/packages/antora-zip-contents-collector-extension/lib/index.js index 7da2df5..b635032 100644 --- a/packages/antora-zip-contents-collector-extension/lib/index.js +++ b/packages/antora-zip-contents-collector-extension/lib/index.js @@ -483,6 +483,7 @@ function register ({ config, downloadLog }) { function addToContentCatalog (contentCatalog, component, version, include, zipFile, file) { const moduleName = include.module || 'ROOT' + const pageLayout = include.layout || 'bare' file = asAntoraFile(include, zipFile, file, include.path, 'application/octet-stream', { component: component.name, version: version.version, @@ -490,7 +491,7 @@ function register ({ config, downloadLog }) { family: 'page', }) const pageAttributes = { - 'page-layout': 'bare', + 'page-layout': pageLayout, 'page-component-name': component.name, 'page-component-version': version.version, 'page-version': version.version, diff --git a/packages/antora-zip-contents-collector-extension/test/zip-contents-collector-extension-test.js b/packages/antora-zip-contents-collector-extension/test/zip-contents-collector-extension-test.js index a395edb..f9dac04 100644 --- a/packages/antora-zip-contents-collector-extension/test/zip-contents-collector-extension-test.js +++ b/packages/antora-zip-contents-collector-extension/test/zip-contents-collector-extension-test.js @@ -750,6 +750,8 @@ describe('zip contents collector extension', () => { expect(src.module).to.be.equal('ROOT') expect(src.family).to.be.equal('page') expect(src.component).to.be.equal('test') + const htmlFile = files.filter((file) => file.src.path === 'api/java/javadoc.html')[0] + expect(htmlFile.asciidoc.attributes['page-layout']).to.be.equal('bare') }, }) }) @@ -782,6 +784,34 @@ describe('zip contents collector extension', () => { }) }) + it('should download zip and collect files when adding to content catalog with layout', async () => { + const extensionConfig = () => ({ + locations: [{ url: `http://localhost:${httpServerPort}/\${name}.zip` }], + }) + const componentConfig = { + include: [{ name: 'javadoc', destination: 'content_catalog', path: 'api/java', layout: 'javadoc' }], + } + await runScenario({ + repoName: 'test-at-root', + extensionConfig, + componentConfig, + zipFiles: ['javadoc'], + httpPath: '/', + descriptorVersion: 'main', + before: ({ contentAggregate, contentCatalog }) => { + expect(contentAggregate).to.have.lengthOf(1) + expect(contentAggregate[0].files).to.be.empty() + }, + after: ({ contentAggregate, contentCatalog }) => { + expect(contentAggregate[0].files).to.have.lengthOf(0) + const files = contentCatalog.getFiles() + expect(files.filter((file) => file.src.path === 'api/java/javadoc.html')).to.have.lengthOf(1) + const htmlFile = files.filter((file) => file.src.path === 'api/java/javadoc.html')[0] + expect(htmlFile.asciidoc.attributes['page-layout']).to.be.equal('javadoc') + }, + }) + }) + it('should create dedicated cache folder for collector under Antora cache dir', async () => { await fsp.mkdir(CACHE_DIR, { recursive: true }) await fsp.writeFile(getCollectorCacheDir(), Buffer.alloc(0))