Skip to content

Commit 6937602

Browse files
committed
fix: demo urls in manifest
1 parent 3c92c14 commit 6937602

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

docs/components/demos.11tydata.cjs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
1-
const { dirname } = require('path');
21
module.exports = {
32
templateEngineOverride: 'njk',
43
permalink: '{{ demo.permalink }}',
54
pagination: {
65
data: 'demos',
76
alias: 'demo',
87
size: 1,
9-
// somehow the main pf-icon demo is being printed twice.
10-
// so we'll group by tag name, and only take the first of each.
11-
before: demos => Object.values(Object.groupBy(demos
12-
.filter(demo => demo.permalink?.includes(demo.tagName))
13-
.map(demo => {
14-
if (demo.filePath?.endsWith(`${demo.tagName}.html`)) {
15-
return {
16-
...demo,
17-
permalink: `${dirname(demo.permalink)}/`,
18-
};
19-
} else {
20-
return demo;
21-
}
22-
}), demo => demo.tagName)).map(([x]) => x),
8+
before: demos => demos.filter(demo => demo.tagName === demo.primaryElementName),
239
},
2410
};

scripts/cem-demo-index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ const copy = structuredClone(manifest) as M.Package;
1515
const getSlug = (demo: M.Demo) =>
1616
demo.url.match(RE)?.groups?.slug ?? '';
1717

18-
const isMainDemo = (demo: M.Demo): boolean =>
19-
demo.url.endsWith(`${getSlug(demo)}/`)
20-
|| demo.url.endsWith('demo/');
18+
const isMainDemo = (tagName: string, demo: M.Demo): boolean =>
19+
demo.url.endsWith(`demo/${tagName}/`);
2120

2221
// replace all canonical demos with /
2322
// e.g.
@@ -34,11 +33,12 @@ await writeFile('custom-elements.json', JSON.stringify({
3433
...decl,
3534
demos:
3635
!isCustomElementDeclaration(decl) ? undefined
37-
: decl.demos?.map(demo => isMainDemo(demo) ? ({
36+
: decl.demos?.map(demo => isMainDemo(decl.tagName!, demo) ? ({
3837
...demo,
3938
url: `https://patternflyelements.com/components/${getSlug(demo)}/demo/`,
4039
}) : demo)
41-
.sort((a, b) => isMainDemo(a) ? -1 : isMainDemo(b) ? 1 : 0),
40+
.sort((a, b) =>
41+
isMainDemo(decl.tagName!, a) ? -1 : isMainDemo(decl.tagName!, b) ? 1 : 0),
4242
})),
4343
})),
4444
}, null, 2), 'utf-8');

0 commit comments

Comments
 (0)