Skip to content

Commit

Permalink
hide hidden files/directories ( starts with _ )
Browse files Browse the repository at this point in the history
  • Loading branch information
noxify committed Jan 22, 2025
1 parent 1618960 commit 9062aa9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const AriaDocsCollection = new Directory({
basePath: "aria-docs",
loaders: {
mdx: withSchema<DocSchema>(
// {frontmatter: frontmatterSchema},
(path) => import(`@content/docs/aria-docs/${path}.mdx`),
),
},
Expand Down
21 changes: 18 additions & 3 deletions src/lib/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ export interface TreeItem {
children?: TreeItem[]
}

/**
* Checks if an entry is hidden (starts with an underscore)
*
* @param entry {EntryType} the entry to check for visibility
* @returns {boolean}
*/
export function isHidden(entry: EntryType) {
return entry.getBaseName().startsWith("_")
}

/** Create a slug from a string. */
// source: https://github.com/souporserious/renoun/blob/main/packages/renoun/src/utils/create-slug.ts
export function createSlug(input: string) {
Expand All @@ -24,6 +34,9 @@ export function createSlug(input: string) {
// source:
// https://github.com/souporserious/renoun/blob/main/packages/renoun/src/file-system/index.test.ts
async function buildTreeNavigation(entry: EntryType): Promise<TreeItem | null> {
if (isHidden(entry)) {
return null
}
if (isDirectory(entry)) {
return {
title: entry.getTitle(),
Expand Down Expand Up @@ -58,7 +71,9 @@ async function buildTreeNavigation(entry: EntryType): Promise<TreeItem | null> {
}

export async function getTree(sources: EntryType[]): Promise<TreeItem[]> {
return (await Promise.all(sources.map(buildTreeNavigation))).filter(
(ele) => !!ele,
)
return (
await Promise.all(
sources.filter((ele) => !isHidden(ele)).map(buildTreeNavigation),
)
).filter((ele) => !!ele)
}

0 comments on commit 9062aa9

Please sign in to comment.