1
0
mirror of https://gitlab.com/MisterBiggs/brain-quartz.git synced 2026-06-03 21:10:34 +00:00

feat: hide category pills when category is already wiki-linked in content

Reduce visual clutter by only showing category pills for categories that
aren't already mentioned as wiki links in the note's content.

Implementation:
- Store outgoing links separately in links.ts before adding categories
- Added outgoingLinks to vfile DataMap type
- Modified CategoryList to filter out categories already in outgoingLinks
- Only category pills for unlinked categories are now displayed

Example:
If a note has categories: [[LLM]], [[Anthropic]], [[AI]] and the content
mentions [[LLM]] and [[Anthropic]], only the AI category pill will appear.

This follows Wikipedia's principle of avoiding redundant links and reduces
visual clutter while maintaining backlinks and graph connections.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-10 11:02:27 -05:00
parent a1a9b5233d
commit ee80f65736
2 changed files with 20 additions and 2 deletions
+15 -2
View File
@@ -1,13 +1,26 @@
import { FullSlug, resolveRelative, slugifyFilePath } from "../util/path" import { FullSlug, resolveRelative, slugifyFilePath, simplifySlug } from "../util/path"
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
import { classNames } from "../util/lang" import { classNames } from "../util/lang"
const CategoryList: QuartzComponent = ({ fileData, displayClass }: QuartzComponentProps) => { const CategoryList: QuartzComponent = ({ fileData, displayClass }: QuartzComponentProps) => {
const categories = fileData.frontmatter?.categories const categories = fileData.frontmatter?.categories
const outgoingLinks = fileData.outgoingLinks || []
if (categories && categories.length > 0) { if (categories && categories.length > 0) {
// Only show categories that aren't already wiki-linked in the content
const categoriesToShow = categories.filter((category) => {
const slug = slugifyFilePath((category + ".md") as any)
const simpleSlug = simplifySlug(slug)
return !outgoingLinks.includes(simpleSlug)
})
if (categoriesToShow.length === 0) {
return null
}
return ( return (
<ul class={classNames(displayClass, "categories")}> <ul class={classNames(displayClass, "categories")}>
{categories.map((category) => { {categoriesToShow.map((category) => {
// Link directly to the note, not to a category aggregation page // Link directly to the note, not to a category aggregation page
const slug = slugifyFilePath((category + ".md") as any) const slug = slugifyFilePath((category + ".md") as any)
const linkDest = resolveRelative(fileData.slug!, slug) const linkDest = resolveRelative(fileData.slug!, slug)
+5
View File
@@ -159,6 +159,10 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options>> = (userOpts)
} }
}) })
// Store outgoing links separately (before adding categories)
// This allows CategoryList to hide categories already linked in content
file.data.outgoingLinks = Array.from(outgoing)
// Include categories as links for backlinks and graph // Include categories as links for backlinks and graph
const categories = file.data.frontmatter?.categories ?? [] const categories = file.data.frontmatter?.categories ?? []
file.data.links = [...outgoing, ...categories] file.data.links = [...outgoing, ...categories]
@@ -172,5 +176,6 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options>> = (userOpts)
declare module "vfile" { declare module "vfile" {
interface DataMap { interface DataMap {
links: SimpleSlug[] links: SimpleSlug[]
outgoingLinks: SimpleSlug[]
} }
} }