From dd47be1bc65d3a8050d6ce9e77cd0e3b10e2a1a9 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sat, 19 Aug 2023 16:28:44 -0700 Subject: [PATCH] improve path resolution stability --- quartz/components/PageList.tsx | 2 +- quartz/components/pages/FolderContent.tsx | 4 ++-- quartz/components/renderPage.tsx | 4 ++-- quartz/components/scripts/graph.inline.ts | 2 +- quartz/plugins/transformers/links.ts | 3 ++- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/quartz/components/PageList.tsx b/quartz/components/PageList.tsx index 63513f5..d7aca08 100644 --- a/quartz/components/PageList.tsx +++ b/quartz/components/PageList.tsx @@ -56,7 +56,7 @@ export function PageList({ fileData, allFiles, limit }: Props) {
  • #{tag} diff --git a/quartz/components/pages/FolderContent.tsx b/quartz/components/pages/FolderContent.tsx index 478eaa7..7067e06 100644 --- a/quartz/components/pages/FolderContent.tsx +++ b/quartz/components/pages/FolderContent.tsx @@ -5,11 +5,11 @@ import path from "path" import style from "../styles/listPage.scss" import { PageList } from "../PageList" -import { simplifySlug } from "../../util/path" +import { _stripSlashes, simplifySlug } from "../../util/path" function FolderContent(props: QuartzComponentProps) { const { tree, fileData, allFiles } = props - const folderSlug = simplifySlug(fileData.slug!) + const folderSlug = _stripSlashes(simplifySlug(fileData.slug!)) const allPagesInFolder = allFiles.filter((file) => { const fileSlug = simplifySlug(file.slug!) const prefixed = fileSlug.startsWith(folderSlug) && fileSlug !== folderSlug diff --git a/quartz/components/renderPage.tsx b/quartz/components/renderPage.tsx index a1d5fee..eb1291f 100644 --- a/quartz/components/renderPage.tsx +++ b/quartz/components/renderPage.tsx @@ -25,7 +25,7 @@ export function pageResources(slug: FullSlug, staticResources: StaticResources): css: [joinSegments(baseDir, "index.css"), ...staticResources.css], js: [ { - src: joinSegments(baseDir, "/prescript.js"), + src: joinSegments(baseDir, "prescript.js"), loadTime: "beforeDOMReady", contentType: "external", }, @@ -37,7 +37,7 @@ export function pageResources(slug: FullSlug, staticResources: StaticResources): }, ...staticResources.js, { - src: baseDir + "/postscript.js", + src: joinSegments(baseDir, "postscript.js"), loadTime: "afterDOMReady", moduleType: "module", contentType: "external", diff --git a/quartz/components/scripts/graph.inline.ts b/quartz/components/scripts/graph.inline.ts index e84480e..e589217 100644 --- a/quartz/components/scripts/graph.inline.ts +++ b/quartz/components/scripts/graph.inline.ts @@ -177,7 +177,7 @@ async function renderGraph(container: string, fullSlug: FullSlug) { window.spaNavigate(new URL(targ, window.location.toString())) }) .on("mouseover", function (_, d) { - const neighbours: SimpleSlug[] = data[slug].links ?? [] + const neighbours: SimpleSlug[] = data[fullSlug].links ?? [] const neighbourNodes = d3 .selectAll(".node") .filter((d) => neighbours.includes(d.id)) diff --git a/quartz/plugins/transformers/links.ts b/quartz/plugins/transformers/links.ts index 5d34fa3..d9c9c7c 100644 --- a/quartz/plugins/transformers/links.ts +++ b/quartz/plugins/transformers/links.ts @@ -60,7 +60,8 @@ export const CrawlLinks: QuartzTransformerPlugin | undefined> = dest, transformOptions, ) - const canonicalDest = path.posix.normalize(joinSegments(curSlug, dest)) + const url = new URL(dest, `https://base.com/${curSlug}`) + const canonicalDest = url.pathname const [destCanonical, _destAnchor] = splitAnchor(canonicalDest) const simple = simplifySlug(destCanonical as FullSlug) outgoing.add(simple)