Skip to content

Commit

Permalink
docs: try to hack playgrounds
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Oct 23, 2023
1 parent 64d159f commit 67b23dd
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions docs/_data/playgrounds.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ module.exports = async function(data) {
const { parseFragment, serialize } = await import('parse5');
const Tools = await import('@parse5/tools');

function append(node, ...nodes) {

Tools.spliceChildren(node, Infinity, 0, ...nodes);

}

const demoManifests = groupBy('primaryElementName', data.demos);

const playgroundConfigsMap = new Map();
Expand All @@ -95,10 +101,8 @@ module.exports = async function(data) {

const baseCssPathPrefix = demo.filePath.match(DEMO_FILEPATH_IS_MAIN_DEMO_RE) ? '' : '../';

Tools.spliceChildren(
append(
fragment,
Infinity,
0,
Tools.createCommentNode('playground-fold'),
Tools.createElement('link', {
rel: 'stylesheet',
Expand All @@ -122,8 +126,6 @@ module.exports = async function(data) {
hidden: true,
});

let content = demoPaths(serialize(fragment), demo.filePath);

const modulesAndLinks = Tools.queryAll(fragment, node =>
Tools.isElementNode(node) &&
isModuleScript(node) ||
Expand Down Expand Up @@ -160,11 +162,17 @@ module.exports = async function(data) {
const modules = Tools.queryAll(fragment, node => Tools.isElementNode(node) && isModuleScript(node));
Array.from(modules).forEach((el, i) => {
const moduleName = `demo/${primaryElementName}-${demoSlug}-inline-script-${i++}.js`;
content += `
<!-- playground-hide -->
<script type="module" src="./${moduleName}></script>
<!-- playground-hide-end -->
`;
append(
fragment,
Tools.createCommentNode('playground-hide'),
Tools.createElement('script', {
type: 'module',
src: `./${moduleName}`,
}),
Tools.createTextNode('\n\n'),
Tools.createCommentNode('playground-hide-end'),
);

fileMap.set(moduleName, {
contentType: 'application/javascript',
content: el.childNodes.map(x => x.value).join('\n'),
Expand All @@ -175,7 +183,7 @@ module.exports = async function(data) {
fileMap.set(filename, {
contentType: 'text/html',
selected: isMainDemo,
content,
content: demoPaths(serialize(fragment), demo.filePath),
label: demo.title,
});

Expand Down

0 comments on commit 67b23dd

Please sign in to comment.