Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tags): Allow separating page tags from frontmatter tags #1672

Open
wants to merge 1 commit into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. This marks the page as tagged with those tags, you can set `parseTags` to `"link-only"` to only turn content tags into links.
- `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
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, tagLinks }: Data) => [
...(frontmatter?.tags ?? []),
...(tagLinks ?? []),
]

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
9 changes: 7 additions & 2 deletions quartz/plugins/transformers/ofm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface Options {
wikilinks: boolean
callouts: boolean
mermaid: boolean
parseTags: boolean
parseTags: boolean | "link-only"
parseArrows: boolean
parseBlockReferences: boolean
enableInHtmlEmbed: boolean
Expand Down Expand Up @@ -338,9 +338,13 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
}

tag = slugTag(tag)
if (file.data.frontmatter) {
if (opts.parseTags != "link-only" && file.data.frontmatter) {
const noteTags = file.data.frontmatter.tags ?? []
file.data.frontmatter.tags = [...new Set([...noteTags, tag])]
} else {
// We store the content tags so that the tagPage can be generated even
// if there's no pages tagged with them through the frontmatter
file.data.tagLinks = (file.data.tagLinks ?? new Set()).add(tag)
}

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