diff --git a/.github/workflows/publish-site.yml b/.github/workflows/publish-site.yml index ca7b715..6cb73f9 100644 --- a/.github/workflows/publish-site.yml +++ b/.github/workflows/publish-site.yml @@ -29,7 +29,7 @@ jobs: with: node-version: '18' - name: Generate Site - run: npx -y antora antora-playbook.yml + run: npx -y antora --html-url-extension-style=indexify antora-playbook.yml - name: Upload Artifact uses: actions/upload-pages-artifact@v2 - name: Deploy Artifact to GitHub Pages diff --git a/antora-playbook.yml b/antora-playbook.yml index 77fa0bb..c1f61fc 100644 --- a/antora-playbook.yml +++ b/antora-playbook.yml @@ -1,4 +1,7 @@ # npx antora antora-playbook.yml +antora: + extensions: + - ./lib/component-url-prefix-extension.js site: title: Eclipse Jetty url: https://jetty.org diff --git a/lib/component-url-prefix-extension.js b/lib/component-url-prefix-extension.js new file mode 100644 index 0000000..80b9e00 --- /dev/null +++ b/lib/component-url-prefix-extension.js @@ -0,0 +1,24 @@ +'use strict' + +const path = require('node:path/posix') + +module.exports.register = function ({ config: { prefix = 'docs' } }) { + if ((prefix = path.join('.', prefix || '', '.')) === '.' || prefix === '..') return + this.once('contentClassified', ({ contentCatalog }) => { + contentCatalog.getComponents().filter(({ name }) => applyTo(name, prefix)).forEach(({ versions }) => { + versions.forEach((version) => { + version.url = `/${prefix}${version.url}` + }) + }) + contentCatalog.getFiles().filter((file) => file.out && applyTo(file.src.component, prefix)).forEach(({ out, pub }) => { + out.path = path.join((out.dirname = path.join(prefix, out.dirname)), out.basename) + out.rootPath = path.join('..', out.rootPath) + pub.url = `/${prefix}${pub.url}` + pub.rootPath = path.join('..', pub.rootPath) + }) + }) +} + +function applyTo (name, prefix) { + return !(name === 'ROOT' || name === prefix) +}