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
9 changes: 9 additions & 0 deletions app/(site)/[[...slug]]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { notFound } from 'next/navigation';
import { fetchPlainHtml, EDS_ORIGIN } from '../../../lib/eds/fetch.js';
import { parseEds } from '../../../lib/eds/parse.js';
import { renderNode } from '../../../lib/eds/render.js';
import { buildMetadata } from '../../../lib/eds/metadata.js';

// Per-page <head> metadata (title, description, Open Graph) from the page's authored Metadata
// block, read via the query-index feed. Falls back to the root layout defaults when a page
// isn't indexed.
export async function generateMetadata({ params }) {
const { slug } = await params;
return buildMetadata((slug ?? []).join('/'));
}

// Pre-render every published page at build time from the EDS query-index feed (SSG). Pages
// not in the feed (or added later) still resolve on demand via ISR, since dynamicParams
Expand Down
23 changes: 23 additions & 0 deletions lib/eds/metadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { fetchQueryIndex, normalizePath } from './queryIndex.js';

// Build Next.js metadata for a page from the EDS query-index — title, description, and
// og:image, all authored via the page's Metadata block and indexed by helix-query.yaml.
// Returns {} when the page isn't in the feed (unpublished / excluded), so the root layout's
// default title/description apply.
export async function buildMetadata(pathSlug = '') {
const map = await fetchQueryIndex();
const row = map.get(normalizePath(`/${pathSlug}`));
if (!row) return {};

const meta = {};
if (row.title) meta.title = row.title;
if (row.description) meta.description = row.description;

const openGraph = {};
if (row.title) openGraph.title = row.title;
if (row.description) openGraph.description = row.description;
if (row.image) openGraph.images = [{ url: row.image }];
if (Object.keys(openGraph).length) meta.openGraph = openGraph;

return meta;
}