From b444c5c13b983bf80df8b6d020eb246e9fd3e78e Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Tue, 22 Aug 2023 23:33:58 -0700 Subject: [PATCH] fix: percent-encoding for files with %, contentIndex for non-latin chars (closes #397, closes #399) --- quartz/plugins/emitters/contentIndex.ts | 2 +- quartz/plugins/transformers/links.ts | 10 ++++++++-- quartz/util/path.ts | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/quartz/plugins/emitters/contentIndex.ts b/quartz/plugins/emitters/contentIndex.ts index f4bf6db02..a18e54e3e 100644 --- a/quartz/plugins/emitters/contentIndex.ts +++ b/quartz/plugins/emitters/contentIndex.ts @@ -22,7 +22,7 @@ interface Options { const defaultOptions: Options = { enableSiteMap: true, enableRSS: true, - includeEmptyFiles: false, + includeEmptyFiles: true, } function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndex): string { diff --git a/quartz/plugins/transformers/links.ts b/quartz/plugins/transformers/links.ts index 7d992722b..f8da36c4d 100644 --- a/quartz/plugins/transformers/links.ts +++ b/quartz/plugins/transformers/links.ts @@ -60,11 +60,17 @@ export const CrawlLinks: QuartzTransformerPlugin | undefined> = dest, transformOptions, ) - const url = new URL(dest, `https://base.com/${curSlug}`) + + // url.resolve is considered legacy + // WHATWG equivalent https://nodejs.dev/en/api/v18/url/#urlresolvefrom-to + const url = new URL(dest, `resolve://${curSlug}`) const canonicalDest = url.pathname const [destCanonical, _destAnchor] = splitAnchor(canonicalDest) - const simple = decodeURI(simplifySlug(destCanonical as FullSlug)) as SimpleSlug + // need to decodeURIComponent here as WHATWG URL percent-encodes everything + const simple = decodeURIComponent( + simplifySlug(destCanonical as FullSlug), + ) as SimpleSlug outgoing.add(simple) } diff --git a/quartz/util/path.ts b/quartz/util/path.ts index d14b827df..1557c1bd5 100644 --- a/quartz/util/path.ts +++ b/quartz/util/path.ts @@ -52,7 +52,7 @@ export function slugifyFilePath(fp: FilePath, excludeExt?: boolean): FullSlug { let slug = withoutFileExt .split("/") - .map((segment) => segment.replace(/\s/g, "-")) // slugify all segments + .map((segment) => segment.replace(/\s/g, "-").replace(/%/g, "-percent")) // slugify all segments .join("/") // always use / as sep .replace(/\/$/, "") // remove trailing slash