Skip to content

Commit b426f95

Browse files
committed
feat: Introduce zuul job for building docs
Signed-off-by: Artem Goncharov <[email protected]>
1 parent 1b864de commit b426f95

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"write-heading-ids": "docusaurus write-heading-ids",
3131
"typecheck": "tsc",
3232
"postinstall": "node getDocs.js && node populateStds.js && node populateCerts.js && node populateClouds.js",
33+
"postprocess": "node postprocess",
3334
"test": "echo \"Error: no test specified\" && exit 1",
3435
"lint:md": "markdownlint-cli2 \"**/*.md\"",
3536
"fix:md": "markdownlint-cli2-fix \"**/*.md\"",

playbooks/post.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- hosts: all
2+
tasks:
3+
- name: 'Postprocess docusaurus to generate artifacts usable for offline use'
4+
ansible.builtin.command: 'npm run postprocess'

postprocess.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict'
2+
3+
const fs = require('fs-extra')
4+
const path = require('path')
5+
const recursiveReaddir = require('recursive-readdir')
6+
7+
const buildDirectory = path.join(__dirname, 'build')
8+
const absoluteUrlRegExp = /(href|src)="(?!http[s]|ftp?:\/\/)([^"|#]+)"/g
9+
10+
const isDirectory = (dirPath) => path.extname(dirPath) === ''
11+
12+
const convertAbsolutePathsToRelative = (content, filePath) =>
13+
content.replace(absoluteUrlRegExp, (_absoluteUrl, $1, $2) => {
14+
const currentDirPath = path.dirname(filePath)
15+
const relativeDirPath =
16+
currentDirPath === '.' ? '.' : path.relative(currentDirPath, '')
17+
18+
let relativePath = path.join(relativeDirPath, $2)
19+
if (isDirectory(relativePath)) {
20+
relativePath = path.join(relativePath, 'index.html')
21+
}
22+
23+
return `${$1}="${relativePath}"`
24+
})
25+
26+
const websiteTextualFileExtensions = ['.css', '.js', '.html', '.xml']
27+
const isNotWebsiteTextualFile = (filePath, stats) =>
28+
!(
29+
stats.isDirectory() ||
30+
websiteTextualFileExtensions.includes(path.extname(filePath))
31+
)
32+
33+
const postProcess = async () => {
34+
const filePaths = await recursiveReaddir(buildDirectory, [
35+
isNotWebsiteTextualFile
36+
])
37+
await Promise.all(
38+
filePaths.map(async (filePath) => {
39+
const content = await fs.readFile(filePath)
40+
const relativePath = path.relative(buildDirectory, filePath)
41+
await fs.writeFile(
42+
filePath,
43+
convertAbsolutePathsToRelative(String(content), relativePath)
44+
)
45+
})
46+
)
47+
}
48+
49+
postProcess()

zuul.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
- job:
3+
name: docs-build
4+
parent: js-build
5+
nodeset: ubuntu-noble
6+
vars:
7+
node_version: 18
8+
javascript_content_dir: build
9+
# pre-run: playbooks/pre.yaml
10+
# run: playbooks/run.yaml
11+
post-run: playbooks/post.yaml
12+
13+
- project:
14+
merge-mode: squash-merge
15+
default-branch: main
16+
check:
17+
jobs:
18+
- docs-build

0 commit comments

Comments
 (0)