mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 23:04:05 -06:00
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 <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.
This commit is contained in:
parent
7d4bed64a9
commit
328a1cfb57
@ -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[] {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user