Skip to content
Open
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
19 changes: 0 additions & 19 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
<script src="//code.tidio.co/9o9hpvuj5fqc7gu1vhialdrpp7buweu2.js" async></script>
-->

<title>comma.ai — make driving chill</title>

<!-- Google SEO -->
<script type="application/ld+json">
{
Expand All @@ -65,23 +63,6 @@
}
</script>

<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:url" content="https://comma.ai/" />
<meta property="og:title" content="comma.ai — make driving chill" />
<meta property="og:description" content="An AI upgrade for your car" />
<meta property="og:image" content="https://comma.ai/og-comma-four.png" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="628" />

<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@comma_ai" />
<meta name="twitter:title" content="comma.ai — make driving chill" />
<meta name="twitter:description" content="An AI upgrade for your car" />
<meta name="twitter:image" content="https://comma.ai/og-comma-four.png" />
<meta name="twitter:image:alt" content="comma four" />

%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
Expand Down
78 changes: 78 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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(/&nbsp;/g, " ")
.replace(/&amp;/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();
Expand Down Expand Up @@ -84,6 +147,21 @@
</script>

<svelte:head>
<title>{pageMeta.title}</title>
<meta name="description" content={pageMeta.description} />
<meta property="og:type" content="website" />
<meta property="og:url" content={canonicalUrl} />
<meta property="og:title" content={pageMeta.title} />
<meta property="og:description" content={pageMeta.description} />
<meta property="og:image" content={pageMeta.image} />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="628" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@comma_ai" />
<meta name="twitter:title" content={pageMeta.title} />
<meta name="twitter:description" content={pageMeta.description} />
<meta name="twitter:image" content={pageMeta.image} />
<meta name="twitter:image:alt" content={pageMeta.imageAlt} />
<link
rel="preload"
href={MonumentExtendedBlack}
Expand Down
8 changes: 0 additions & 8 deletions src/routes/jobs/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,6 @@
}
</script>

<svelte:head>
<title>Jobs - comma</title>
<meta
name="description"
content="At comma.ai, we are solving self-driving cars while delivering shippable intermediaries."
/>
</svelte:head>

<div class="jobs-page light">
<section class="jobs-hero" aria-labelledby="jobs-title">
<div class="container">
Expand Down
4 changes: 0 additions & 4 deletions src/routes/shop/[product]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
$: ({ product, descriptionComponent } = data);
</script>

<svelte:head>
<title>{product.title} — comma shop</title>
</svelte:head>

<section class="light" id="product-item">
<div class="container">
{#if descriptionComponent}
Expand Down
5 changes: 0 additions & 5 deletions src/routes/shop/comma-four-trade-in/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<script>
</script>

<svelte:head>
<title>comma four trade-in — comma shop</title>
</svelte:head>

<section class="light" id="trade-in">
<div class="container">
<h1>comma four trade-in</h1>
Expand Down Expand Up @@ -97,4 +93,3 @@
border-top: 1px solid rgba(0, 0, 0, 0.15);
}
</style>

Loading