Skip to content

Commit 20d78b0

Browse files
committed
DirectoryListing tag filter
1 parent 5ab1a24 commit 20d78b0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/components/DirectoryListing.astro

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ const props = z.object({
1515
descriptions: z.boolean().default(false),
1616
folder: z.string().optional(),
1717
maxDepth: z.number().default(1),
18+
tag: z.string().optional(),
1819
});
1920
20-
let { descriptions, folder, maxDepth } = props.parse(Astro.props);
21+
let { descriptions, folder, maxDepth, tag } = props.parse(Astro.props);
2122
2223
if (!folder) folder = Astro.params.slug!;
2324
@@ -34,7 +35,11 @@ function getChildren(parentPath: string, depth: number) {
3435
return allPages.filter((page) => {
3536
const pagePath = page.id;
3637
const pageDepth = pagePath.split("/").length;
37-
return pageDepth === depth && pagePath.startsWith(parentPath);
38+
return (
39+
pageDepth === depth &&
40+
pagePath.startsWith(parentPath) &&
41+
(tag ? page.data.tags?.includes(tag) : true)
42+
);
3843
});
3944
}
4045

src/content/docs/style-guide/components/directory-listing.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ When enabled, shows the [frontmatter `description`](/style-guide/frontmatter/) f
5353

5454
Controls how many levels of nested pages to display. A value of `1` shows only direct children, while higher values will show deeper nesting levels.
5555

56+
### `tag`
57+
58+
**type:** `string`
59+
60+
Optionally, filter the listing to only pages with a specific tag.
61+
5662
## Associated content types
5763

5864
- [Navigation](/style-guide/documentation-content-strategy/content-types/navigation/)

0 commit comments

Comments
 (0)