Harden calculator SEO signals
This commit is contained in:
@@ -84,6 +84,7 @@ export const calculatorSeo = (calc: CalculatorDef) => {
|
|||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
canonicalUrl: canonical,
|
canonicalUrl: canonical,
|
||||||
|
canonicalSlug,
|
||||||
noindex,
|
noindex,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error, redirect } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import { getCalculatorBySlug, getCalculatorsByCategory, categories, getEffectiveCategory } from '$lib/data/calculators';
|
import { getCalculatorBySlug, getCalculatorsByCategory, categories, getEffectiveCategory } from '$lib/data/calculators';
|
||||||
import { calculatorJsonLd, calculatorSeo } from '$lib/seo';
|
import { calculatorJsonLd, calculatorSeo, toJsonLd } from '$lib/seo';
|
||||||
|
|
||||||
export const load: PageServerLoad = ({ params, setHeaders }) => {
|
export const load: PageServerLoad = ({ params, setHeaders }) => {
|
||||||
const calc = getCalculatorBySlug(params.slug);
|
const calc = getCalculatorBySlug(params.slug);
|
||||||
@@ -13,13 +13,17 @@ export const load: PageServerLoad = ({ params, setHeaders }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const effectiveCategory = getEffectiveCategory(calc);
|
const effectiveCategory = getEffectiveCategory(calc);
|
||||||
|
const seo = calculatorSeo(calc);
|
||||||
|
|
||||||
|
if (seo.canonicalSlug !== calc.slug) {
|
||||||
|
throw redirect(301, `/${seo.canonicalSlug}`);
|
||||||
|
}
|
||||||
|
|
||||||
const related = getCalculatorsByCategory(effectiveCategory)
|
const related = getCalculatorsByCategory(effectiveCategory)
|
||||||
.filter(c => c.slug !== calc.slug)
|
.filter(c => c.slug !== calc.slug)
|
||||||
.slice(0, 8);
|
.slice(0, 8);
|
||||||
|
|
||||||
const categoryMeta = categories[effectiveCategory];
|
const categoryMeta = categories[effectiveCategory];
|
||||||
const seo = calculatorSeo(calc);
|
|
||||||
if (seo.noindex) {
|
if (seo.noindex) {
|
||||||
setHeaders({
|
setHeaders({
|
||||||
'X-Robots-Tag': 'noindex, follow'
|
'X-Robots-Tag': 'noindex, follow'
|
||||||
@@ -30,7 +34,7 @@ export const load: PageServerLoad = ({ params, setHeaders }) => {
|
|||||||
calculator: calc,
|
calculator: calc,
|
||||||
related,
|
related,
|
||||||
seo,
|
seo,
|
||||||
jsonLd: JSON.stringify(calculatorJsonLd(calc, seo.canonicalUrl)),
|
jsonLd: toJsonLd(calculatorJsonLd(calc, seo.canonicalUrl)),
|
||||||
category: effectiveCategory,
|
category: effectiveCategory,
|
||||||
categoryLabel: categoryMeta?.label ?? calc.category,
|
categoryLabel: categoryMeta?.label ?? calc.category,
|
||||||
categoryIcon: categoryMeta?.icon ?? '🔢'
|
categoryIcon: categoryMeta?.icon ?? '🔢'
|
||||||
|
|||||||
@@ -68,6 +68,7 @@
|
|||||||
<meta name="twitter:card" content={seo.twitter.card} />
|
<meta name="twitter:card" content={seo.twitter.card} />
|
||||||
<meta name="twitter:title" content={seo.twitter.title} />
|
<meta name="twitter:title" content={seo.twitter.title} />
|
||||||
<meta name="twitter:description" content={seo.twitter.description} />
|
<meta name="twitter:description" content={seo.twitter.description} />
|
||||||
|
{@html `<script type="application/ld+json">${data.jsonLd}</script>`}
|
||||||
{@html `<script type="application/ld+json">${breadcrumbJsonLd}</script>`}
|
{@html `<script type="application/ld+json">${breadcrumbJsonLd}</script>`}
|
||||||
{@html `<script type="application/ld+json">${webPageJsonLd}</script>`}
|
{@html `<script type="application/ld+json">${webPageJsonLd}</script>`}
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|||||||
Reference in New Issue
Block a user