fix: deduplication and slugiication of tags

based on copilot's review
This commit is contained in:
Suryaansh Rai 2026-01-17 22:47:01 +05:30
parent b91651f9a7
commit 84ff4012d1

View File

@ -9,6 +9,7 @@ import {
getAllSegmentPrefixes, getAllSegmentPrefixes,
joinSegments, joinSegments,
simplifySlug, simplifySlug,
slugTag,
} from "../../util/path" } from "../../util/path"
import { QuartzEmitterPlugin } from "../types" import { QuartzEmitterPlugin } from "../types"
import { toHtml } from "hast-util-to-html" import { toHtml } from "hast-util-to-html"
@ -153,6 +154,9 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
let sortedTags: string[] = [] let sortedTags: string[] = []
if (opts.rssTags && opts.rssTags.length > 0) { if (opts.rssTags && opts.rssTags.length > 0) {
// Deduplicate and slugify user-provided tags
const userTags = new Set(opts.rssTags.map((tag) => slugTag(tag)))
// Only include user-specified tags that actually exist in the content // Only include user-specified tags that actually exist in the content
const availableTags = new Set<string>() const availableTags = new Set<string>()
for (const [_, content] of linkIndex) { for (const [_, content] of linkIndex) {
@ -161,7 +165,7 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
availableTags.add(tag) availableTags.add(tag)
} }
} }
sortedTags = opts.rssTags.filter((tag) => availableTags.has(tag)) sortedTags = Array.from(userTags).filter((tag) => availableTags.has(tag))
} else if ((opts.rssTagsLimit ?? 0) > 0) { } else if ((opts.rssTagsLimit ?? 0) > 0) {
const tagCounts: Map<string, number> = new Map() const tagCounts: Map<string, number> = new Map()