forked from sdarwin/antora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboost.js
77 lines (64 loc) · 2.36 KB
/
boost.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Copyright (c) 2023 Vinnie Falco ([email protected])
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Official repository: https://github.com/boostorg/antora
*/
'use strict'
const fs = require('node:fs');
const path = require('node:path');
/*
This extension allows every asciidoc attribute
specified in the playbook or the command line
to become a variable in the playbook using the
syntax ${var}.
*/
class Ext {
static register() {
new Ext(this)
}
constructor(ctx) {
;(this.ctx = ctx)
.on('contextStarted', this.contextStarted.bind(this))
}
doReplace1(elem, pat, sub) {
if (Array.isArray(elem)) {
for(var i = 0; i < elem.length; i++)
if (typeof elem[i] != "string")
this.doReplace1(elem[i], pat, sub)
else
elem[i] = elem[i].replaceAll(pat, sub)
} else if (typeof elem == 'object') {
for (let key in elem)
if (typeof elem[key] != "string")
this.doReplace1(elem[key], pat, sub)
else
elem[key] = elem[key].replaceAll(pat, sub)
}
}
doReplace(playbook) {
for (const [key, value] of Object.entries(playbook.asciidoc.attributes)) {
var pat = "${" + key + "}"
this.doReplace1(playbook.site, pat, value)
this.doReplace1(playbook.urls, pat, value)
this.doReplace1(playbook.content, pat, value)
this.doReplace1(playbook.output, pat, value)
this.doReplace1(playbook.ui, pat, value)
}
}
contextStarted({playbook}) {
var branch = playbook.asciidoc.attributes['page-boost-branch']
if(! branch )
throw new Error("Missing required attribute: asciidoc.attributes.page-boost-branch");
if( branch === "master" || branch === "develop") {
playbook.content.tags = ""
playbook.content.branches = branch
} else {
playbook.content.tags = "boost-" + branch
playbook.content.branches = null // disable branches
playbook.urls.latestVersionSegment = "" // disable tag in URL
}
this.doReplace(playbook);
}
}
module.exports = Ext