deploy: restore registry seo helpers
This commit is contained in:
parent
0be731e474
commit
d496a58935
1 changed files with 64 additions and 4 deletions
68
lib/seo.ts
68
lib/seo.ts
|
|
@ -1,6 +1,11 @@
|
||||||
import type { Metadata } from "next"
|
import type { Metadata } from "next"
|
||||||
import { businessConfig } from "@/lib/seo-config"
|
import { businessConfig } from "@/lib/seo-config"
|
||||||
import { buildAbsoluteUrl, ogImagePath } from "@/lib/seo-registry"
|
import {
|
||||||
|
buildAbsoluteUrl,
|
||||||
|
getSeoPageDefinition,
|
||||||
|
ogImagePath,
|
||||||
|
type StaticSeoPageKey,
|
||||||
|
} from "@/lib/seo-registry"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean HTML entities from text (e.g., & -> &, " -> ")
|
* Clean HTML entities from text (e.g., & -> &, " -> ")
|
||||||
|
|
@ -29,6 +34,21 @@ export interface SEOData {
|
||||||
keywords?: string[]
|
keywords?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createRobotsValue(noindex?: boolean): Metadata["robots"] | undefined {
|
||||||
|
if (!noindex) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
index: false,
|
||||||
|
follow: false,
|
||||||
|
googleBot: {
|
||||||
|
index: false,
|
||||||
|
follow: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate SEO metadata for a WordPress page/post
|
* Generate SEO metadata for a WordPress page/post
|
||||||
*/
|
*/
|
||||||
|
|
@ -46,7 +66,7 @@ export function generateSEOMetadata(data: SEOData): Metadata {
|
||||||
} = data
|
} = data
|
||||||
|
|
||||||
const cleanTitle = cleanHtmlEntities(title)
|
const cleanTitle = cleanHtmlEntities(title)
|
||||||
const fullTitle = cleanTitle.includes(`| ${businessConfig.name}`)
|
const fullTitle = cleanTitle.includes(businessConfig.name)
|
||||||
? cleanTitle
|
? cleanTitle
|
||||||
: `${cleanTitle} | ${businessConfig.name}`
|
: `${cleanTitle} | ${businessConfig.name}`
|
||||||
let seoDescription = cleanHtmlEntities(description || excerpt || "")
|
let seoDescription = cleanHtmlEntities(description || excerpt || "")
|
||||||
|
|
@ -56,8 +76,6 @@ export function generateSEOMetadata(data: SEOData): Metadata {
|
||||||
if (!seoDescription) {
|
if (!seoDescription) {
|
||||||
seoDescription =
|
seoDescription =
|
||||||
"Rocky Mountain Vending provides vending machine placement, service, repairs, and support across Utah."
|
"Rocky Mountain Vending provides vending machine placement, service, repairs, and support across Utah."
|
||||||
} else if (seoDescription.length > 165) {
|
|
||||||
seoDescription = `${seoDescription.slice(0, 162).trim()}...`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ogImage = image || ogImagePath
|
const ogImage = image || ogImagePath
|
||||||
|
|
@ -99,6 +117,48 @@ export function generateSEOMetadata(data: SEOData): Metadata {
|
||||||
return metadata
|
return metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function generateRegistryMetadata(
|
||||||
|
key: StaticSeoPageKey,
|
||||||
|
overrides?: Partial<SEOData>
|
||||||
|
): Metadata {
|
||||||
|
const page = getSeoPageDefinition(key)
|
||||||
|
|
||||||
|
return generateSEOMetadata({
|
||||||
|
title: overrides?.title ?? page.title,
|
||||||
|
description: overrides?.description ?? page.description,
|
||||||
|
excerpt: overrides?.excerpt,
|
||||||
|
date: overrides?.date,
|
||||||
|
modified: overrides?.modified,
|
||||||
|
image: overrides?.image,
|
||||||
|
robots: overrides?.robots ?? createRobotsValue(page.noindex),
|
||||||
|
path: overrides?.path ?? page.canonicalPath ?? page.path,
|
||||||
|
keywords: overrides?.keywords ?? [...page.keywords],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function generateRegistryStructuredData(
|
||||||
|
key: StaticSeoPageKey,
|
||||||
|
overrides?: {
|
||||||
|
title?: string
|
||||||
|
description?: string
|
||||||
|
url?: string
|
||||||
|
datePublished?: string
|
||||||
|
dateModified?: string
|
||||||
|
type?: "Article" | "WebPage"
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
const page = getSeoPageDefinition(key)
|
||||||
|
|
||||||
|
return generateStructuredData({
|
||||||
|
title: overrides?.title ?? page.title,
|
||||||
|
description: overrides?.description ?? page.description,
|
||||||
|
url: overrides?.url ?? buildAbsoluteUrl(page.canonicalPath ?? page.path),
|
||||||
|
datePublished: overrides?.datePublished,
|
||||||
|
dateModified: overrides?.dateModified,
|
||||||
|
type: overrides?.type,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate structured data (JSON-LD) for a page
|
* Generate structured data (JSON-LD) for a page
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue