@
feat(web): SEO — server-rendered template pages + /guides articles - templates/[slug] converted from client to server component: per-template generateMetadata (title/description/canonical/OG) + SoftwareApplication JSON-LD; code-audit toggle split into a client island; missing/non-public templates now return a real 404. - sitemap.ts pulls public template slugs live from the API (best-effort) + the new /guides routes. - new /guides section: 3 server-rendered SEO articles (host MCP with OAuth, hosted-platforms comparison, MintMCP alternative) with TechArticle JSON-LD; Guides link added to the marketing nav. - lib/seo.ts: articleJsonLd + templateJsonLd builders. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> @
This commit is contained in:
76
apps/web/lib/templates-server.ts
Normal file
76
apps/web/lib/templates-server.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
// Server-only fetchers for the public template marketplace. Used by the
|
||||
// server-rendered template detail page (SEO metadata + JSON-LD) and the
|
||||
// sitemap. Never import this into a client component.
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:4000';
|
||||
|
||||
export interface TemplateTool {
|
||||
name: string;
|
||||
description: string;
|
||||
inputSchema: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface TemplateSecretHint {
|
||||
key: string;
|
||||
description: string;
|
||||
howToGetUrl?: string;
|
||||
}
|
||||
|
||||
export interface TemplateDetail {
|
||||
id: string;
|
||||
slug: string;
|
||||
title: string;
|
||||
shortDescription: string;
|
||||
longDescription: string | null;
|
||||
category: string;
|
||||
status: 'draft' | 'public' | 'hidden' | 'takedown';
|
||||
verified: boolean;
|
||||
forkCount: number;
|
||||
activeDeployments: number;
|
||||
toolsSchema: TemplateTool[];
|
||||
generatedCode: string;
|
||||
requiredSecrets: TemplateSecretHint[];
|
||||
scopes: string[];
|
||||
ownerName: string | null;
|
||||
ownerOrgName: string | null;
|
||||
sourceServerId: string | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a single public template by slug for server rendering. Returns null
|
||||
* for missing / non-public templates so the page can `notFound()` — we only
|
||||
* want `public` templates indexed.
|
||||
*/
|
||||
export async function fetchTemplate(slug: string): Promise<TemplateDetail | null> {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/v1/templates/${encodeURIComponent(slug)}`, {
|
||||
// Cache server-side for 5 min so crawler hits don't hammer the API.
|
||||
next: { revalidate: 300 },
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const data = (await res.json()) as { template?: TemplateDetail };
|
||||
const t = data.template;
|
||||
if (!t || t.status !== 'public') return null;
|
||||
return t;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Slugs of public templates, for the sitemap. Best-effort: returns [] on error. */
|
||||
export async function fetchPublicTemplateSlugs(): Promise<string[]> {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/v1/templates?limit=100&sort=newest`, {
|
||||
next: { revalidate: 600 },
|
||||
});
|
||||
if (!res.ok) return [];
|
||||
const data = (await res.json()) as
|
||||
| { templates?: Array<{ slug?: string }> }
|
||||
| Array<{ slug?: string }>;
|
||||
const list = Array.isArray(data) ? data : (data.templates ?? []);
|
||||
return list.map((t) => t.slug).filter((s): s is string => typeof s === 'string');
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user