Skip to content

Commit

Permalink
refactor: mostly whitespace changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Jan 27, 2025
1 parent 5564865 commit 6c71197
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions docs/_plugins/element-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,14 @@ function isHidden(tagName: string) {

export default function(eleventyConfig: UserConfig) {
eleventyConfig.addCollection('elementDocs', async function() {
try {
const [manifest] = getAllManifests();

const _docsPages =
eleventyConfig.globalData.elements as DocsPage[] | (() => Promise<DocsPage[]>);

const docsPages = typeof _docsPages === 'function' ? await _docsPages() : _docsPages;

// 1. compile a list of all sibling element names by scanning the filesystem
// 2. compile a list of all output files
// 3. assign helpful data to each page entry
// 4. compile a list of tabs for each page's subnav.
// this step depends on the full list from step 2.
// 5. assign data which relies on the filesystem (async)
// 1. compile a list of all sibling element names by scanning the filesystem
// 2. compile a list of all output files
// 3. assign helpful data to each page entry
// 4. compile a list of tabs for each page's subnav.
// this step depends on the full list from step 2.
// 5. assign data which relies on the filesystem (async)

try {
const siblingElementsByTagName = new Map<string, string[]>();
for await (const path of glob(`elements/*/*.ts`, { cwd })) {
const tagName = path.replace('elements/', '').split('/').shift()!;
Expand All @@ -124,26 +117,33 @@ export default function(eleventyConfig: UserConfig) {
}
}

return (await Promise.all(
Array.from(new Set([
// docs file paths that exist on disk
...await Array.fromAsync(glob(`elements/*/docs/*.md`, { cwd })),
// ensure that code and demos pages are generated, should there not be any content for them
// in elements/*/docs/*-code.md or elements/*/docs/*-demos.md. Duplicates are avoided with
// the new Set constructor
...(await Array.fromAsync(glob('elements/*', { cwd }), x =>
const [manifest] = getAllManifests();

const _docsPages =
eleventyConfig.globalData.elements as DocsPage[] | (() => Promise<DocsPage[]>);

const docsPages = typeof _docsPages === 'function' ? await _docsPages() : _docsPages;

const allFiles = Array.from(new Set([
// docs file paths that exist on disk
...await Array.fromAsync(glob(`elements/*/docs/*.md`, { cwd })),
// ensure that code and demos pages are generated, should there not be any content for them
// in elements/*/docs/*-code.md or elements/*/docs/*-demos.md. Duplicates are avoided with
// the new Set constructor
...(await Array.fromAsync(glob('elements/*', { cwd }), x =>
x.includes('.') ? [] : [
`${x}/docs/30-code.md`,
`${x}/docs/90-demos.md`,
])).flat(),
]))
]));

return (await Promise.all(
allFiles
.sort()
.map(filePath => {
const tagName = filePath
.split(sep)
.find(x => x.startsWith('rh-'))!;
const pageSlug = filePath
.split(sep)
const pathParts = filePath.split(sep);
const tagName = pathParts.find(x => x.startsWith('rh-'))!;
const pageSlug = pathParts
.pop()
?.split('.')
?.shift()
Expand Down Expand Up @@ -217,7 +217,7 @@ export default function(eleventyConfig: UserConfig) {
overviewImageHref,
siblingElements: siblingElementsByTagName.get(data.tagName) ?? [],
};
})
}) satisfies Promise<ElementDocsPageData>[]
));
} catch (e) {
// it's important to surface this
Expand Down

0 comments on commit 6c71197

Please sign in to comment.