Skip to content

Commit

Permalink
fix(aliases): Make sure the graph shows aliased pages
Browse files Browse the repository at this point in the history
Given pages A and B, where B has an alias Z, if page A had a link [[Z]]
you'd expect the graph to show an edge from A to B and B to have A as a
backlink.

That didn't happen, here's a fix
  • Loading branch information
necauqua committed Jan 2, 2025
1 parent 2e6a675 commit c5a3110
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions quartz/components/scripts/graph.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
const tags: SimpleSlug[] = []
const validLinks = new Set(data.keys())

const aliases = new Map<SimpleSlug, SimpleSlug>()
for (const [slug, details] of data.entries()) {
for (const alias of details.aliases) {
aliases.set(simplifySlug(alias), slug)
}
}

const tweens = new Map<string, TweenNode>()
for (const [source, details] of data.entries()) {
const outgoing = details.links ?? []
Expand All @@ -107,6 +114,10 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
if (validLinks.has(dest)) {
links.push({ source: source, target: dest })
}
const aliased = aliases.get(dest)
if (aliased) {
links.push({ source: source, target: aliased })
}
}

if (showTags) {
Expand Down
2 changes: 2 additions & 0 deletions quartz/plugins/emitters/contentIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type ContentDetails = {
title: string
links: SimpleSlug[]
tags: string[]
aliases: FullSlug[]
content: string
richContent?: string
date?: Date
Expand Down Expand Up @@ -125,6 +126,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 129 in quartz/plugins/emitters/contentIndex.ts

View workflow job for this annotation

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

Type '{}' is missing the following properties from type 'FullSlug[]': length, pop, push, concat, and 35 more.
content: file.data.text ?? "",
richContent: opts?.rssFullHtml
? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true }))
Expand Down

0 comments on commit c5a3110

Please sign in to comment.