11---
22import { Metadata , QuickstartsFrontmatter } from " src/content.config.ts"
33import { SITE , OPEN_GRAPH , PAGE } from " ../config"
4+ import { getOgType } from " ~/utils/seo/og"
5+ import { resolveCanonical , getMimeFromUrlPath , toAbsoluteUrl } from " ~/utils/seo/url"
46import { detectApiReference } from " @components/VersionSelector/utils/versions"
57import { extractVersionInfo } from " @components/VersionSelector/utils/extractVersionInfo"
68import VersionSelectorHead from " @components/VersionSelector/base/VersionSelectorHead.astro"
@@ -13,9 +15,11 @@ export interface Props {
1315 quickstartFrontmatter? : QuickstartsFrontmatter
1416 pageTitle? : string // Add page title from frontmatter
1517 howToSteps? : { name: string ; slug: string }[]
18+ suppressDefaultStructuredData? : boolean
1619}
1720
18- const { metadata, canonicalURL, quickstartFrontmatter, pageTitle, howToSteps } = Astro .props
21+ const { metadata, canonicalURL, quickstartFrontmatter, pageTitle, howToSteps, suppressDefaultStructuredData } =
22+ Astro .props
1923const contentTitle = pageTitle ?? metadata ?.title ?? PAGE .titleFallback
2024const formattedContentTitle = ` ${contentTitle } | ${SITE .title } `
2125const description = metadata ?.description ?? SITE .description
@@ -26,14 +30,10 @@ var canonicalImageSrc = OPEN_GRAPH.image.src
2630let ogImageType = " image/png"
2731let ogImageAlt = OPEN_GRAPH .image .alt
2832if (metadata ?.image ) {
29- const imageUrl = new URL (metadata .image , Astro .site ). toString ( )
33+ const imageUrl = toAbsoluteUrl (metadata .image , Astro .site )
3034 canonicalImageSrc = imageUrl
31- // Infer from URL pathname only (ignore query/hash) to avoid network requests
32- const pathname = new URL (imageUrl ).pathname .toLowerCase ()
33- if (pathname .endsWith (" .jpg" ) || pathname .endsWith (" .jpeg" )) ogImageType = " image/jpeg"
34- else if (pathname .endsWith (" .png" )) ogImageType = " image/png"
35- else if (pathname .endsWith (" .webp" )) ogImageType = " image/webp"
36- else if (pathname .endsWith (" .gif" )) ogImageType = " image/gif"
35+ const pathname = new URL (imageUrl ).pathname
36+ ogImageType = getMimeFromUrlPath (pathname ) || ogImageType
3737}
3838
3939// Prefer a context-specific image alt when possible
@@ -54,60 +54,38 @@ if (isApiReference && product && isVersioned) {
5454}
5555
5656// Generate structured data
57- const canonicalURLObj = typeof canonicalURL === " string" ? new URL (canonicalURL ) : canonicalURL
57+ const canonicalURLObj: URL = typeof canonicalURL === " string" ? new URL (canonicalURL ) : ( canonicalURL as URL )
5858
5959// Canonical override support (non-versioned pages only)
60- const resolvedCanonicalHref = (() => {
61- const candidate = metadata ?.canonical
62- if (! candidate ) return canonicalURL
63- try {
64- // If candidate is absolute, use it; otherwise resolve against site
65- const url = new URL (candidate , Astro .site )
66- return url .toString ()
67- } catch {
68- return canonicalURL
69- }
70- })()
60+ const resolvedCanonicalHref = resolveCanonical (metadata ?.canonical , Astro .site , canonicalURLObj )
7161
7262// Contextual Open Graph type
73- const ogType = (() => {
74- const websiteExact = new Set ([
75- " /" ,
76- " /ccip" ,
77- " /data-feeds" ,
78- " /vrf" ,
79- " /chainlink-functions" ,
80- " /chainlink-automation" ,
81- " /chainlink-local" ,
82- " /resources" ,
83- ])
84- const isWebsite = websiteExact .has (currentPage ) || currentPage .startsWith (" /ccip/directory" )
85- return isWebsite ? " website" : " article"
86- })()
63+ const ogType = getOgType (currentPage )
8764
8865// Use quickstart frontmatter if available, otherwise use regular metadata
8966// Suppress default structured data for CCIP directory pages (handled by page-level generators)
90- const structuredDataObjects = isCcipDirectoryPath
91- ? []
92- : quickstartFrontmatter
93- ? generateStructuredData (
94- quickstartFrontmatter ,
95- contentTitle ,
96- canonicalURLObj ,
97- currentPage ,
98- undefined ,
99- undefined ,
100- howToSteps
101- )
102- : generateStructuredData (
103- metadata ,
104- contentTitle ,
105- canonicalURLObj ,
106- currentPage ,
107- metadata ?.estimatedTime ,
108- versionInfo ,
109- howToSteps
110- )
67+ const structuredDataObjects =
68+ suppressDefaultStructuredData || isCcipDirectoryPath
69+ ? []
70+ : quickstartFrontmatter
71+ ? generateStructuredData (
72+ quickstartFrontmatter ,
73+ contentTitle ,
74+ canonicalURLObj ,
75+ currentPage ,
76+ undefined ,
77+ undefined ,
78+ howToSteps
79+ )
80+ : generateStructuredData (
81+ metadata ,
82+ contentTitle ,
83+ canonicalURLObj ,
84+ currentPage ,
85+ metadata ?.estimatedTime ,
86+ versionInfo ,
87+ howToSteps
88+ )
11189---
11290
11391<!-- Page Metadata --> { /* Conditional canonical: Let VersionSelectorHead handle it for versioned pages */ }
0 commit comments