🪛 Clean up and fix og-image code (#820)

This commit is contained in:
Luke Vella 2023-08-18 12:32:12 +01:00 committed by GitHub
parent e7a69ffe1d
commit 6ff907004c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 25 deletions

View file

@ -15,13 +15,18 @@ function joinPath(baseUrl: string, subpath = "") {
return baseUrl;
}
export function absoluteUrl(subpath = "") {
export function absoluteUrl(subpath = "", query?: Record<string, string>) {
const queryString = query
? `?${Object.entries(query)
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
.join("&")}`
: "";
const baseUrl =
process.env.NEXT_PUBLIC_BASE_URL ??
getVercelUrl() ??
`http://localhost:${port}`;
return joinPath(baseUrl, subpath);
return joinPath(baseUrl, subpath) + queryString;
}
export function shortUrl(subpath = "") {