mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-02-03 22:15:42 -06:00
feat(contentIndex): add flexible tag-based RSS feed generation
Enable generating RSS feeds for specific tags via `rssTags` option
This commit is contained in:
parent
47433a9068
commit
7bfbb6016a
@ -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(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user