JSON-LD
atroui/json-ldFreeBlock
Site graph, article, FAQ, and breadcrumb JSON-LD helpers.
Install it
npx shadcn@latest add https://atroui.com/r/json-ld.jsonSource
1import { getBrand } from "@/lib/brand"2import { getSiteDomain } from "@/lib/seo"3import { getSiteUrl } from "@/lib/site-url"45function serializeJsonLd(data: unknown): string {6 return JSON.stringify(data).replace(/</g, "\u003c")7}8910type OrgJsonLdProps = {11 name?: string12}1314export function SiteGraphJsonLd({ name }: OrgJsonLdProps = {}) {15 const brand = getBrand()16 const orgName = name ?? brand.name17 const siteUrl = getSiteUrl()18 const domain = getSiteDomain()19 const orgId = `${siteUrl}#organization`20 const webId = `${siteUrl}#website`2122 const data = {23 "@context": "https://schema.org",24 "@graph": [25 {26 "@type": "Organization",27 "@id": orgId,28 name: orgName,29 alternateName: [domain],30 url: siteUrl,31 logo: {32 "@type": "ImageObject",33 url: `${siteUrl}/favicon-192.png`,34 width: 192,35 height: 192,36 },37 description: brand.tagline,38 },39 {40 "@type": "WebSite",41 "@id": webId,42 name: orgName,43 alternateName: [domain],44 url: siteUrl,45 inLanguage: "en-US",46 publisher: { "@id": orgId },47 },48 ],49 }5051 return (52 <script53 type="application/ld+json"54 dangerouslySetInnerHTML={{ __html: serializeJsonLd(data) }}55 />56 )57}5859export function ArticleJsonLd({60 title,61 description,62 slug,63 date,64 dateModified,65 author,66 image,67 basePath = "/blog",68}: {69 title: string70 description: string71 slug: string72 date: string73 dateModified?: string74 author?: string75 image?: string76 basePath?: string77}) {78 const siteUrl = getSiteUrl()79 const brandName = getBrand().name80 const authorName = author ?? brandName81 const segment = basePath.startsWith("/") ? basePath : `/${basePath}`82 const pageUrl = `${siteUrl}${segment}/${slug}`83 const imageUrl = image?.startsWith("http")84 ? image85 : image86 ? `${siteUrl}${image.startsWith("/") ? image : `/${image}`}`87 : `${siteUrl}${segment}/${slug}/opengraph-image`8889 const data = {90 "@context": "https://schema.org",91 "@type": "Article",92 headline: title,93 description,94 datePublished: date,95 dateModified: dateModified ?? date,96 image: imageUrl,97 mainEntityOfPage: {98 "@type": "WebPage",99 "@id": pageUrl,100 },101 author: {102 "@type": "Organization",103 name: authorName,104 url: siteUrl,105 },106 publisher: {107 "@type": "Organization",108 name: brandName,109// … truncated
What it pulls in
Other registry items
Files it writes
More from atroui
All 81 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Analytics Provideranalytics-provider | atroui | Blocks | Free | 1 dep | |
| AR Portfolioar-portfolio | atroui | Blocks | Free | 1 dep | |
| Before / Afterbefore-after-slider | atroui | Blocks | Free | no deps | |
| Calendly Embedcalendly-embed | atroui | Blocks | Free | 1 dep | |
| Changelogchangelog | atroui | Blocks | Free | no deps | |
| Command Menucommand-menu | atroui | Blocks | Free | 4 deps | |
| Contact Formcontact-form | atroui | Blocks | Free | 2 deps | |
| Contextual CTAcontextual-cta | atroui | Blocks | Free | 2 deps |
