Jacky Zhao
2024-02-05 06ee73e006fedef64d326aae8909bcc4ca5b243a
quartz/util/path.ts
@@ -2,7 +2,7 @@
import type { Element as HastElement } from "hast"
import rfdc from "rfdc"
const clone = rfdc()
export const clone = rfdc()
// this file must be isomorphic so it can't use node libs (e.g. path)
@@ -50,7 +50,14 @@
function sluggify(s: string): string {
  return s
    .split("/")
    .map((segment) => segment.replace(/\s/g, "-").replace(/%/g, "-percent").replace(/\?/g, "-q")) // slugify all segments
    .map((segment) =>
      segment
        .replace(/\s/g, "-")
        .replace(/&/g, "-and-")
        .replace(/%/g, "-percent")
        .replace(/\?/g, "")
        .replace(/#/g, ""),
    )
    .join("/") // always use / as sep
    .replace(/\/$/, "")
}