Skip to content

Commit 9aff2d3

Browse files
committed
add extension that sets page-project-url and page-project-host attributes on component version
1 parent f240887 commit 9aff2d3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

antora-playbook.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ antora:
22
extensions:
33
- ./ext/asciidoctor-compliance-settings.js
44
- ./ext/promote-favicon-to-root.js
5+
- ./ext/assign-project-url.js
56
- ./ext/page-location.js
67
runtime:
78
cache_dir: ./.cache/antora

ext/assign-project-url.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict'
2+
3+
module.exports.register = function () {
4+
// could switch this to componentsRegistered after upgrading to Antora 3.2
5+
this.once('contentClassified', ({ siteAsciiDocConfig, contentCatalog }) => {
6+
contentCatalog.getComponents().forEach((component) => {
7+
component.versions.forEach((componentVersion) => {
8+
const componentVersionId = { component: component.name, version: componentVersion.version }
9+
const componentVersionStartPage = contentCatalog.resolvePage('index.adoc', componentVersionId)
10+
if (!componentVersionStartPage) return
11+
const { startPath, webUrl } = componentVersionStartPage.src.origin
12+
if (!(startPath === 'docs' && webUrl)) return
13+
if (componentVersion.asciidoc === siteAsciiDocConfig) {
14+
componentVersion.asciidoc = Object.assign(
15+
{},
16+
siteAsciiDocConfig,
17+
{ attributes: Object.assign({}, siteAsciiDocConfig.attributes) }
18+
)
19+
}
20+
componentVersion.asciidoc.attributes['page-project-url'] = webUrl
21+
componentVersion.asciidoc.attributes['page-project-host'] = ~webUrl.indexOf('gitlab') ? 'gitlab' : 'github'
22+
})
23+
})
24+
})
25+
}

0 commit comments

Comments
 (0)