chore: rebase fix type error

This commit is contained in:
bfahrenfort 2024-02-13 19:36:22 -06:00
parent c1b7ef4f6f
commit 35c8351ea9

View File

@ -50,7 +50,7 @@ function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndex): string {
return `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">${urls}</urlset>` return `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">${urls}</urlset>`
} }
function generateRSSFeed(cfg: GlobalConfiguration, idx?: ContentIndex, limit?: number): string { function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: number): string {
if (idx == undefined) { if (idx == undefined) {
return "" return ""
} }
@ -94,7 +94,7 @@ function generateRSSFeed(cfg: GlobalConfiguration, idx?: ContentIndex, limit?: n
</rss>` </rss>`
} }
export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => { export const ContentIndex: QuartzEmitterPlugin<Options> = (opts) => {
opts = { ...defaultOptions, ...opts } opts = { ...defaultOptions, ...opts }
return { return {
name: "ContentIndex", name: "ContentIndex",
@ -122,7 +122,12 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
const cfg = ctx.cfg.configuration const cfg = ctx.cfg.configuration
const emitted: FilePath[] = [] const emitted: FilePath[] = []
const feedIndices: Map<String, ContentIndex> = new Map() const feedIndices: Map<String, ContentIndex> = 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() const linkIndex: ContentIndex = new Map()
for (const [tree, file] of content) { for (const [tree, file] of content) {
const slug = file.data.slug! const slug = file.data.slug!
@ -152,7 +157,9 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
emitted.push( emitted.push(
await write({ await write({
ctx, 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, slug: "sitemap" as FullSlug,
ext: ".xml", ext: ".xml",
}), }),
@ -160,10 +167,11 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
} }
if (opts?.enableRSS) { if (opts?.enableRSS) {
opts?.feedDirectories?.map(async (feed) => { directories.map(async (feed) => {
const emittedFeed = await write({ const emittedFeed = await write({
ctx, 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, slug: feed as FullSlug,
ext: ".xml", ext: ".xml",
}) })