Skip to content

Commit 7045d55

Browse files
Update Antora UI extensions for local docs preview (#647)
1 parent 9e25b78 commit 7045d55

File tree

6 files changed

+106
-47
lines changed

6 files changed

+106
-47
lines changed

docs/extensions/assets-processor.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use strict";
2+
3+
module.exports.register = (context) => {
4+
const logger = context.getLogger("assets-processor-extension");
5+
6+
context.once("uiLoaded", ({ uiCatalog }) => {
7+
const manifestContents = uiCatalog
8+
.findByType("asset")
9+
.find((file) => file.stem === "assets-manifest")
10+
.contents?.toString();
11+
if (!manifestContents) {
12+
logger.error("Could not find assets-manifest.json in the UI bundle.");
13+
return;
14+
}
15+
const manifest = JSON.parse(manifestContents);
16+
// Add manifest to node global context so it can be accessed by the handlebars helper during createPageComposer
17+
global.assetsManifest = manifest;
18+
});
19+
20+
context.once("pagesComposed", () => {
21+
// Clean up the global context
22+
delete global.assetsManifest;
23+
});
24+
};

docs/extensions/tailwind-processor.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
'use strict'
1+
"use strict";
22

3-
const { execSync } = require('child_process')
3+
const { execSync } = require("child_process");
44

55
module.exports.register = (context) => {
6-
context.once('sitePublished', () => {
6+
context.once("sitePublished", ({ playbook }) => {
77
const logger = context.getLogger('tailwind-processor-extension')
8-
logger.info('Building Tailwind')
9-
execSync('npm run tailwindcss', { stdio: 'inherit' })
10-
logger.info('Tailwind Build Successful')
11-
})
12-
}
8+
const outputDir = playbook?.output?.dir || "build/site";
9+
logger.info("Building Tailwind");
10+
var configPath = execSync(`find ${outputDir} -name tailwind.config.js`)
11+
.toString()
12+
.trim();
13+
var cssPath = execSync(`find ${outputDir} -name site*.css`)
14+
.toString()
15+
.trim();
16+
logger.info(
17+
`npm run tailwindcss --tailwind-config-path=${configPath} --css-path=${cssPath}`
18+
);
19+
execSync(
20+
`npm run tailwindcss --tailwind-config-path=${configPath} --css-path=${cssPath}`,
21+
{ stdio: "inherit" }
22+
);
23+
logger.info("Tailwind Build Successful");
24+
});
25+
};
Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
module.exports.register = function ({ config }) {
2-
const { addToNavigation, unlistedPagesHeading = 'Unlisted Pages' } = config
3-
const logger = this.getLogger('unlisted-pages-extension')
4-
this
5-
.on('navigationBuilt', ({ contentCatalog }) => {
6-
contentCatalog.getComponents().forEach(({ versions }) => {
7-
versions.forEach(({ name: component, version, navigation: nav, url: defaultUrl }) => {
8-
const navEntriesByUrl = getNavEntriesByUrl(nav)
9-
const unlistedPages = contentCatalog
10-
.findBy({ component, version, family: 'page' })
11-
.filter((page) => page.out)
12-
.reduce((collector, page) => {
13-
// Check if the 'unlisted-page' attribute is set to true
14-
if (page.asciidoc.attributes['unlisted-page'] === 'true') {
15-
return collector; // Skip this page
16-
}
17-
if ((page.pub.url in navEntriesByUrl) || page.pub.url === defaultUrl) return collector
18-
logger.warn({ file: page.src, source: page.src.origin }, 'detected unlisted page')
19-
return collector.concat(page)
20-
}, [])
21-
if (unlistedPages.length && addToNavigation) {
22-
nav.push({
23-
content: unlistedPagesHeading,
24-
items: unlistedPages.map((page) => {
25-
return { content: page.asciidoc.navtitle, url: page.pub.url, urlType: 'internal' }
26-
}),
27-
root: true,
28-
})
29-
}
2+
const { addToNavigation, unlistedPagesHeading = 'Unlisted Pages' } = config
3+
const logger = this.getLogger('unlisted-pages-extension')
4+
this
5+
.on('navigationBuilt', ({ contentCatalog }) => {
6+
contentCatalog.getComponents().forEach(({ versions }) => {
7+
versions.forEach(({ name: component, version, navigation: nav, url: defaultUrl }) => {
8+
const navEntriesByUrl = getNavEntriesByUrl(nav)
9+
const unlistedPages = contentCatalog
10+
.findBy({ component, version, family: 'page' })
11+
.filter((page) => page.out)
12+
.reduce((collector, page) => {
13+
// Check if the 'unlisted-page' attribute is set to true
14+
if (page.asciidoc.attributes['unlisted-page'] === 'true') {
15+
return collector; // Skip this page
16+
}
17+
if ((page.pub.url in navEntriesByUrl) || page.pub.url === defaultUrl) return collector
18+
logger.warn({ file: page.src, source: page.src.origin }, 'detected unlisted page')
19+
return collector.concat(page)
20+
}, [])
21+
if (unlistedPages.length && addToNavigation) {
22+
nav.push({
23+
content: unlistedPagesHeading,
24+
items: unlistedPages.map((page) => {
25+
return { content: page.asciidoc.navtitle, url: page.pub.url, urlType: 'internal' }
26+
}),
27+
root: true,
28+
})
29+
}
30+
})
3031
})
3132
})
32-
})
33-
}
33+
}
3434

35-
function getNavEntriesByUrl (items = [], accum = {}) {
36-
items.forEach((item) => {
37-
if (item.urlType === 'internal') accum[item.url.split('#')[0]] = item
38-
getNavEntriesByUrl(item.items, accum)
39-
})
40-
return accum
41-
}
35+
function getNavEntriesByUrl (items = [], accum = {}) {
36+
items.forEach((item) => {
37+
if (item.urlType === 'internal') accum[item.url.split('#')[0]] = item
38+
getNavEntriesByUrl(item.items, accum)
39+
})
40+
return accum
41+
}

docs/local-preview-playbook.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ content:
1919

2020
antora:
2121
extensions:
22+
- '@antora/atlas-extension'
2223
- '@antora/collector-extension'
24+
- extensions/assets-processor.js
2325
- extensions/tailwind-processor.js
2426
- id: unlisted-pages
2527
enabled: true
@@ -36,7 +38,8 @@ asciidoc:
3638
- asciidoctor-external-callout
3739
attributes:
3840
# BUILT-IN ATTRIBUTES
39-
allow-uri-read: '' # this has no effect in antora, but does help development in Intellij
41+
# allow-uri-read: '' # Quality-of-life benefit for IntelliJ users. CAUTION: Opens the door to malicious code insertion - must remain disabled in prod build environment.
42+
# hide-uri-scheme: '' # Consider enabling this attribute to make raw http hyperlinks look cleaner.
4043
experimental: ''
4144
idprefix: ''
4245
idseparator: '-'
@@ -55,8 +58,20 @@ asciidoc:
5558
astra_db: 'Astra DB'
5659
astra_stream: 'Astra Streaming'
5760
astra_ui: 'Astra Portal'
61+
astra_cli: 'Astra CLI'
62+
astra-streaming-examples-repo: 'https://raw.githubusercontent.com/datastax/astra-streaming-examples/master'
63+
luna-streaming-examples-repo: 'https://raw.githubusercontent.com/datastaxdevs/luna-streaming-examples/main'
5864
support_url: 'https://support.datastax.com'
5965
glossary-url: 'https://docs.datastax.com/en/glossary/docs/index.html#'
66+
emoji-tada: "🎉"
67+
emoji-rocket: "🚀"
68+
emoji-smile: "&#128512"
69+
dse: 'DataStax Enterprise (DSE)'
70+
cassandra: 'Apache Cassandra(R)'
71+
classic: 'classic'
72+
classic_cap: 'Classic'
73+
serverless: 'serverless'
74+
serverless_cap: 'Serverless'
6075
# Antora Atlas
6176
primary-site-url: https://docs.datastax.com/en
6277
primary-site-manifest-url: https://docs.datastax.com/en/site-manifest.json

docs/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"url": "https://github.com/datastax/ragstack-ai.git"
1010
},
1111
"scripts": {
12-
"tailwindcss": "tailwindcss build -c ./build/site/_/js/tailwind.config.js -i ./build/site/_/css/site.css -o ./build/site/_/css/site.css --minify",
12+
"tailwindcss": "tailwindcss build -c ${npm_config_tailwind_config_path} -i ${npm_config_css_path} -o ${npm_config_css_path} --minify",
1313
"build:local": "env FORCE_SHOW_EDIT_PAGE_LINK=true antora --clean --fetch --stacktrace local-preview-playbook.yml"
1414
},
1515
"dependencies": {
@@ -20,6 +20,7 @@
2020
"asciidoctor-external-callout": "~1.2.1",
2121
"asciidoctor-kroki": "~0.18.1",
2222
"csv-parser": "^3.0.0",
23+
"lodash": "^4.17.21",
2324
"npm-run-all": "^4.1.5",
2425
"tailwindcss": "^3.3.5"
2526
}

0 commit comments

Comments
 (0)