feat(contentIndex): add flexible tag-based RSS feed generation

Enable generating RSS feeds for specific tags via `rssTags` option
This commit is contained in:
Suryaansh Rai 2026-01-17 22:24:20 +05:30
parent 47433a9068
commit 7bfbb6016a

View File

@ -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,7 +142,12 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
ext: ".xml",
})
if (opts?.includeTags && (opts.rssTagsLimit ?? 0) > 0) {
if (opts?.includeTags) {
let sortedTags: string[] = []
if (opts.rssTags && opts.rssTags.length > 0) {
sortedTags = opts.rssTags
} else if ((opts.rssTagsLimit ?? 0) > 0) {
const tagCounts: Map<string, number> = new Map()
// Count tags from all non-empty files (unless includeEmptyFiles is true)
@ -151,10 +158,11 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
}
}
const sortedTags = Array.from(tagCounts.entries())
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(