2 changed files with 21 additions and 0 deletions
@ -0,0 +1,14 @@ |
|||||
|
import { describe, expect, test } from "bun:test"; |
||||
|
import { buildPublicProfileAbsoluteUrl } from "./public-profile-url"; |
||||
|
|
||||
|
describe("buildPublicProfileAbsoluteUrl", () => { |
||||
|
test("joins origin with /@slug path", () => { |
||||
|
expect(buildPublicProfileAbsoluteUrl("https://example.com", "my-slug")).toBe( |
||||
|
"https://example.com/@my-slug", |
||||
|
); |
||||
|
}); |
||||
|
|
||||
|
test("normalizes origin without trailing slash", () => { |
||||
|
expect(buildPublicProfileAbsoluteUrl("https://example.com/", "ab")).toBe("https://example.com/@ab"); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,7 @@ |
|||||
|
/** |
||||
|
* 与站内路由 `/@${publicSlug}` 对应的绝对 URL(用于复制到剪贴板)。 |
||||
|
*/ |
||||
|
export function buildPublicProfileAbsoluteUrl(origin: string, publicSlug: string): string { |
||||
|
const base = origin.replace(/\/+$/, ""); |
||||
|
return new URL(`/@${publicSlug}`, `${base}/`).href; |
||||
|
} |
||||
Loading…
Reference in new issue