Skip to content

Commit

Permalink
feat(tags): Allow separating page tags from frontmatter tags
Browse files Browse the repository at this point in the history
I feel like tags in note content are just links to the tag page, and
shouldn't mark the page with that tag.

Also the way it was done - adding content tags to frontmatter -
interferes with my WIP page properties component, I want to only show
"explicitly put in the frontmatter" tags.

Added an option to have those "outgoing" tags that don't tag the page,
yet get a tag page generated (so that the popover is not 404 if there
are no pages with this tag).
  • Loading branch information
necauqua committed Jan 2, 2025
1 parent 2e6a675 commit 27d93a4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/plugins/ObsidianFlavoredMarkdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This plugin accepts the following configuration options:
- `wikilinks`:If `true` (default), turns [[wikilinks]] into regular links.
- `callouts`: If `true` (default), adds support for [[callouts|callout]] blocks for emphasizing content.
- `mermaid`: If `true` (default), enables [[Mermaid diagrams|Mermaid diagram]] rendering within Markdown files.
- `parseTags`: If `true` (default), parses and links tags within the content.
- `parseTags`: If `true` (default), parses and links tags within the content. By default this adds content tags to the frontmatter and effectively marks the page as tagged with those tags. If this is undesirable, you can set `parseTags` to `"outgoing"` to make content tags into links without adding them to page frontmatter.
- `parseArrows`: If `true` (default), transforms arrow symbols into their HTML character equivalents.
- `parseBlockReferences`: If `true` (default), handles block references, linking to specific content blocks.
- `enableInHtmlEmbed`: If `true`, allows embedding of content directly within HTML. Defaults to `false`.
Expand Down
1 change: 1 addition & 0 deletions quartz/plugins/emitters/contentIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
title: file.data.frontmatter?.title!,
links: file.data.links ?? [],
tags: file.data.frontmatter?.tags ?? [],
aliases: file.data.aliases ?? [],

Check failure on line 128 in quartz/plugins/emitters/contentIndex.ts

View workflow job for this annotation

GitHub Actions / build-and-test (ubuntu-latest)

Object literal may only specify known properties, and 'aliases' does not exist in type 'ContentDetails'.
content: file.data.text ?? "",
richContent: opts?.rssFullHtml
? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true }))
Expand Down
12 changes: 8 additions & 4 deletions quartz/plugins/emitters/tagPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ import { TagContent } from "../../components"
import { write } from "./helpers"
import { i18n } from "../../i18n"
import DepGraph from "../../depgraph"
import { Data } from "vfile"

interface TagPageOptions extends FullPageLayout {
sort?: (f1: QuartzPluginData, f2: QuartzPluginData) => number
}

const getTags = ({ frontmatter, outgoingTags }: Data) => [
...(frontmatter?.tags ?? []),
...(outgoingTags ?? []),
]

export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (userOpts) => {
const opts: FullPageLayout = {
...sharedPageComponents,
Expand Down Expand Up @@ -55,7 +61,7 @@ export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (userOpts)

for (const [_tree, file] of content) {
const sourcePath = file.data.filePath!
const tags = (file.data.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes)
const tags = getTags(file.data).flatMap(getAllSegmentPrefixes)
// if the file has at least one tag, it is used in the tag index page
if (tags.length > 0) {
tags.push("index")
Expand All @@ -76,9 +82,7 @@ export const TagPage: QuartzEmitterPlugin<Partial<TagPageOptions>> = (userOpts)
const allFiles = content.map((c) => c[1].data)
const cfg = ctx.cfg.configuration

const tags: Set<string> = new Set(
allFiles.flatMap((data) => data.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes),
)
const tags: Set<string> = new Set(allFiles.flatMap(getTags).flatMap(getAllSegmentPrefixes))

// add base tag
tags.add("index")
Expand Down
7 changes: 5 additions & 2 deletions quartz/plugins/transformers/ofm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface Options {
wikilinks: boolean
callouts: boolean
mermaid: boolean
parseTags: boolean
parseTags: boolean | "outgoing"
parseArrows: boolean
parseBlockReferences: boolean
enableInHtmlEmbed: boolean
Expand Down Expand Up @@ -331,9 +331,11 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
}

tag = slugTag(tag)
if (file.data.frontmatter) {
if (opts.parseTags != "outgoing" && file.data.frontmatter) {
const noteTags = file.data.frontmatter.tags ?? []
file.data.frontmatter.tags = [...new Set([...noteTags, tag])]
} else {
file.data.outgoingTags = (file.data.outgoingTags ?? new Set()).add(tag)
}

return {
Expand Down Expand Up @@ -821,5 +823,6 @@ declare module "vfile" {
blocks: Record<string, Element>
htmlAst: HtmlRoot
hasMermaidDiagram: boolean | undefined
outgoingTags: Set<string>
}
}

0 comments on commit 27d93a4

Please sign in to comment.