From 006d60695761ec10e5c4e715ed2212cd1fbedda0 Mon Sep 17 00:00:00 2001 From: Reuben Tier Date: Wed, 27 Sep 2023 12:18:55 +0100 Subject: Prevent crashing with no content folder (#745) Co-authored-by: Chris Swithinbank --- .changeset/cool-moons-thank.md | 5 +++++ packages/starlight/utils/routing.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/cool-moons-thank.md diff --git a/.changeset/cool-moons-thank.md b/.changeset/cool-moons-thank.md new file mode 100644 index 00000000..ec20b878 --- /dev/null +++ b/.changeset/cool-moons-thank.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': patch +--- + +Prevent Starlight crashing when the content folder doesn't exist, or is empty diff --git a/packages/starlight/utils/routing.ts b/packages/starlight/utils/routing.ts index 56bd7c84..6af940c8 100644 --- a/packages/starlight/utils/routing.ts +++ b/packages/starlight/utils/routing.ts @@ -35,7 +35,7 @@ interface Path extends GetStaticPathsItem { const normalizeIndexSlug = (slug: string) => (slug === 'index' ? '' : slug); /** All entries in the docs content collection. */ -const docs: StarlightDocsEntry[] = (await getCollection('docs')).map(({ slug, ...entry }) => ({ + const docs: StarlightDocsEntry[] = (await getCollection('docs') ?? []).map(({ slug, ...entry }) => ({ ...entry, slug: normalizeIndexSlug(slug), })); -- cgit