Astro blog integration
Render your Opinly blog as a static Astro site with @opinly/astro — one page for every post, category, tag and author, with SEO, sitemap, RSS and analytics built in.
@opinly/astro turns your Opinly content into a static Astro site: every published post,
category, tag and author page, with SEO tags, structured data, a sitemap, an RSS feed and
Opinly Analytics. Pages are built at build time, with no client-side JavaScript.
Install
pnpm add @opinly/astronpm i @opinly/astroyarn add @opinly/astroSet OPINLY_API_KEY in your build environment (create one under Settings → Developers in the
Opinly dashboard). It's read at build time only and never reaches the page. Requires Astro 5.
Configure
// astro.config.mjs
import { defineConfig } from 'astro/config'
import opinly from '@opinly/astro'
export default defineConfig({
integrations: [
opinly({
siteUrl: 'https://www.acme.com',
siteName: 'Acme',
blogPath: '/blog',
cdnNamespace: 'REPLACE-ME-xxxxxxxx', // your 21-char CDN namespace
pixel: { writeKey: 'pk-…', host: 'https://static.opinly.ai' }, // optional
}),
],
})The integration adds /blog/sitemap.xml and /blog/rss.xml, and tells Opinly where your blog
lives, so each post's address, rankings and traffic show up in the dashboard.
One page for the whole blog
---
// src/pages/blog/[...slug].astro
import { OpinlyContent, OpinlyHead, OpinlyPixel } from '@opinly/astro/components'
import { getOpinlyStaticPaths, links, type OpinlyPage } from '@opinly/astro/runtime'
export const getStaticPaths = getOpinlyStaticPaths
const { page } = Astro.props as { page: OpinlyPage }
---
<html lang="en">
<head><OpinlyHead page={page} /></head>
<body>
{page.type === 'post' && (
<article class="prose">
<h1>{page.post.title}</h1>
<OpinlyContent post={page.post} />
</article>
)}
{page.type !== 'post' && (
<ul>{page.posts.map((post) => <li><a href={links.post(post)}>{post.title}</a></li>)}</ul>
)}
<OpinlyPixel />
</body>
</html>page.type is home, post, category, tag or author, and each comes with the data it
renders. links builds every URL and image path from your config, so your links always match
the sitemap.
Components
<OpinlyHead page jsonLd? />: title, description, canonical, Open Graph, Twitter card, and BlogPosting and FAQ structured data for posts. PassjsonLdto add your own.<OpinlyContent post classNames? nodes? marks? />: the post body as HTML. Text is escaped and unsafe URLs are dropped.nodesandmarksoverride how a type renders. See Rendering.<OpinlyPixel />: Opinly Analytics, including page views after client-side navigation with Astro's<ClientRouter />.
Keeping it fresh
A static site shows what was published when it last built. Rebuild when content changes: add a webhook that triggers your host's build hook (Vercel, Netlify and Cloudflare Pages all have one).
Preview unpublished posts
Set OPINLY_SHOW_DRAFT=true on a preview build and it renders every post's latest edits, plus
posts that have never been published. Leave it off on your live site. See
preview mode.