Docs

Get your blog up and running in 10 minutes.

Go to Dashboard

Quickstart

Pick your framework. Next.js with the App Router is the one to take if you have the choice: your posts end up in the HTML, so search engines and link previews both work.

1Create a blog and copy its API key

Sign up, name your blog, pick a design. You land on an API key. Keys are read-only, belong to one blog, and can be revoked at any time from API Keys in the dashboard.

2Install the SDK

npm install @blogbuddy/sdk

3Put your key in the environment

.env.local
BLOGBUDDY_API_KEY=sk_live_your_key_here
NEXT_PUBLIC_SITE_URL=https://acme.com

4Write one config object

Every component and helper below takes this same object, so it is written once.

lib/blogbuddy.ts
import type { BlogBuddyConfig } from '@blogbuddy/sdk/server'

export const blog: BlogBuddyConfig = {
  blog: 'your-blog-slug',
  apiKey: process.env.BLOGBUDDY_API_KEY!,
  siteUrl: process.env.NEXT_PUBLIC_SITE_URL!,
  postUrlTemplate: '/blog/{slug}',
  siteName: 'Acme',
}

5Add the post page

notFound() matters: without onNotFound an unknown slug throws, and the framework reports that as a 500 rather than a 404.

app/blog/[slug]/page.tsx
import { notFound } from 'next/navigation'
import { BlogBuddyPost, blogBuddyMetadata, blogBuddyStaticParams } from '@blogbuddy/sdk/server'
import { blog } from '@/lib/blogbuddy'

export const generateMetadata = blogBuddyMetadata(blog)
export const generateStaticParams = blogBuddyStaticParams(blog)

