← Back to Skills

A brand blog at `/blog` in your own app

Posts are written, reviewed and approved in the marketing pipeline (iec-marketing). Your app only **reads published posts** and renders them at…

Commandplatform

About

Posts are written, reviewed and approved in the marketing pipeline (iec-marketing). Your app only **reads published posts** and renders them at `yourdomain.com/blog`. No auth, no key, no database.

Skill Content

This is the raw markdown that gets installed as a Claude Code command.

---
name: tawa-brand-blog
description: "Serving a brand blog at /blog inside your own Tawa app from the portal blog store. Use when adding or debugging a blog on a service."
---

# A brand blog at `/blog` in your own app

## The Short Version

Posts are written, reviewed and approved in the marketing pipeline (iec-marketing). Your app only
**reads published posts** and renders them at `yourdomain.com/blog`. No auth, no key, no database.

```
iec-marketing (write, counsel review, approve)
   └─ portal post store ── GET https://portal.insureco.io/api/blog/public/marketing?brand=<key>
                                └─ your app: /blog, /blog/<slug>, /blog/feed.xml, /sitemap.xml
```

1. A brand exists for the product (Marketing → Brands), with `project` set.
2. A platform admin sets the brand's blog target to **`external`** on your domain.
3. Add four routes and a small middleware to your app (below). Deploy.

