From 35c8351ea9228cc9b00add0a068e8395b00e53ec Mon Sep 17 00:00:00 2001 From: bfahrenfort Date: Tue, 13 Feb 2024 19:36:22 -0600 Subject: [PATCH] chore: rebase fix type error --- quartz/plugins/emitters/contentIndex.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/quartz/plugins/emitters/contentIndex.ts b/quartz/plugins/emitters/contentIndex.ts index 15561486b..4d4b72f8e 100644 --- a/quartz/plugins/emitters/contentIndex.ts +++ b/quartz/plugins/emitters/contentIndex.ts @@ -50,7 +50,7 @@ function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndex): string { return `${urls}` } -function generateRSSFeed(cfg: GlobalConfiguration, idx?: ContentIndex, limit?: number): string { +function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: number): string { if (idx == undefined) { return "" } @@ -94,7 +94,7 @@ function generateRSSFeed(cfg: GlobalConfiguration, idx?: ContentIndex, limit?: n ` } -export const ContentIndex: QuartzEmitterPlugin> = (opts) => { +export const ContentIndex: QuartzEmitterPlugin = (opts) => { opts = { ...defaultOptions, ...opts } return { name: "ContentIndex", @@ -122,7 +122,12 @@ export const ContentIndex: QuartzEmitterPlugin> = (opts) => { const cfg = ctx.cfg.configuration const emitted: FilePath[] = [] const feedIndices: Map = new Map() - for (const feed of opts?.feedDirectories) { + + // bfahrenfort: ts can't see the expansion of opts above that guarantees a non-null feedDirectories + const directories = + opts?.feedDirectories == null ? defaultOptions.feedDirectories : opts.feedDirectories + + for (const feed of directories) { const linkIndex: ContentIndex = new Map() for (const [tree, file] of content) { const slug = file.data.slug! @@ -152,7 +157,9 @@ export const ContentIndex: QuartzEmitterPlugin> = (opts) => { emitted.push( await write({ ctx, - content: generateSiteMap(cfg, feedIndices.get("index")), + // bfahrenfort: "index" is guaranteed non-null + // see directories instantiation and feedIndices.set iterating over directories + content: generateSiteMap(cfg, feedIndices.get("index")!), slug: "sitemap" as FullSlug, ext: ".xml", }), @@ -160,10 +167,11 @@ export const ContentIndex: QuartzEmitterPlugin> = (opts) => { } if (opts?.enableRSS) { - opts?.feedDirectories?.map(async (feed) => { + directories.map(async (feed) => { const emittedFeed = await write({ ctx, - content: generateRSSFeed(cfg, feedIndices.get(feed), opts?.rssLimit), + // bfahrenfort: we just generated a feedIndices entry for every directories entry, guaranteed non-null + content: generateRSSFeed(cfg, feedIndices.get(feed)!, opts?.rssLimit), slug: feed as FullSlug, ext: ".xml", })