export default async function Page({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params
  return <BlogBuddyPost {...blog} slug={slug} onNotFound={notFound} />
}

6Add the index page

app/blog/page.tsx
import { BlogBuddyList } from '@blogbuddy/sdk/server'
import { blog } from '@/lib/blogbuddy'

export default async function Page({ searchParams }: { searchParams: Promise<{ page?: string }> }) {
  const { page } = await searchParams
  return <BlogBuddyList {...blog} perPage={10} page={Number(page) || 1} title="Blog" />
}

That is a working blog. SEO adds the sitemap, feeds and share cards.

Components

On a server: @blogbuddy/sdk/server

React Server Components. Next.js App Router, or any framework that can render them.

ComponentWhat it does
BlogBuddyPostOne post, rendered with your published design. Fetches the post and the template, emits JSON-LD, and counts the view. Takes slug plus your config.
BlogBuddyListYour index page: every published post through the list design, paginated if the design has a Pagination block. Takes perPage and page.

In a browser: @blogbuddy/sdk/renderer

The same two components for Vite, Create React App and any other single-page build. The dot is the whole difference: dotted means the browser.

ComponentWhat it does
BlogBuddy.PostThe browser equivalent of BlogBuddyPost. Same design, fetched and rendered client-side.
BlogBuddy.ListThe browser equivalent of BlogBuddyList. Pages in place rather than by URL.

Nothing in the package imports from Next, so a single-page build will bundle the server pair happily and then throw at runtime with a message naming the dotted ones.

If you render posts yourself
ComponentWhat it does
ArticleJsonLdStructured data for one post, if you render the body yourself. From /json-ld.
JsonLdAny object as a JSON-LD script tag. From /json-ld.
BlogBuddyViewBeaconCounts a view for a post you rendered yourself. From /view-beacon.

Route helpers

One line per route. Each takes the config object from the quickstart and returns the export that route expects.

HelperWhat it does
blogBuddyMetadata(config)Export as generateMetadata. Title, description, canonical, Open Graph and Twitter tags for the post at that slug.
blogBuddyStaticParams(config)Export as generateStaticParams. Pre-renders every published post at build time.
blogBuddySitemap(config, options?)Export as the default from app/sitemap.ts. Takes extra for your non-blog URLs. Noindexed posts are dropped.
blogBuddyFeed(config, options?)Export as GET from a route. RSS by default; pass format: "atom" for Atom, fullContent: true to include post bodies.
app/sitemap.ts
import { blogBuddySitemap } from '@blogbuddy/sdk/server'
import { blog } from '@/lib/blogbuddy'

export default blogBuddySitemap(blog, {
  extra: [{ url: 'https://acme.com', lastModified: new Date().toISOString(), priority: 1 }],
})
app/blog/feed.xml/route.ts
import { blogBuddyFeed } from '@blogbuddy/sdk/server'
import { blog } from '@/lib/blogbuddy'

export const GET = blogBuddyFeed(blog)
app/robots.ts
export default function robots() {
  return { rules: { userAgent: '*', allow: '/' }, sitemap: 'https://acme.com/sitemap.xml' }
}

A sitemap may only list URLs on the host that serves it, which is why these live in your app rather than ours. A feed names its own address, and the default assumes the paths above - mounting one elsewhere takes a path: blogBuddyFeed(blog, { feedUrl: '/feed.xml' }).

SEO

Your posts live on your domain, so the SEO value is yours - and the canonical tags, previews and sitemap have to be served from your site. BlogBuddy generates them; you serve them.

1. Fill in Blog settings → SEO

Set your Site URL and Post URL pattern. Every absolute URL is built from those two. The same panel holds the defaults every post inherits: site name, a default share image, a default author and a language. Paste a share image and its dimensions are measured for you, which is what lets an unfurler lay the card out before the image arrives.

Skip it and siteUrl comes back null - nothing crashes, but your canonical tags have no domain to point at, so keep the fallback in your own config as the quickstart does.

2. What each post gets on its own

Every post's search details are worked out from the post itself, with nothing to fill in:

  • Title - the post's headline.
  • Description - the opening of the post, cut to about 160 characters.
  • Author - a teammate's name, or any other name for a guest post. Left empty, it is the blog's default author.

On Pro and up, each post's Search and sharing panel lets you change them. The fields open with the automatic text already in them; anything you leave as it is keeps following the post.

  • Search title - what result lists and shared links show. The <h1> never changes, and JSON-LD keeps the real headline.
  • Search description - used instead of the opening of the post.
  • Hide from search engines - emits noindex, follow and drops the post from the sitemap. It stays public and linkable.
Config fields, and a share image per post

Config fields worth knowing

FieldWhat it does
blogYour blog slug. Required.
apiKeyA key for that blog. Required.
siteUrlWhere your site lives, e.g. https://acme.com. Every absolute URL is built from it.
postUrlTemplateWhere one post lives, e.g. /blog/{slug}. Defaults to /blog/{slug}.
pageUrlTemplateWhere page N of your index lives. Set it if your index pages are path segments rather than a query string.
postImageUrlTemplateA route that generates a share card per post. Without it, posts with no cover share one site-wide image.
siteNameThe source shown on a shared link. Falls back to the blog settings.
revalidateHow long a fetched post is cached, in seconds. Defaults to an hour, so a newly published post appears without a redeploy.

A share image per post

Without one, every post with no cover image shares the same site-wide card - so the preview says what the site is rather than what the post is. Point postImageUrlTemplate at a route on your own site that draws one:

lib/blogbuddy.ts
export const blog: BlogBuddyConfig = {
  // ...
  postImageUrlTemplate: '/blog/{slug}/opengraph-image',
}
app/blog/[slug]/opengraph-image.tsx
import { ImageResponse } from 'next/og'
import { getPost } from '@blogbuddy/sdk/server'
import { blog } from '@/lib/blogbuddy'

export const size = { width: 1200, height: 630 }
export const contentType = 'image/png'

export default async function Image({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params
  const { title } = await getPost({ ...blog, slug })
  return new ImageResponse(<div style={{ /* ... */ }}>{title}</div>, size)
}

The order is: the post's own cover image, then this, then the default share image from your blog settings.

3. Checking it worked

  • curl a post URL and confirm the article text is in the body. If it is not, no amount of metadata will help.
  • Paste a post URL into Slack. A title, description and image mean your Open Graph tags are right.
  • Run the URL through Google's Rich Results Test to validate the JSON-LD.
  • Submit your sitemap in Search Console, then check the post count matches.
Advanced

Not needed for a working blog. Open what applies to you.

Vite, CRA and other SPAs

The Vite or React tab in the quickstart sets one up. BlogBuddy.Post and BlogBuddy.List fetch the posts and your design, declare your fonts, apply your CSS, and write the title, description, canonical link and Open Graph tags.

What a browser-only blog gives up, plus a sitemap and feeds

What you give up, and what you do not

Your blog looks identical either way - same design, same blocks, same fonts. Every difference below comes from one thing: whether HTML exists before the visitor’s browser starts working.

FeatureNext.jsVite / CRA
The post text is in the HTML your host returns
Yes
NoAn empty shell, filled in by JavaScript
Link previews in Slack, X, iMessage
Yes
NoUnfurlers run no JavaScript. No library fixes this
Google indexes the post
YesStraight away
PartlyOnce Google returns to run the JavaScript
Titles, descriptions, canonical tags
Yes
YesReact 19 hoists them. On React 18, add react-helmet-async
Sitemap and RSS/Atom feeds
YesOne line each
YesA prebuild script writes real files
A URL per page of the index
YesReal links, e.g. ?page=2
NoButtons that swap in place
Your API key stays off the client
YesServer-side only
NoShips in the bundle. Use a second key

The two you cannot buy back are the preview card and the post text being in the response, because the programs that need them run no JavaScript. If link previews matter, prerender at build time with a browser-snapshot prerenderer, which loads each route in a real browser and saves the settled DOM. An SSR-style one renders in Node, where effects never run, so you get the empty shell.

Sitemap and feeds

These you can have in full. The root SDK entry runs in Node, so a prebuild script writes real static files that crawlers fetch directly.

scripts/generate-seo.mjs
import { writeFileSync } from 'node:fs'
import { buildSitemapEntries, buildRssFeed } from '@blogbuddy/sdk'

const config = { siteUrl: 'https://acme.com', postUrlTemplate: '/blog/{slug}', siteName: 'Acme' }

const { data: posts } = await fetch(
  'https://api.blogbuddy.net/api/v1/posts?blog=your-blog-slug',
  { headers: { Authorization: `Bearer ${process.env.BLOGBUDDY_API_KEY}` } }
).then((r) => r.json())

writeFileSync('public/sitemap.xml',
  '<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' +
  buildSitemapEntries(posts, config)
    .map((e) => `  <url><loc>${e.url}</loc><lastmod>${new Date(e.lastModified).toISOString()}</lastmod></url>`)
    .join('\n') + '\n</urlset>\n')

writeFileSync('public/feed.xml',
  buildRssFeed(posts, config, { feedUrl: 'https://acme.com/feed.xml' }).body)

Use two keys, not one.

The script above runs in CI, so its key stays in an environment variable. The key you pass to BlogBuddy.Post ships inside your bundle - make it a separate key on the same blog, so a lifted one can be revoked without breaking your build. Keys are read-only either way, so the worst it can do is read posts that are already public.

Data functions and hooks

For rendering your own UI instead of the published design.

Show the functions and hooks

On a server: @blogbuddy/sdk/server

FunctionWhat it does
getPost(config, slug)One post. Throws when the slug does not exist - pair it with isRequestError.
getPosts(config)Every published post, newest first.
getPostsPage(config, options)One page of posts, plus the total and page count.
getPostsForSitemap(config)Slugs and dates only, with no post bodies. A fraction of the payload.
getBlogConfig(config)The blog's name, slug and every SEO default saved in Blog settings.
seoConfig(config)Your config merged with those saved defaults, ready to hand to any build* function.
isRequestError(error, status?)Narrows a thrown fetch error so you can tell a 404 from an outage.

In a browser: @blogbuddy/sdk/hooks

HookWhat it does
useBlogBuddy(options)Every published post, with loading and error. For rendering your own UI.
useBlogBuddyPost(options)A single post by slug. Pass countViews: false to read without counting, or referrer: false to count it without sending where the reader came from.
useBlogBuddyTemplate(options)The blog's published design, if you want to render it yourself.
app/blog/custom-list.tsx
'use client'
import { useBlogBuddy } from '@blogbuddy/sdk/hooks'

export function CustomList({ apiKey }: { apiKey: string }) {
  const { data: posts, loading, error } = useBlogBuddy({ blog: 'your-blog-slug', apiKey })

  if (loading) return <p>Loading…</p>
  if (error) return <p>Could not load posts.</p>
  return <ul>{posts.map((p) => <li key={p.slug}>{p.title}</li>)}</ul>
}

Everywhere: @blogbuddy/sdk

The root entry is framework-free and runs in Node, so a build script can use it. Every route helper above is a thin wrapper over these.

FunctionWhat it does
buildPostMetadata(post, config)Everything a post page needs in <head>. What blogBuddyMetadata wraps.
buildBlogMetadata(config, options?)The same for an index page. Pass page for paginated indexes, or every page canonicalises to page one.
buildSitemapEntries(posts, config)Sitemap rows, with noindexed posts removed.
buildArticleJsonLd(post, config)Article structured data as a plain object.
buildBreadcrumbJsonLd(post, config)Puts "site › Blog › Post" under a search result instead of a raw URL.
buildBlogJsonLd(posts, config)Describes an index as a blog carrying those posts.
buildRssFeed / buildAtomFeedA feed document and its content type, for serving yourself.
feedLinkTags(config)<link rel="alternate"> tags, so browsers and readers discover your feeds.
postUrl / blogIndexUrl / postDescriptionThe small pieces the builders above are made of.

Next.js Cache Components

Only if your next.config.ts sets cacheComponents: true. Next then stops caching fetch implicitly: data is either inside a "use cache" boundary, which can be prerendered, or it counts as runtime data. The SDK fetches over the network, so the build stops on generateMetadata:

Show the fix
the build output
Next.js encountered uncached or runtime data in `generateMetadata()`.
This route's metadata is blocked, but the rest of its content can be prerendered.

Wrap the metadata helper

On an index page, call it inside a cached function:

app/blog/page.tsx
const blogMetadata = blogBuddyMetadata(blog)

export async function generateMetadata() {
  "use cache"
  return blogMetadata()
}

On a post page, pass the route props through:

app/blog/[slug]/page.tsx
const postMetadata = blogBuddyMetadata(blog)

export async function generateMetadata(props: { params: Promise<{ slug: string }> }) {
  "use cache"
  return postMetadata(props)
}

The default cache profile revalidates every 15 minutes. Use cacheLife inside the same function to change that.

Give the page body its own boundary

A different one, and for a different reason: reading params or searchParams in a page component makes the whole route depend on the URL. Move that access into a child inside Suspense:

app/blog/page.tsx
async function Posts({ searchParams }: { searchParams: Promise<{ page?: string }> }) {
  const { page } = await searchParams
  return <BlogBuddyList {...blog} perPage={10} page={Number(page) || 1} />
}

export default function Page({ searchParams }: { searchParams: Promise<{ page?: string }> }) {
  return (
    <Suspense fallback={<p>Loading…</p>}>
      <Posts searchParams={searchParams} />
    </Suspense>
  )
}

A page that reads neither needs nothing - the components suspend and stream on their own. And the SDK cannot do any of this for you: "use cache" only compiles when the flag is on, so shipping it inside the package would break every app that has not turned it on. The boundary belongs in your app.

REST API

Everything is under /api/v1 and takes a bearer key. The SDK calls these for you; use them directly if you are not on React.

Authorization: Bearer sk_live_your_api_key_here
Show the endpoints

Keys are read-only and scoped to one blog, but anyone can read one out of your page source, and every request that reaches us counts against the blog owner's monthly allowance - a response served from the edge cache does not. When the allowance runs out the API answers 429 until the month resets or the plan is lifted, so keep keys server-side where you can.

GET /api/v1/posts?blog=slug

Every published post, newest first, each with an excerpt and pre-rendered contentHtml. Add page and per_page to paginate - meta then carries total and totalPages. Add fields=sitemap for slugs and dates only.

GET /api/v1/posts/[slug]?blog=slug

One post, plus view_count, headings for a table of contents, and relatedPosts. Posts from both endpoints carry author, seoTitle, seoDescription and seoNoindex. Reading does not count a view - it is cached at the edge, and a cached response never reaches us.

POST /api/v1/posts/[slug]/view?blog=slug

Records one read. Both SDK paths call it for you. Answers 202, never cached. The same reader reloading inside a short window counts once, and non-browser requests are not counted. Pass countViews={false} to render without counting.

The body carries document.referrer, which is where the Sources panel in Analytics comes from - the server cannot work it out, because this request is sent from your page. Only the site is stored, never the full address, and never your own domain. Pass referrer={false} to count the view without it.

GET /api/v1/blog?blog=slug

The blog's name and slug plus every SEO default. Field names match SeoSiteConfig exactly, so the response spreads straight into one.

GET /api/v1/templates?blog=slug

The published list and post designs, plus any custom fonts to load.