Skip to content

Commit

Permalink
Update UI extensions for local preview
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-schneider committed Aug 23, 2024
1 parent c9e5faf commit 928263e
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 47 deletions.
24 changes: 24 additions & 0 deletions lib/assets-processor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

module.exports.register = (context) => {
const logger = context.getLogger("assets-processor-extension");

context.once("uiLoaded", ({ uiCatalog }) => {
const manifestContents = uiCatalog
.findByType("asset")
.find((file) => file.stem === "assets-manifest")
.contents?.toString();
if (!manifestContents) {
logger.error("Could not find assets-manifest.json in the UI bundle.");
return;
}
const manifest = JSON.parse(manifestContents);
// Add manifest to node global context so it can be accessed by the handlebars helper during createPageComposer
global.assetsManifest = manifest;
});

context.once("pagesComposed", () => {
// Clean up the global context
delete global.assetsManifest;
});
};
29 changes: 21 additions & 8 deletions lib/tailwind-processor.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
'use strict'
"use strict";

const { execSync } = require('child_process')
const { execSync } = require("child_process");

module.exports.register = (context) => {
context.once('sitePublished', () => {
context.once("sitePublished", ({ playbook }) => {
const logger = context.getLogger('tailwind-processor-extension')
logger.info('Building Tailwind')
execSync('npm run tailwindcss', { stdio: 'inherit' })
logger.info('Tailwind Build Successful')
})
}
const outputDir = playbook?.output?.dir || "build/site";
logger.info("Building Tailwind");
var configPath = execSync(`find ${outputDir} -name tailwind.config.js`)
.toString()
.trim();
var cssPath = execSync(`find ${outputDir} -name site*.css`)
.toString()
.trim();
logger.info(
`npm run tailwindcss --tailwind-config-path=${configPath} --css-path=${cssPath}`
);
execSync(
`npm run tailwindcss --tailwind-config-path=${configPath} --css-path=${cssPath}`,
{ stdio: "inherit" }
);
logger.info("Tailwind Build Successful");
});
};
74 changes: 37 additions & 37 deletions lib/unlisted-pages-extension.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
module.exports.register = function ({ config }) {
const { addToNavigation, unlistedPagesHeading = 'Unlisted Pages' } = config
const logger = this.getLogger('unlisted-pages-extension')
this
.on('navigationBuilt', ({ contentCatalog }) => {
contentCatalog.getComponents().forEach(({ versions }) => {
versions.forEach(({ name: component, version, navigation: nav, url: defaultUrl }) => {
const navEntriesByUrl = getNavEntriesByUrl(nav)
const unlistedPages = contentCatalog
.findBy({ component, version, family: 'page' })
.filter((page) => page.out)
.reduce((collector, page) => {
// Check if the 'unlisted-page' attribute is set to true
if (page.asciidoc.attributes['unlisted-page'] === 'true') {
return collector; // Skip this page
}
if ((page.pub.url in navEntriesByUrl) || page.pub.url === defaultUrl) return collector
logger.warn({ file: page.src, source: page.src.origin }, 'detected unlisted page')
return collector.concat(page)
}, [])
if (unlistedPages.length && addToNavigation) {
nav.push({
content: unlistedPagesHeading,
items: unlistedPages.map((page) => {
return { content: page.asciidoc.navtitle, url: page.pub.url, urlType: 'internal' }
}),
root: true,
})
}
const { addToNavigation, unlistedPagesHeading = 'Unlisted Pages' } = config
const logger = this.getLogger('unlisted-pages-extension')
this
.on('navigationBuilt', ({ contentCatalog }) => {
contentCatalog.getComponents().forEach(({ versions }) => {
versions.forEach(({ name: component, version, navigation: nav, url: defaultUrl }) => {
const navEntriesByUrl = getNavEntriesByUrl(nav)
const unlistedPages = contentCatalog
.findBy({ component, version, family: 'page' })
.filter((page) => page.out)
.reduce((collector, page) => {
// Check if the 'unlisted-page' attribute is set to true
if (page.asciidoc.attributes['unlisted-page'] === 'true') {
return collector; // Skip this page
}
if ((page.pub.url in navEntriesByUrl) || page.pub.url === defaultUrl) return collector
logger.warn({ file: page.src, source: page.src.origin }, 'detected unlisted page')
return collector.concat(page)
}, [])
if (unlistedPages.length && addToNavigation) {
nav.push({
content: unlistedPagesHeading,
items: unlistedPages.map((page) => {
return { content: page.asciidoc.navtitle, url: page.pub.url, urlType: 'internal' }
}),
root: true,
})
}
})
})
})
})
}
}

function getNavEntriesByUrl (items = [], accum = {}) {
items.forEach((item) => {
if (item.urlType === 'internal') accum[item.url.split('#')[0]] = item
getNavEntriesByUrl(item.items, accum)
})
return accum
}
function getNavEntriesByUrl (items = [], accum = {}) {
items.forEach((item) => {
if (item.urlType === 'internal') accum[item.url.split('#')[0]] = item
getNavEntriesByUrl(item.items, accum)
})
return accum
}
16 changes: 15 additions & 1 deletion local-preview-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ antora:
extensions:
- '@antora/atlas-extension'
- '@antora/collector-extension'
- lib/assets-processor.js
- lib/tailwind-processor.js
- id: unlisted-pages
enabled: true
Expand All @@ -36,7 +37,8 @@ asciidoc:
- asciidoctor-external-callout
attributes:
# BUILT-IN ATTRIBUTES
allow-uri-read: '' # this has no effect in antora, but does help development in Intellij
# 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.
# hide-uri-scheme: '' # Consider enabling this attribute to make raw http hyperlinks look cleaner.
experimental: ''
idprefix: ''
idseparator: '-'
Expand All @@ -55,8 +57,20 @@ asciidoc:
astra_db: 'Astra DB'
astra_stream: 'Astra Streaming'
astra_ui: 'Astra Portal'
astra_cli: 'Astra CLI'
astra-streaming-examples-repo: 'https://raw.githubusercontent.com/datastax/astra-streaming-examples/master'
luna-streaming-examples-repo: 'https://raw.githubusercontent.com/datastaxdevs/luna-streaming-examples/main'
support_url: 'https://support.datastax.com'
glossary-url: 'https://docs.datastax.com/en/glossary/docs/index.html#'
emoji-tada: "🎉"
emoji-rocket: "🚀"
emoji-smile: "&#128512"
dse: 'DataStax Enterprise (DSE)'
cassandra: 'Apache Cassandra(R)'
classic: 'classic'
classic_cap: 'Classic'
serverless: 'serverless'
serverless_cap: 'Serverless'
# Antora Atlas
primary-site-url: https://docs.datastax.com/en
primary-site-manifest-url: https://docs.datastax.com/en/site-manifest.json
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"url": "https://github.com/datastax/migration-docs.git"
},
"scripts": {
"tailwindcss": "tailwindcss build -c ./build/site/_/js/tailwind.config.js -i ./build/site/_/css/site.css -o ./build/site/_/css/site.css --minify",
"tailwindcss": "tailwindcss build -c ${npm_config_tailwind_config_path} -i ${npm_config_css_path} -o ${npm_config_css_path} --minify",
"build:local": "env FORCE_SHOW_EDIT_PAGE_LINK=true antora --clean --fetch --stacktrace local-preview-playbook.yml"
},
"dependencies": {
Expand Down

0 comments on commit 928263e

Please sign in to comment.