Skip to content

Commit 9b7a987

Browse files
Update UI extensions for local preview
1 parent 99c5ecb commit 9b7a987

5 files changed

+87
-48
lines changed

lib/assets-processor.js

+24
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+
};

lib/tailwind-processor.js

+21-8
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+
};

lib/unlisted-pages-extension.js

+37-37
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+
}

local-preview-playbook.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ antora:
2020
extensions:
2121
- '@antora/atlas-extension'
2222
- '@antora/collector-extension'
23+
- lib/assets-processor.js
2324
- lib/tailwind-processor.js
2425
- id: unlisted-pages
2526
enabled: true
@@ -36,7 +37,8 @@ asciidoc:
3637
- asciidoctor-external-callout
3738
attributes:
3839
# BUILT-IN ATTRIBUTES
39-
allow-uri-read: '' # this has no effect in antora, but does help development in Intellij
40+
# 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.
41+
# hide-uri-scheme: '' # Consider enabling this attribute to make raw http hyperlinks look cleaner.
4042
experimental: ''
4143
idprefix: ''
4244
idseparator: '-'
@@ -64,7 +66,7 @@ asciidoc:
6466
emoji-rocket: "🚀"
6567
emoji-smile: "&#128512"
6668
dse: 'DataStax Enterprise (DSE)'
67-
cassandra: 'Apache Cassandra®'
69+
cassandra: 'Apache Cassandra(R)'
6870
classic: 'classic'
6971
classic_cap: 'Classic'
7072
serverless: 'serverless'

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"url": "https://github.com/datastax/pulsar-docs.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": {

0 commit comments

Comments
 (0)