From 328a1cfb57e6b748e4768c4793d3769fde37f075 Mon Sep 17 00:00:00 2001 From: moexiami Date: Mon, 30 Dec 2024 19:37:35 +0800 Subject: [PATCH] fix(path): correct handle URI schemes in joinSegments In Head component, joinSegments is used to build a socialUrl with (`https://${baseUrl}`, slug), which causes a slash to be lost in the result. For example, joinSegments("https://quartz.jzhao.xyz", "layout") will return "https:/quartz.jzhao.xyz/layout". The result is then used in og:url and twitter:url in . This fix tries to preserve each segment, but removes all leading and trailing slashes. In addition, for the first segment, the leading slash is only de-duplicated, not fully trimmed. --- quartz/util/path.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/quartz/util/path.ts b/quartz/util/path.ts index c02bfb12d..8e1aeefa2 100644 --- a/quartz/util/path.ts +++ b/quartz/util/path.ts @@ -185,8 +185,13 @@ export function slugTag(tag: string) { export function joinSegments(...args: string[]): string { return args .filter((segment) => segment !== "") + .map((segment, index) => + index === 0 + ? // Deduplicate but not remove leading slashes for first segment + segment.replace(/\/+$/g, "").replace(/^\/\/+/g, "/") + : segment.replace(/^\/+|\/+$/g, ""), + ) .join("/") - .replace(/\/\/+/g, "/") } export function getAllSegmentPrefixes(tags: string): string[] {