Live examples: `policyblockchain.com/blog`, `binddesk.com/blog` (insureco/binddesk-www#19).

## Subfolder or subdomain?

| | `yourdomain.com/blog` (this page) | `blog.yourdomain.com` (HypeSite) |
|---|---|---|
| Search credit | All on your domain | Mostly on the blog subdomain |
| Work | Routes in your app, a deploy | None: iec-marketing builds the HypeSite |
| Blog target | `external` | `subdomain` |

A subdomain does not hurt the main site. It just helps it less. For a product site whose domain
should rank, use the subfolder.

## 1. Brand and blog target

The brand needs a `key` (`binddesk`) and a portal `project`. Set the target (platform admin; the
`PATCH` takes the person's own token):

```jsonc
// PATCH {IEC_MARKETING_URL}/api/orgs/<org>/brands/<key>
{ "blogTarget": { "mode": "external", "host": "binddesk.com" }, "blogTargetNote": null }
```

With `external`, the publisher builds no site. Approving a post marks it `published` with
`canonicalUrl: https://<host>/blog/<slug>`, and your app picks it up on its next read.

## 2. The public read

| Request | Returns |
|---|---|
| `?brand=<key>` | `{ posts: [...] }` without bodies: `slug, title, excerpt, publishedAt, updatedAt, canonicalUrl, image, tags, keywords, author` |
| `?brand=<key>&slug=<slug>` | `{ post }` with `body` (Markdown) and **`bodyHtml`** (rendered and sanitized). An unknown or unpublished slug is **404** |
| `&limit=1..200&cursor=…` | Paged, with `nextCursor` |
| `&fields=sitemap` | Only `slug, publishedAt, updatedAt, canonicalUrl, tags` |

Only `published` posts are ever returned. Render `bodyHtml` as is: it is sanitized before it is
stored. Some hosts refuse requests without a normal User-Agent; Node's `fetch` is fine.

## 3. The routes (Next.js App Router)

Copy from binddesk-www (`web/lib/blog.ts`, `web/app/blog/**`, `web/app/sitemap.ts`,
`web/app/robots.ts`, `web/middleware.ts`) and change the brand key and `SITE_URL`.

```ts
// lib/blog.ts
export const SITE_URL = 'https://binddesk.com'
const FEED_URL = (process.env.BLOG_FEED_URL || 'https://portal.insureco.io').replace(/\/$/, '')
const BRAND = 'binddesk'

async function getJson(query: string) {
  try {
    const res = await fetch(`${FEED_URL}/api/blog/public/marketing?${query}`, {
      next: { revalidate: 300 },              // 5-minute cache
      signal: AbortSignal.timeout(4000),
    })
    return res.ok ? await res.json() : null
  } catch {
    return null                               // fail open: the blog shows "coming soon"
  }
}
export const getPosts = async () => (await getJson(`brand=${BRAND}`))?.posts ?? []
export const getPost = async (slug: string) =>
  (await getJson(`brand=${BRAND}&slug=${encodeURIComponent(slug)}`))?.post ?? null
```

| Route | Must have |
|---|---|
| `app/blog/page.tsx` | List, newest first; an empty state; `alternates.canonical: '/blog'` and the RSS alternate |
| `app/blog/[slug]/page.tsx` | `notFound()` for a missing post; `alternates.canonical: '/blog/<slug>'`; Open Graph `article`; `BlogPosting` JSON-LD |
| `app/blog/feed.xml/route.ts` | RSS 2.0 with absolute links |
| `app/sitemap.ts` | Public pages plus every post (`lastModified` from `updatedAt` or `publishedAt`) |
| `app/robots.ts` | `Sitemap:` line; disallow `/api/` and the signed-in app areas |

Set `metadataBase: new URL(SITE_URL)` in the blog metadata (or the root layout). Without it a
relative canonical stays relative in the HTML.

## 4. Compliance checklist

Check each one on a built app (`next build`, then `node .next/standalone/server.js`) before you merge.

- [ ] **Canonical is absolute and on your domain**: `<link rel="canonical" href="https://yourdomain.com/blog/<slug>">`. It must match the post's `canonicalUrl`.
- [ ] **A missing post answers HTTP 404**, not a 200 "not found" page (a soft 404). See below.
- [ ] **`/sitemap.xml` lists the posts**, and `/robots.txt` points at it.
- [ ] **`BlogPosting` JSON-LD** with `headline`, `datePublished`, `mainEntityOfPage`. Escape `<` in the JSON (`.replace(/</g, '\\u003c')`).
- [ ] **No second copy indexed**: do not also mount the brand on a HypeSite with `feedBrands`. One brand, one place.
- [ ] **The read fails open**: feed down means an empty list, never a 500.
- [ ] **`/blog` is public**: no auth middleware or client-side auth redirect in front of it.
- [ ] **A Blog link** in the public navigation, so crawlers and people find it.
- [ ] **Analytics**: `<MatomoAnalytics />` already covers `/blog` if the app renders it ([Analytics](analytics.md)).

### Soft 404s on Next.js 14.0

Next.js **14.0.x** answers `notFound()` from a dynamic page with HTTP **200** (fixed in later 14.x).
Search engines read that as a soft 404. Check yours:

```bash
curl -s -o /dev/null -w "%{http_code}\n" https://yourdomain.com/blog/does-not-exist   # must be 404
```

If it says 200, either upgrade Next.js, or add a middleware that asks the feed and answers 404
itself (binddesk-www does this):

```ts
// middleware.ts
export async function middleware(req: NextRequest) {
  const m = /^\/blog\/([a-z0-9][a-z0-9-]{0,199})$/.exec(req.nextUrl.pathname)
  if (!m) return NextResponse.next()
  const ctl = new AbortController(); const t = setTimeout(() => ctl.abort(), 3000)
  try {
    const res = await fetch(`${FEED_URL}/api/blog/public/marketing?brand=${BRAND}&slug=${m[1]}`, { signal: ctl.signal })
    if (res.status === 404) return new NextResponse(NOT_FOUND_HTML, { status: 404, headers: { 'content-type': 'text/html; charset=utf-8' } })
    return NextResponse.next()
  } catch { return NextResponse.next() } finally { clearTimeout(t) }
}
export const config = { matcher: ['/blog/:path*'] }
```

Three traps in 14.0, all found the hard way:

- `matcher: ['/blog/:slug']` compiles to a pattern that never matches `/blog/<slug>`. Use `'/blog/:path*'` and test the path yourself.
- `AbortSignal.timeout` does not exist in the 14.0 edge runtime. Use an `AbortController`.
- `NextResponse.rewrite(url, { status: 404 })` to an app page still answers 200. Return a small self-contained HTML response.

## Common mistakes

- Pointing the blog target at `subdomain` and also building `/blog` in the app: two copies of every post.
- Hand-writing `NEXT_PUBLIC_*` for the feed URL. It is a public URL; read it server-side.
- Calling `notFound()` and assuming the status is 404. Curl it.
- Caching the feed longer than a few minutes: an approved post should appear within five.
- Leaving the old "Not set up yet" `blogTargetNote` on the brand after setting the target.

See also: [HypeSites](hypesites.md), [SEO](seo.md), [Next.js on Tawa](nextjs.md).

Install

Copy the skill content and save it to:

~/.claude/commands/tawa-brand-blog.md
Download .md

Coming soon via CLI:

tawa chaac install tawa-brand-blog

Details

Format
Command
Category
platform
Version
1.0.31896
Tokens
~1,874
Updated
2026-11-25
platformmarketingblogseonextjsiec-marketing