import type { SiteConfig } from './types.ts' /** * Public base URL for links that leave the site (canonical, Open Graph, * sitemap, preview links): the configured `siteUrl` when set, else the * Kody-hosted mount URL. Never ends with a slash. */ export function publicBaseUrl( config: Pick, hostedUrl: string | undefined, ) { const base = config.siteUrl ?? hostedUrl return base ? base.replace(/\/+$/, '') : null } /** Join a site path ("/galleries/x") onto a base URL. */ export function joinUrl(base: string, path: string) { const relative = path.replace(/^\/+/, '') return relative ? `${base}/${relative}` : base } export function previewLink(base: string, token: string) { return `${joinUrl(base, '/preview')}?token=${encodeURIComponent(token)}` }