116 lines
3.5 KiB
TypeScript
116 lines
3.5 KiB
TypeScript
import { locationPages } from '$lib/content/locations';
|
|
import type { LocationPageContent } from '$lib/types';
|
|
|
|
const siteUrl = 'https://www.goodwalk.co.nz';
|
|
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`
|
|
}));
|
|
}
|
|
|
|
export const goodwalkProviderNode = {
|
|
'@type': ['LocalBusiness', 'PetCareService'],
|
|
'@id': `${siteUrl}/#business`,
|
|
name: 'Goodwalk',
|
|
url: siteUrl,
|
|
logo: `${siteUrl}/images/goodwalk-auckland-dog-walking-logo.webp`,
|
|
image: `${siteUrl}/images/goodwalk-auckland-dog-walking-logo.webp`,
|
|
email: 'info@goodwalk.co.nz',
|
|
telephone: '+64226421011',
|
|
address: {
|
|
'@type': 'PostalAddress',
|
|
addressLocality: 'Auckland Central',
|
|
addressRegion: 'Auckland',
|
|
addressCountry: 'NZ'
|
|
}
|
|
} as const;
|
|
|
|
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, solo 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: goodwalkProviderNode,
|
|
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>[]
|
|
};
|
|
}
|