Files
gw-svelte/src/lib/seo.ts
T

101 lines
3.0 KiB
TypeScript
Raw Normal View History

import { locationPages } from '$lib/content/locations';
import type { LocationPageContent } from '$lib/types';
const siteUrl = 'https://www.goodwalk.co.nz';
2026-05-18 09:43:29 +12:00
const defaultLocationImage = '/images/goodwalk-tiny-gang-pack-walk-small-dogs-auckland.webp';
const defaultLocationImageAlt = 'Goodwalk Auckland dog walking services';
interface BreadcrumbItem {
name: string;
path?: string;
url?: string;
}
export function absoluteUrl(value: string) {
if (!value) {
return siteUrl;
}
if (value.startsWith('http://') || value.startsWith('https://')) {
return value;
}
return `${siteUrl}${value.startsWith('/') ? value : `/${value}`}`;
}
export function buildBreadcrumb(items: BreadcrumbItem[]) {
return {
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
itemListElement: items.map((item, index) => ({
'@type': 'ListItem',
position: index + 1,
name: item.name,
item: item.url ?? absoluteUrl(item.path ?? '/')
}))
};
}
export function buildAreaServed(locations = locationPages) {
return locations.map((location) => ({
'@type': 'Place',
name: `${location.suburb}, Auckland, New Zealand`
}));
}
function getLocationSeoImage(location: LocationPageContent) {
return location.seo?.image ?? location.parks.find((park) => park.image?.src)?.image?.src ?? defaultLocationImage;
}
function getLocationSeoImageAlt(location: LocationPageContent) {
return (
location.seo?.imageAlt ??
location.parks.find((park) => park.image?.alt)?.image?.alt ??
`Goodwalk dog walkers in ${location.suburb}, Auckland`
);
}
export function buildLocationSeo(location: LocationPageContent) {
const canonicalPath = `/locations/${location.slug}`;
const title =
location.seo?.title ?? `Dog Walkers in ${location.suburb} | Goodwalk Auckland`;
const description =
location.seo?.description ??
`Goodwalk provides pack walks, 1:1 walks, and puppy visits in ${location.suburb}, Auckland Central. Small dog specialists with free pickup and drop-off. Book a free Meet & Greet.`;
const image = getLocationSeoImage(location);
const imageAlt = getLocationSeoImageAlt(location);
const breadcrumbLabel = location.seo?.breadcrumbLabel ?? location.suburb;
const serviceName = location.seo?.serviceName ?? `Goodwalk Dog Walking - ${location.suburb}`;
const serviceType = location.seo?.serviceType ?? 'Dog walking and puppy visits';
return {
title,
description,
canonicalPath,
image,
imageAlt,
structuredData: [
{
'@context': 'https://schema.org',
'@type': 'Service',
name: serviceName,
description,
serviceType,
provider: {
2026-05-12 00:45:02 +12:00
'@id': `${siteUrl}/#business`
},
areaServed: {
'@type': 'Place',
name: `${location.suburb}, Auckland, New Zealand`
},
image: absoluteUrl(image),
url: absoluteUrl(canonicalPath)
},
buildBreadcrumb([
{ name: 'Home', url: siteUrl },
{ name: breadcrumbLabel, path: canonicalPath }
])
] as Record<string, unknown>[]
};
}