mirror of
https://gitlab.com/MisterBiggs/brain-quartz.git
synced 2026-06-03 21:10:34 +00:00
ee80f65736
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>
72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import { FullSlug, resolveRelative, slugifyFilePath, simplifySlug } from "../util/path"
|
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
|
import { classNames } from "../util/lang"
|
|
|
|
const CategoryList: QuartzComponent = ({ fileData, displayClass }: QuartzComponentProps) => {
|
|
const categories = fileData.frontmatter?.categories
|
|
const outgoingLinks = fileData.outgoingLinks || []
|
|
|
|
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 (
|
|
<ul class={classNames(displayClass, "categories")}>
|
|
{categoriesToShow.map((category) => {
|
|
// Link directly to the note, not to a category aggregation page
|
|
const slug = slugifyFilePath((category + ".md") as any)
|
|
const linkDest = resolveRelative(fileData.slug!, slug)
|
|
return (
|
|
<li>
|
|
<a href={linkDest} class="internal category-link">
|
|
{category}
|
|
</a>
|
|
</li>
|
|
)
|
|
})}
|
|
</ul>
|
|
)
|
|
} else {
|
|
return null
|
|
}
|
|
}
|
|
|
|
CategoryList.css = `
|
|
.categories {
|
|
list-style: none;
|
|
display: flex;
|
|
padding-left: 0;
|
|
gap: 0.4rem;
|
|
margin: 1rem 0;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.section-li > .section > .categories {
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.categories > li {
|
|
display: inline-block;
|
|
white-space: nowrap;
|
|
margin: 0;
|
|
overflow-wrap: normal;
|
|
}
|
|
|
|
a.internal.category-link {
|
|
border-radius: 8px;
|
|
background-color: var(--highlight);
|
|
padding: 0.2rem 0.4rem;
|
|
margin: 0 0.1rem;
|
|
}
|
|
`
|
|
|
|
export default (() => CategoryList) satisfies QuartzComponentConstructor
|