Skip to content

Commit

Permalink
fix(path): correct handle URI schemes in joinSegments
Browse files Browse the repository at this point in the history
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 <head><meta>.

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.
  • Loading branch information
Xiami2012 committed Dec 30, 2024
1 parent 7d4bed6 commit 328a1cf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion quartz/util/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand Down

0 comments on commit 328a1cf

Please sign in to comment.