Site URL
atroui/site-urlFreeUtility
getSiteUrl() for metadata and JSON-LD.
Install it
npx shadcn@latest add https://atroui.com/r/site-url.jsonSource
1/**2 * Canonical public site URL for metadata, sitemap, and JSON-LD.3 */45import { getBrand } from "@/lib/brand";67export function getSiteUrl(): string {8 const brand = getBrand();910 // Prefer explicit public URL, then brand default. Only use Vercel deployment11 // host on preview builds so production JSON-LD / OG never point at *.vercel.app.12 const raw =13 process.env.NEXT_PUBLIC_SITE_URL ||14 (process.env.VERCEL_ENV === "preview" && process.env.VERCEL_URL15 ? `https://${process.env.VERCEL_URL}`16 : brand.siteUrl);1718 // Prefer www for apex hosts when crawlers are picky about og:image redirects.19 try {20 const url = new URL(raw);21 const apex = brand.domain.replace(/^www\./, "");22 if (url.hostname === apex) {23 url.hostname = `www.${apex}`;24 return url.toString().replace(/\/$/, "");25 }26 } catch {27 // fall through28 }29 return raw.replace(/\/$/, "");30}
What it pulls in
Other registry items
Files it writes
More from atroui
All 82 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Analyticsanalytics | atroui | Utilities | Free | no deps | |
| Brandbrand | atroui | Utilities | Free | no deps | |
| Project Briefproject-brief | atroui | Utilities | Free | no deps | |
| SEO helpersseo | atroui | Utilities | Free | no deps | |
| Utilsutils | atroui | Utilities | Free | 2 deps |
