-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update UI extensions for local preview
- Loading branch information
1 parent
c9e5faf
commit 928263e
Showing
5 changed files
with
98 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters