// Page metadata and structured data shared by every page: canonical URL, Open Graph and X cards, and // schema.org JSON-LD. Share images are 1200 x 630 JPEGs in public/og, made from the covers by `npm run covers`. import fs from "fs"; import path from "path"; import type { Metadata } from "next"; import type { Track } from "@/lib/tracks"; import { lastModified, type TutorialMeta } from "@/lib/tutorial-types"; export const SITE_URL = "https://airesourcepro.com"; export const SITE_NAME = "AI Resource Pro"; export const SITE_TITLE = "AI Resource Pro | Learn AI by building with it"; export const SITE_DESCRIPTION = "Free, hands-on AI tutorials and videos: Claude and Codex best practices, computer-use agents, and open-weight AI models on your own GPU."; export const SITE_OG_IMAGE = "/og/site.jpg"; // Describes the site share image for screen readers (pages with their own cover use their title) export const SITE_OG_IMAGE_ALT = "AI Resource PRO: Learn AI by building with it. The Impossible A logo drawn in black-and-white particles."; // The RSS feed, announced in every page's head (app/feed.xml) export const RSS_ALTERNATE = { "application/rss+xml": [{ url: "/feed.xml", title: `${SITE_NAME} tutorials` }] }; // Who writes the tutorials: the AI Resource Pro team (no personal byline) export const AUTHOR = { name: "AI Resource Pro", path: "/about", photo: "/android-chrome-192x192.png", }; const absolute = (p: string) => new URL(p, SITE_URL).toString(); // A cover's share image (public/og/.jpg), or the site's when that cover has none yet export function ogImageFor(cover: string): string { const og = cover.replace(/^\/covers\//, "/og/").replace(/\.webp$/, ".jpg"); return fs.existsSync(path.join(process.cwd(), "public", og)) ? og : SITE_OG_IMAGE; } type PageMeta = { title: string; description: string; // Site path, e.g. "/claude"; becomes the canonical URL path: string; image?: string; // The home page's title goes out as is instead of through the "%s | AI Resource Pro" template absoluteTitle?: boolean; type?: "website" | "article"; publishedTime?: string; modifiedTime?: string; noindex?: boolean; }; export function pageMetadata({ title, description, path: pagePath, image = SITE_OG_IMAGE, absoluteTitle, type = "website", publishedTime, modifiedTime, noindex, }: PageMeta): Metadata { const images = [{ url: image, width: 1200, height: 630, alt: image === SITE_OG_IMAGE ? SITE_OG_IMAGE_ALT : title }]; return { title: absoluteTitle ? { absolute: title } : title, description, alternates: { canonical: pagePath, types: RSS_ALTERNATE }, openGraph: { title, description, url: pagePath, siteName: SITE_NAME, locale: "en_US", images, ...(type === "article" ? { type, publishedTime, modifiedTime, authors: [absolute(AUTHOR.path)] } : { type }), }, twitter: { card: "summary_large_image", title, description, images }, ...(type === "article" ? { authors: [{ name: AUTHOR.name, url: AUTHOR.path }] } : {}), ...(noindex ? { robots: { index: false, follow: true } } : {}), }; } // ---------- JSON-LD ---------- const ORGANIZATION_ID = `${SITE_URL}/#organization`; const publisher = { "@type": "Organization", "@id": ORGANIZATION_ID, name: SITE_NAME, url: SITE_URL, logo: { "@type": "ImageObject", url: absolute("/android-chrome-512x512.png"), width: 512, height: 512 }, }; export function siteJsonLd() { return [ { "@context": "https://schema.org", ...publisher, description: SITE_DESCRIPTION, }, { "@context": "https://schema.org", "@type": "WebSite", "@id": `${SITE_URL}/#website`, url: SITE_URL, name: SITE_NAME, description: SITE_DESCRIPTION, inLanguage: "en", publisher: { "@id": ORGANIZATION_ID }, }, ]; } export function breadcrumbJsonLd(items: { name: string; path: string }[]) { return { "@context": "https://schema.org", "@type": "BreadcrumbList", itemListElement: items.map((item, i) => ({ "@type": "ListItem", position: i + 1, name: item.name, item: absolute(item.path), })), }; } // A track or the full list: the page and the tutorials it lists, in order export function collectionJsonLd({ name, description, path: pagePath, tutorials }: { name: string; description: string; path: string; tutorials: TutorialMeta[]; }) { return { "@context": "https://schema.org", "@type": "CollectionPage", name, description, url: absolute(pagePath), isPartOf: { "@id": `${SITE_URL}/#website` }, mainEntity: { "@type": "ItemList", itemListElement: tutorials.map((t, i) => ({ "@type": "ListItem", position: i + 1, url: absolute(`/${t.track}/${t.slug}`), name: t.title, })), }, }; } // Tutorials are dated by day only; Google wants a time zone, so send the start of that day in New York function startOfDay(day: string): string { // 05:00 UTC is just after midnight in New York, so DST changeover days get midnight's own offset const nearMidnight = new Date(`${day}T05:00:00Z`); const zone = new Intl.DateTimeFormat("en-US", { timeZone: "America/New_York", timeZoneName: "longOffset" }) .formatToParts(nearMidnight) .find((p) => p.type === "timeZoneName")?.value; const offset = zone?.replace("GMT", "") || "+00:00"; return `${day}T00:00:00${offset}`; } export function tutorialJsonLd(tutorial: TutorialMeta, track: Track) { const url = absolute(`/${tutorial.track}/${tutorial.slug}`); const article = { "@context": "https://schema.org", "@type": "TechArticle", headline: tutorial.title, description: tutorial.description, url, mainEntityOfPage: url, image: [absolute(ogImageFor(tutorial.cover)), absolute(tutorial.cover)], ...(tutorial.publishedAt ? { datePublished: startOfDay(tutorial.publishedAt), dateModified: startOfDay(lastModified(tutorial)) } : {}), author: { "@id": ORGANIZATION_ID }, publisher, articleSection: track.name, proficiencyLevel: tutorial.level, timeRequired: `PT${tutorial.minutes}M`, inLanguage: "en", isAccessibleForFree: true, }; if (!tutorial.video) return [article]; const video = { "@context": "https://schema.org", "@type": "VideoObject", name: tutorial.title, description: tutorial.description, thumbnailUrl: `https://airesourcepro.com/media/video/${tutorial.video}/poster.jpg`, ...(tutorial.videoUploadedAt ? { uploadDate: tutorial.videoUploadedAt } : {}), contentUrl: `https://airesourcepro.com/media/video/${tutorial.video}/${tutorial.video}-1080p.mp4`, publisher, }; return [article, video]; }