Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions apps/www/app/(docs)/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ export async function generateMetadata({
return {}
}

const url = process.env.NEXT_PUBLIC_APP_URL

const ogUrl = new URL(`${url}/og`)
const ogUrl = new URL(absoluteUrl("/og"))
ogUrl.searchParams.set("title", doc.title ?? "")
ogUrl.searchParams.set("description", doc.description ?? "")

Expand Down
4 changes: 1 addition & 3 deletions apps/www/app/(marketing)/showcase/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export async function generateMetadata({
return {}
}

const url = process.env.NEXT_PUBLIC_APP_URL

const ogUrl = new URL(`${url}/og`)
const ogUrl = new URL(absoluteUrl("/og"))
ogUrl.searchParams.set("title", doc.title ?? "")
ogUrl.searchParams.set("description", doc.description ?? "")

Expand Down
26 changes: 24 additions & 2 deletions apps/www/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import process from "process"
import { Metadata } from "next"
import type { Metadata } from "next"
import clsx, { ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"

import { siteConfig } from "@/config/site"

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
Expand Down Expand Up @@ -65,8 +67,28 @@ export const normalizeTag = (tag: unknown): string[] => {
: [String(tag)]
}

const getBaseUrl = (): string => {
const configuredUrl = process.env.NEXT_PUBLIC_APP_URL?.trim()
if (!configuredUrl) {
return siteConfig.url
}

let url = configuredUrl.replace(/\/$/, "")
if (!/^https?:\/\//i.test(url)) {
url = `https://${url}`
}

try {
new URL(url)
return url
} catch {
return siteConfig.url
}
}

export function absoluteUrl(path: string) {
return `${process.env.NEXT_PUBLIC_APP_URL}${path}`
const normalizedPath = path.startsWith("/") ? path : `/${path}`
return new URL(normalizedPath, `${getBaseUrl()}/`).toString()
}

export function constructMetadata({
Expand Down
Loading