File size: 7,954 Bytes
689359a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | import Image from "next/image";
import Link from "next/link";
import { getLocale, getTranslations } from "next-intl/server";
import { ArrowRight, Github } from "lucide-react";
import { RelatedGuides } from "@/components/marketing/related-guides";
import { SiteFooter } from "@/components/marketing/site-footer";
import { intlLocale } from "@/i18n/config";
import { type BlogPost, getSiteUrl } from "@/lib/blog-posts";
import { GITHUB_URL } from "@/lib/site";
export interface ArticleFaq {
question: string;
answer: string;
}
export const articleProseClassName =
"space-y-6 leading-8 [&_h2]:scroll-mt-8 [&_h2]:pt-6 [&_h2]:text-2xl [&_h2]:font-bold [&_h2]:tracking-tight [&_h3]:pt-2 [&_h3]:text-lg [&_h3]:font-semibold [&_a]:font-medium [&_a]:underline [&_a]:underline-offset-4 [&_p]:text-muted-foreground [&_li]:text-muted-foreground [&_ul]:ml-5 [&_ul]:list-disc [&_ul]:space-y-2 [&_ol]:ml-5 [&_ol]:list-decimal [&_ol]:space-y-2 [&_code]:rounded [&_code]:bg-muted [&_code]:px-1.5 [&_code]:py-0.5 [&_code]:font-mono [&_code]:text-[0.85em] [&_code]:text-foreground";
export function formatArticleDate(date: string, locale: string) {
return new Intl.DateTimeFormat(intlLocale(locale), { dateStyle: "long", timeZone: "UTC" }).format(new Date(`${date}T00:00:00.000Z`));
}
export function CodeBlock({ children, label }: { children: string; label?: string }) {
return (
<figure className="not-prose overflow-hidden rounded-lg border bg-zinc-950 text-zinc-100">
{label ? <figcaption className="border-b border-zinc-800 px-4 py-2 font-mono text-xs text-zinc-400">{label}</figcaption> : null}
<pre className="overflow-x-auto p-4 text-[13px] leading-6"><code className="!bg-transparent !p-0 !text-[13px] !text-zinc-100">{children.trim()}</code></pre>
</figure>
);
}
/** Header, breadcrumb, JSON-LD, related links, and footer shared by long-form blog articles. */
export async function ArticleShell({
post,
breadcrumb,
toc,
faqs,
cta,
videos = [],
children,
}: {
post: BlogPost;
breadcrumb: string;
toc: Array<[id: string, label: string]>;
faqs: ArticleFaq[];
cta?: { title: string; body: string; label: string; href?: string };
videos?: Array<Record<string, unknown>>;
children: React.ReactNode;
}) {
const locale = post.language ?? await getLocale();
const t = await getTranslations({ locale, namespace: "blog" });
const siteUrl = getSiteUrl();
const url = `${siteUrl}/blog/${post.slug}`;
const updatedLabel = formatArticleDate(post.updatedAt, locale);
const structuredData = {
"@context": "https://schema.org",
"@graph": [
...videos,
{
"@type": "BreadcrumbList",
itemListElement: [
{ "@type": "ListItem", position: 1, name: t("shell.home"), item: siteUrl },
{ "@type": "ListItem", position: 2, name: t("shell.blog"), item: `${siteUrl}/blog` },
{ "@type": "ListItem", position: 3, name: breadcrumb, item: url },
],
},
{
"@type": "BlogPosting",
headline: post.title,
description: post.description,
datePublished: post.publishedAt,
dateModified: post.updatedAt,
author: { "@type": "Organization", name: post.author },
publisher: { "@type": "Organization", name: "SupoClip", url: siteUrl, logo: { "@type": "ImageObject", url: `${siteUrl}/logo.png` } },
articleSection: post.category,
keywords: post.keywords.join(", "),
inLanguage: intlLocale(locale),
mainEntityOfPage: url,
image: post.image ? `${siteUrl}${post.image.src}` : undefined,
},
{
"@type": "FAQPage",
mainEntity: faqs.map(({ question, answer }) => ({
"@type": "Question",
name: question,
acceptedAnswer: { "@type": "Answer", text: answer },
})),
},
],
};
return (
<main className="min-h-screen bg-background text-foreground">
<script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(structuredData).replace(/</g, "\\u003c") }} />
);
}
|