From 7bfbb6016aa23628e91d61ad30fc035c737531b7 Mon Sep 17 00:00:00 2001 From: Suryaansh Rai Date: Sat, 17 Jan 2026 22:24:20 +0530 Subject: [PATCH] feat(contentIndex): add flexible tag-based RSS feed generation Enable generating RSS feeds for specific tags via `rssTags` option --- quartz/plugins/emitters/contentIndex.tsx | 32 +++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/quartz/plugins/emitters/contentIndex.tsx b/quartz/plugins/emitters/contentIndex.tsx index e00a87f58..ef51a7fa4 100644 --- a/quartz/plugins/emitters/contentIndex.tsx +++ b/quartz/plugins/emitters/contentIndex.tsx @@ -30,6 +30,7 @@ interface Options { includeEmptyFiles: boolean includeTags: boolean rssTagsLimit: number + rssTags: string[] } const defaultOptions: Options = { @@ -41,6 +42,7 @@ const defaultOptions: Options = { includeEmptyFiles: true, includeTags: false, rssTagsLimit: 15, + rssTags: [], } function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndexMap): string { @@ -140,21 +142,27 @@ export const ContentIndex: QuartzEmitterPlugin> = (opts) => { ext: ".xml", }) - if (opts?.includeTags && (opts.rssTagsLimit ?? 0) > 0) { - const tagCounts: Map = new Map() + if (opts?.includeTags) { + let sortedTags: string[] = [] - // Count tags from all non-empty files (unless includeEmptyFiles is true) - for (const [_, content] of linkIndex) { - const tags = content.tags.flatMap(getAllSegmentPrefixes) - for (const tag of new Set(tags)) { // Use Set to avoid double counting per file - tagCounts.set(tag, (tagCounts.get(tag) ?? 0) + 1) + if (opts.rssTags && opts.rssTags.length > 0) { + sortedTags = opts.rssTags + } else if ((opts.rssTagsLimit ?? 0) > 0) { + const tagCounts: Map = new Map() + + // Count tags from all non-empty files (unless includeEmptyFiles is true) + for (const [_, content] of linkIndex) { + const tags = content.tags.flatMap(getAllSegmentPrefixes) + for (const tag of new Set(tags)) { // Use Set to avoid double counting per file + tagCounts.set(tag, (tagCounts.get(tag) ?? 0) + 1) + } } - } - const sortedTags = Array.from(tagCounts.entries()) - .sort((a, b) => b[1] - a[1]) // Sort by frequency descending - .slice(0, opts.rssTagsLimit) - .map(([tag]) => tag) + sortedTags = Array.from(tagCounts.entries()) + .sort((a, b) => b[1] - a[1]) // Sort by frequency descending + .slice(0, opts.rssTagsLimit) + .map(([tag]) => tag) + } for (const tag of sortedTags) { const tagFilteredIndex = new Map(