From 08cf4d5edb4fe3e49a1ac3ee0b873f8055eb1079 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Fri, 12 Jun 2026 09:31:27 -0700 Subject: [PATCH] fix social previews --- src/app.html | 19 ----- src/routes/+layout.svelte | 78 +++++++++++++++++++ src/routes/jobs/+page.svelte | 8 -- src/routes/shop/[product]/+page.svelte | 4 - .../shop/comma-four-trade-in/+page.svelte | 5 -- 5 files changed, 78 insertions(+), 36 deletions(-) diff --git a/src/app.html b/src/app.html index 7902ce85..4eddb18f 100644 --- a/src/app.html +++ b/src/app.html @@ -48,8 +48,6 @@ --> - comma.ai — make driving chill - - - - - - - - - - - - - - - - - - %sveltekit.head% diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 3ea9258e..06e154cb 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -35,7 +35,70 @@ import { onMount } from "svelte"; import { page } from "$app/stores"; + const SITE_URL = "https://comma.ai"; + const DEFAULT_META = { + title: "comma.ai — make driving chill", + description: "An AI upgrade for your car", + image: `${SITE_URL}/og-comma-four.png`, + imageAlt: "comma four", + }; + const ROUTE_META = { + "/jobs": { + title: "Jobs - comma", + description: "At comma.ai, we are solving self-driving cars while delivering shippable intermediaries.", + }, + "/shop/comma-four-trade-in": { + title: "comma four trade-in — comma shop", + description: "Trade in any older comma device for $250 credit towards a brand new comma four.", + }, + }; + let loading = false; + let pageMeta = DEFAULT_META; + let canonicalUrl = `${SITE_URL}/`; + + function normalizePathname(pathname) { + return pathname === "/" ? pathname : pathname.replace(/\/$/, ""); + } + + function textFromHtml(html) { + return html + .replace(/<[^>]*>/g, " ") + .replace(/ /g, " ") + .replace(/&/g, "&") + .replace(/\s+([,.;:!?])/g, "$1") + .replace(/\s+/g, " ") + .trim(); + } + + function truncateDescription(description) { + if (description.length <= 200) return description; + return `${description.slice(0, 197).trim()}...`; + } + + function getProductDescription(product) { + if (!product?.description) return DEFAULT_META.description; + return truncateDescription(textFromHtml(product.description).replace(/^Description\s+/i, "")); + } + + function getPageMeta(pageValue) { + if (pageValue.data?.product) { + return { + ...DEFAULT_META, + title: `${pageValue.data.product.title} — comma shop`, + description: getProductDescription(pageValue.data.product), + }; + } + + const pathname = normalizePathname(pageValue.url.pathname); + return { + ...DEFAULT_META, + ...(ROUTE_META[pathname] || {}), + }; + } + + $: pageMeta = getPageMeta($page); + $: canonicalUrl = `${SITE_URL}${normalizePathname($page.url.pathname) || "/"}`; async function openCart() { await loadCart(); @@ -84,6 +147,21 @@ + {pageMeta.title} + + + + + + + + + + + + + + - - Jobs - comma - - -
diff --git a/src/routes/shop/[product]/+page.svelte b/src/routes/shop/[product]/+page.svelte index d27ee91e..0a4198e4 100644 --- a/src/routes/shop/[product]/+page.svelte +++ b/src/routes/shop/[product]/+page.svelte @@ -6,10 +6,6 @@ $: ({ product, descriptionComponent } = data); - - {product.title} — comma shop - -
{#if descriptionComponent} diff --git a/src/routes/shop/comma-four-trade-in/+page.svelte b/src/routes/shop/comma-four-trade-in/+page.svelte index afb00675..b9bc660a 100644 --- a/src/routes/shop/comma-four-trade-in/+page.svelte +++ b/src/routes/shop/comma-four-trade-in/+page.svelte @@ -1,10 +1,6 @@ - - comma four trade-in — comma shop - -

comma four trade-in

@@ -97,4 +93,3 @@ border-top: 1px solid rgba(0, 0, 0, 0.15); } -