Skip to content

Commit

Permalink
fix: percent-encoding for files with %, contentIndex for non-latin ch…
Browse files Browse the repository at this point in the history
…ars (closes jackyzha0#397, closes jackyzha0#399)
  • Loading branch information
jackyzha0 committed Aug 23, 2023
1 parent 36548d5 commit b444c5c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion quartz/plugins/emitters/contentIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface Options {
const defaultOptions: Options = {
enableSiteMap: true,
enableRSS: true,
includeEmptyFiles: false,
includeEmptyFiles: true,
}

function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndex): string {
Expand Down
10 changes: 8 additions & 2 deletions quartz/plugins/transformers/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,17 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options> | 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)
}

Expand Down
2 changes: 1 addition & 1 deletion quartz/util/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b444c5c

Please sign in to comment.