Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions apps/site/src/lib/structured-data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
import { absoluteUrl, SITE_NAME } from "./site";
import { youtubeId } from "./youtube";

function cleanDescription(
desc?: string | null,
fallback?: string | null,
): string | undefined {
const trimmed = desc?.trim();
if (trimmed && trimmed.toLowerCase() !== "fix me") {
return trimmed;
}
const fb = fallback?.trim();
return fb && fb.toLowerCase() !== "fix me" ? fb : undefined;
}

/**
* JSON-LD builders, ported from the Next app's lib/structured-data.ts.
Expand Down Expand Up @@ -97,7 +110,7 @@ export function articleSchema(
"@type": content.articleType ?? "TechArticle",
"@id": `${url}#article`,
headline: content.title ?? undefined,
description: content.excerpt ?? undefined,
description: cleanDescription(content.excerpt, content.title),
...(content.imageUrl ? { image: content.imageUrl } : {}),
...(content.date ? { datePublished: content.date } : {}),
...(content._updatedAt ? { dateModified: content._updatedAt } : {}),
Expand Down Expand Up @@ -204,19 +217,27 @@ export function videoObjectSchema(
durationIso = d;
}

const ytId = youtubeId(video.youtubeUrl);
const resolvedThumb =
video.thumbnailUrl ||
(ytId ? `https://i.ytimg.com/vi/${ytId}/hqdefault.jpg` : undefined);
const embedUrl = ytId
? `https://www.youtube.com/embed/${ytId}`
: video.youtubeUrl
.replace("watch?v=", "embed/")
.replace("youtu.be/", "www.youtube.com/embed/");

return {
"@type": "VideoObject",
"@id": `${url}#video`,
name: video.title ?? undefined,
description: video.description ?? undefined,
...(video.thumbnailUrl ? { thumbnailUrl: [video.thumbnailUrl] } : {}),
description: cleanDescription(video.description, video.title),
...(resolvedThumb ? { thumbnailUrl: [resolvedThumb] } : {}),
...(video.uploadDate ? { uploadDate: video.uploadDate } : {}),
...(durationIso ? { duration: durationIso } : {}),
...(video.transcript ? { transcript: video.transcript } : {}),
contentUrl: video.youtubeUrl,
embedUrl: video.youtubeUrl
.replace("watch?v=", "embed/")
.replace("youtu.be/", "www.youtube.com/embed/"),
embedUrl,
};
}

Expand Down Expand Up @@ -326,7 +347,7 @@ export function podcastEpisodeSchema(
"@id": `${url}#episode`,
url,
name: content.title ?? undefined,
description: content.excerpt ?? undefined,
description: cleanDescription(content.excerpt, content.title),
...(content.date ? { datePublished: content.date } : {}),
...(content.imageUrl ? { image: content.imageUrl } : {}),
...(content.season ? { seasonNumber: content.season } : {}),
Expand Down
15 changes: 10 additions & 5 deletions apps/site/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@ export const onRequest = defineMiddleware(async (context, next) => {
});
}

if (context.locals.sanity.preview.enabled) {
// Not cosmetic: without this a response containing unpublished drafts can
// be written to the edge cache and served to the public.
response.headers.set("Cache-Control", "no-store, private");
if (
context.locals.sanity.preview.enabled ||
origin !== "https://codingcat.dev"
) {
if (context.locals.sanity.preview.enabled) {
// Not cosmetic: without this a response containing unpublished drafts can
// be written to the edge cache and served to the public.
response.headers.set("Cache-Control", "no-store, private");
}
response.headers.set("X-Robots-Tag", "noindex, nofollow");
}

Expand All @@ -97,7 +102,7 @@ export const onRequest = defineMiddleware(async (context, next) => {
);

// AIPREF / AI Preference Headers
response.headers.set("Content-Usage", "train-ai=n, search=y");
response.headers.set("Content-Usage", "train-ai=y, search=y");

// Always emit Link headers (RFC 8288) for AI agent discoverability
response.headers.set(
Expand Down
Loading