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
|
includeEmptyFiles: boolean
|
||||||
includeTags: boolean
|
includeTags: boolean
|
||||||
rssTagsLimit: number
|
rssTagsLimit: number
|
||||||
|
rssTags: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultOptions: Options = {
|
const defaultOptions: Options = {
|
||||||
@ -41,6 +42,7 @@ const defaultOptions: Options = {
|
|||||||
includeEmptyFiles: true,
|
includeEmptyFiles: true,
|
||||||
includeTags: false,
|
includeTags: false,
|
||||||
rssTagsLimit: 15,
|
rssTagsLimit: 15,
|
||||||
|
rssTags: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndexMap): string {
|
function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndexMap): string {
|
||||||
@ -140,21 +142,27 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
|||||||
ext: ".xml",
|
ext: ".xml",
|
||||||
})
|
})
|
||||||
|
|
||||||
if (opts?.includeTags && (opts.rssTagsLimit ?? 0) > 0) {
|
if (opts?.includeTags) {
|
||||||
const tagCounts: Map<string, number> = new Map()
|
let sortedTags: string[] = []
|
||||||
|
|
||||||
// Count tags from all non-empty files (unless includeEmptyFiles is true)
|
if (opts.rssTags && opts.rssTags.length > 0) {
|
||||||
for (const [_, content] of linkIndex) {
|
sortedTags = opts.rssTags
|
||||||
const tags = content.tags.flatMap(getAllSegmentPrefixes)
|
} else if ((opts.rssTagsLimit ?? 0) > 0) {
|
||||||
for (const tag of new Set(tags)) { // Use Set to avoid double counting per file
|
const tagCounts: Map<string, number> = new Map()
|
||||||
tagCounts.set(tag, (tagCounts.get(tag) ?? 0) + 1)
|
|
||||||
|
// 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())
|
sortedTags = Array.from(tagCounts.entries())
|
||||||
.sort((a, b) => b[1] - a[1]) // Sort by frequency descending
|
.sort((a, b) => b[1] - a[1]) // Sort by frequency descending
|
||||||
.slice(0, opts.rssTagsLimit)
|
.slice(0, opts.rssTagsLimit)
|
||||||
.map(([tag]) => tag)
|
.map(([tag]) => tag)
|
||||||
|
}
|
||||||
|
|
||||||
for (const tag of sortedTags) {
|
for (const tag of sortedTags) {
|
||||||
const tagFilteredIndex = new Map(
|
const tagFilteredIndex = new Map(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user