A blog post template, built only from library items: the way back, the title in Funnel Display, a wide image, the body in a 720px column (paragraphs, subheads, a list, a quote, a figure of creatives), more posts and the offer.
Install
React apps get the React files; every other stack gets the web component.
One post of a website's blog. The body is a list of blocks in lib/pages/blog-post.ts; pass content for each post.
Never
New colors, shadows or type sizes added to a section: use the items' props
More than one White button in a section
A body wider than 720px
sections lists the sections to show, in order (head, cover, body, related, offer); a key left out is not shown. The head, cover and body stay inside the article, where the first of them falls. The cover, the figures' images and the related posts' images are image slots (or the placeholder's brand, caption and tone). menus passes the header menus (the live card's picture, the use cases' shots).
The web component takes the same as attributes or properties (<spyglass-blog-post-page>); title is heading there.
<BlogPostPage>
Prop
Type
Default
content
BlogPostContent
menus
HeaderMenus
The header menus' content, pictures included (the live card's `picture`, the use cases' `shots`); Acme by default.
sections
readonly BlogPostSection[]
The sections to show, in order; all of them in the page order by default (leave one out to omit it).
className
string
Examples
The same example in React and as web components; both render identically.
react/examples/blog-post-page/Page.tsx
import { BlogPostPage } from '@/react/components/pages/BlogPostPage'
// The blog post page template with its own copy.
export default function Page() {
return <BlogPostPage />
}
elements/examples/blog-post-page/Page.html
<!-- The blog post page template with its own copy. -->
<spyglass-blog-post-page></spyglass-blog-post-page>
Source
react/components/pages/BlogPostPage.tsx
import { ChevronLeft } from 'lucide-react'
import { CreativeCard } from '@/react/components/site/CreativeCard'
import { CreativeGrid } from '@/react/components/site/CreativeGrid'
import { FooterRow } from '@/react/components/site/FooterRow'
import { SiteHeader } from '@/react/components/site/SiteHeader'
import { OfferBlock } from '@/react/components/blocks/OfferBlock'
import { blogPostContent, type BlogPostBlock, type BlogPostContent, blogPostSections, type BlogPostSection } from '@/lib/pages/blog-post'
import { cn } from '@/react/lib/cn'
import { pageSections, groupSections } from '@/lib/image'
import { Fragment, type ReactNode } from 'react'
import type { HeaderMenus } from '@/lib/site-header'
// A blog post from library items: the way back, the date and category in capitals, the title in Funnel Display, the
// byline, a wide image, then the body in a 720px column (DM Sans paragraphs, Funnel Display subheads, a list, a quote
// set off by a hairline, a figure of creatives), more posts and the offer. `content` replaces the post
// (lib/pages/blog-post.ts); its `body` is a list of blocks.
export interface BlogPostPageProps {
content?: BlogPostContent
/** The header menus' content, pictures included (the live card's `picture`, the use cases' `shots`); Acme by default. */
menus?: HeaderMenus
/** The sections to show, in order; all of them in the page order by default (leave one out to omit it). */
sections?: readonly BlogPostSection[]
className?: string
}
const WRAP = 'mx-auto w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] px-(--ds-layout-gutter)'
const COLUMN = 'mx-auto w-full max-w-180 px-12 max-sm:px-4'
const ARTICLE: readonly BlogPostSection[] = ['head', 'cover', 'body']
const TITLE = 'rounded-control transition-[color] duration-160 ease-standard hover:text-fg-soft'
function Block({ block: b }: { block: BlogPostBlock }) {
if (b.kind === 'h2') return <h2 className="mt-6 type-heading-2 text-fg">{b.text}</h2>
if (b.kind === 'quote') return <blockquote className="m-0 border-l-2 border-edge-strong pl-6 type-heading-3 text-fg">{b.text}</blockquote>
if (b.kind === 'list') return <ul className="grid list-disc gap-2 pl-5 type-body-lg text-fg-soft marker:text-fg-faint">{b.items.map((i) => <li key={i}>{i}</li>)}</ul>
if (b.kind === 'figure') return (
<figure className="m-0 my-4 grid gap-3">
<CreativeGrid items={b.images} ratio="3/4" />
<figcaption className="type-caption text-fg-muted">{b.caption}</figcaption>
</figure>
)
return <p className="type-body-lg text-fg-soft">{b.text}</p>
}
export function BlogPostPage({ content: c = blogPostContent, menus, sections, className }: BlogPostPageProps) {
const parts: Record<BlogPostSection, ReactNode> = {
head: (
<header className={cn(COLUMN, 'flex flex-col items-start pt-16 max-sm:pt-10')}>
<a href={c.back.href} className="inline-flex items-center gap-1.5 rounded-control type-ui text-fg-muted transition-[color] duration-160 ease-standard hover:text-fg">
<ChevronLeft size={16} strokeWidth={1.5} aria-hidden="true" />
{c.back.label}
</a>
<p className="mt-8 type-label text-fg-muted">{`${c.date} · ${c.category}`}</p>
<h1 className="mt-4 type-hero text-balance max-sm:type-heading-1">{c.title}</h1>
<p className="mt-6 type-ui text-fg-muted">{c.byline}</p>
</header>
),
cover: (
<div className={cn(WRAP, 'mt-12 max-sm:mt-8')}>
<CreativeCard {...c.image} alt={c.image.alt ?? c.title} ratio="16/9" className="mx-auto max-w-page" />
</div>
),
body: (
<div className={cn(COLUMN, 'grid gap-6 py-12 max-sm:py-8')}>
{c.body.map((b, i) => <Block key={i} block={b} />)}
</div>
),
related: (
<section className={cn(WRAP, 'grid gap-10 py-24 max-sm:gap-8 max-sm:py-16')}>
<h2 className="type-section">{c.related.title}</h2>
<div className="grid grid-cols-3 gap-6 max-md:grid-cols-1">
{c.related.posts.map((p) => (
<article key={p.href} className="grid content-start gap-4">
<CreativeCard {...p.image} alt={p.image.alt ?? p.title} ratio="7/5" />
<p className="type-label text-fg-muted">{p.date}</p>
<h3 className="type-heading-3 text-balance"><a href={p.href} className={TITLE}>{p.title}</a></h3>
</article>
))}
</div>
</section>
),
offer: <OfferBlock headline={c.offer.headline} note={c.offer.note} cta={c.offer.cta} seed={2} />,
}
return (
<div data-ds="blog-post-page" className={cn('bg-surface text-fg', className)}>
<SiteHeader menus={menus} links={c.header.nav} secondary={c.header.secondary} cta={c.header.cta} />
<main>
{groupSections(pageSections(blogPostSections, sections), ARTICLE).map((k) => (Array.isArray(k) ? <article key="article">{k.map((a) => <Fragment key={a}>{parts[a]}</Fragment>)}</article> : <Fragment key={k}>{parts[k]}</Fragment>))}
</main>
<footer className="border-t border-edge">
<div className={cn(WRAP, 'py-10')}>
<FooterRow domain={c.footer.domain} homeHref="/" links={c.footer.links} />
</div>
</footer>
</div>
)
}
export default BlogPostPage
lib/pages/blog-post.ts
// The blog post template's copy: a neutral example post by the team, with Acme placeholders. Both flavors read this file.
import type { CreativeImage } from '@/lib/image'
/** An Acme placeholder creative: the advertiser, a neutral tone (1 to 4) and a headline. */
const creative = (brand: string, tone: 1 | 2 | 3 | 4, caption?: string): CreativeImage => (caption ? { brand, tone, caption } : { brand, tone })
const nav = [
{ label: 'Product', href: '/product' },
{ label: 'Pricing', href: '/pricing' },
{ label: 'Changelog', href: '/changelog' },
{ label: 'Blog', href: '/blog' },
]
const footer = {
domain: 'spyglass.so',
links: [
{ label: 'Product', href: '/product' },
{ label: 'Pricing', href: '/pricing' },
{ label: 'About', href: '/about' },
{ label: 'Changelog', href: '/changelog' },
{ label: 'Blog', href: '/blog' },
{ label: 'Terms', href: '/legal' },
],
}
const header = { nav, secondary: { label: 'Sign in', href: '/sign-in' }, cta: { label: 'Get 50% off', href: '/pricing' } }
// A block of the post's body. Written out in place (no type alias), so the web component's generated types stand alone.
const body: ({ kind: 'p' | 'h2' | 'quote'; text: string } | { kind: 'list'; items: string[] } | { kind: 'figure'; caption: string; images: CreativeImage[] })[] = [
{ kind: 'p', text: 'A brand’s best ad tells you what worked once. A week of its ads tells you what it believes. Start with the week.' },
{ kind: 'h2', text: 'Count formats first.' },
{ kind: 'p', text: 'Sort the week by format before you look at a single hook. UGC, studio, static, carousel. The split is the strategy.' },
{ kind: 'list', items: ['Pull seven days of ads for one brand.', 'Tag each one by format.', 'Note which formats got new versions.'] },
{ kind: 'figure', caption: 'Three of Acme Skin’s ads from one week, side by side.', images: [creative('Acme Skin', 3, 'Glow in two steps.'), creative('Acme Skin', 2, 'The travel kit.'), creative('Acme Skin', 4, 'Night repair.')] },
{ kind: 'h2', text: 'Then read the hooks.' },
{ kind: 'p', text: 'Hooks repeat inside a format. When a brand ships the same opening three times, it is working.' },
{ kind: 'quote', text: 'The split is the strategy. The hook is the tactic.' },
{ kind: 'p', text: 'Write down what changed since last week. That list is your brief.' },
]
export const blogPostContent = {
header: { ...header, nav: nav.map((l) => (l.href === '/blog' ? { ...l, current: true } : l)) },
back: { label: 'Blog', href: '/blog' },
date: 'Nov 12, 2026',
category: 'Research',
title: 'How to read a competitor’s creative mix.',
byline: 'By the Spyglass team',
image: creative('Acme Skin', 3),
body,
related: {
title: 'More from the blog.',
posts: [
{ href: '/blog/skincare-hooks', title: 'Five hooks that keep working in skincare ads.', date: 'Nov 5, 2026', image: creative('Acme Skin', 2) },
{ href: '/blog/swipe-files', title: 'A swipe file your team will use.', date: 'Oct 29, 2026', image: creative('Acme Studio', 4) },
{ href: '/blog/launch-week', title: 'What a launch week looks like in the index.', date: 'Oct 22, 2026', image: creative('Acme Drinks', 1) },
],
},
offer: { headline: 'Stop screenshotting at midnight.', note: '$10 for your first month, then $20/month', cta: { label: 'Start Creator for 50% off', href: '/pricing' } },
footer,
}
export type BlogPostContent = typeof blogPostContent
export type BlogPostBlock = (typeof body)[number]
/** The blog post's sections in order (head, cover and body stay inside the article, where the first of them falls); pass `sections` to reorder them or leave some out. */
export const blogPostSections = ['head', 'cover', 'body', 'related', 'offer'] as const
export type BlogPostSection = (typeof blogPostSections)[number]
react/lib/cn.ts
// Joins class names, skipping falsy ones: cn('a', on && 'b', ['c', undefined]). It does not merge conflicting
// utilities (no tailwind-merge), as Vue's class binding does not: the library's classes are written not to compete,
// and a className from the caller is appended after them, as Vue appends a fallthrough class.
export type ClassValue = string | false | null | undefined | 0 | ClassValue[]
export function cn(...values: ClassValue[]): string {
const out: string[] = []
for (const v of values) {
if (!v) continue
if (Array.isArray(v)) {
const s = cn(...v)
if (s) out.push(s)
}
else out.push(v)
}
return out.join(' ')
}
elements/components/pages/blog-post-page.ts
import { html, nothing } from 'lit'
import { ifDefined } from 'lit/directives/if-defined.js'
import { ChevronLeft } from 'lucide'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import { icon } from '@/elements/lib/icon'
import { blogPostContent, type BlogPostBlock, type BlogPostContent, blogPostSections, type BlogPostSection } from '@/lib/pages/blog-post'
import '@/elements/components/site/creative-card'
import '@/elements/components/site/creative-grid'
import '@/elements/components/site/footer-row'
import '@/elements/components/site/site-header'
import '@/elements/components/blocks/offer-block'
import styles from 'virtual:tw'
import { pageSections, groupSections } from '@/lib/image'
import { headerMenus, type HeaderMenus } from '@/lib/site-header'
// BlogPostPage.tsx as <spyglass-blog-post-page>: the way back, the title, a wide image, the body in a 720px column,
// more posts and the offer. `content` replaces the post; its `body` is a list of blocks.
const WRAP = 'mx-auto w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] px-(--ds-layout-gutter)'
const COLUMN = 'mx-auto w-full max-w-180 px-12 max-sm:px-4'
const ARTICLE: readonly BlogPostSection[] = ['head', 'cover', 'body']
const TITLE = 'rounded-control transition-[color] duration-160 ease-standard hover:text-fg-soft'
const block = (b: BlogPostBlock) => {
if (b.kind === 'h2') return html`<h2 class="mt-6 type-heading-2 text-fg">${b.text}</h2>`
if (b.kind === 'quote') return html`<blockquote class="m-0 border-l-2 border-edge-strong pl-6 type-heading-3 text-fg">${b.text}</blockquote>`
if (b.kind === 'list') return html`<ul class="grid list-disc gap-2 pl-5 type-body-lg text-fg-soft marker:text-fg-faint">${b.items.map((i) => html`<li>${i}</li>`)}</ul>`
if (b.kind === 'figure') return html`<figure class="m-0 my-4 grid gap-3"><spyglass-creative-grid .items=${b.images} ratio="3/4"></spyglass-creative-grid><figcaption class="type-caption text-fg-muted">${b.caption}</figcaption></figure>`
return html`<p class="type-body-lg text-fg-soft">${b.text}</p>`
}
/**
* @summary The blog post template.
*/
export class BlogPostPage extends DsElement {
static styles = [DsElement.styles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="blog-post-page"]'))
static properties = { content: { type: Object }, menus: { type: Object }, sections: { type: Array } }
/** The post (lib/pages/blog-post.ts by default). */
content: BlogPostContent = blogPostContent
/** The header menus' content, pictures included (the live card's `picture`, the use cases' `shots`); Acme by default. */
menus?: HeaderMenus
/** The sections to show, in order (a list of names); all of them in the page order by default. */
sections?: BlogPostSection[]
render() {
const c = this.content ?? blogPostContent
const parts: Record<BlogPostSection, unknown> = {
head: html`<header class=${`${COLUMN} flex flex-col items-start pt-16 max-sm:pt-10`}><a href=${c.back.href} class="inline-flex items-center gap-1.5 rounded-control type-ui text-fg-muted transition-[color] duration-160 ease-standard hover:text-fg">${icon(ChevronLeft, 'chevron-left', { size: 16, strokeWidth: 1.5, attrs: { 'aria-hidden': 'true' } })}${c.back.label}</a><p class="mt-8 type-label text-fg-muted">${`${c.date} · ${c.category}`}</p><h1 class="mt-4 type-hero text-balance max-sm:type-heading-1">${c.title}</h1><p class="mt-6 type-ui text-fg-muted">${c.byline}</p></header>`,
cover: html`<div class=${`${WRAP} mt-12 max-sm:mt-8`}><spyglass-creative-card src=${ifDefined(c.image.src)} fit=${ifDefined(c.image.fit)} position=${ifDefined(c.image.position)} brand=${ifDefined(c.image.brand)} caption=${ifDefined(c.image.caption)} tone=${ifDefined(c.image.tone)} alt=${c.image.alt ?? c.title} ratio="16/9" class="mx-auto max-w-page"></spyglass-creative-card></div>`,
body: html`<div class=${`${COLUMN} grid gap-6 py-12 max-sm:py-8`}>${c.body.map(block)}</div>`,
related: html`<section class=${`${WRAP} grid gap-10 py-24 max-sm:gap-8 max-sm:py-16`}><h2 class="type-section">${c.related.title}</h2><div class="grid grid-cols-3 gap-6 max-md:grid-cols-1">${c.related.posts.map((p) => html`<article class="grid content-start gap-4"><spyglass-creative-card src=${ifDefined(p.image.src)} fit=${ifDefined(p.image.fit)} position=${ifDefined(p.image.position)} brand=${ifDefined(p.image.brand)} caption=${ifDefined(p.image.caption)} tone=${ifDefined(p.image.tone)} alt=${p.image.alt ?? p.title} ratio="7/5"></spyglass-creative-card><p class="type-label text-fg-muted">${p.date}</p><h3 class="type-heading-3 text-balance"><a href=${p.href} class=${TITLE}>${p.title}</a></h3></article>`)}</div></section>`,
offer: html`<spyglass-offer-block headline=${c.offer.headline} note=${c.offer.note} .cta=${c.offer.cta} seed="2"></spyglass-offer-block>`,
}
return html`<div data-ds="blog-post-page" class="bg-surface text-fg">
<spyglass-site-header .menus=${this.menus ?? headerMenus} .links=${c.header.nav} .secondary=${c.header.secondary} .cta=${c.header.cta}></spyglass-site-header>
<main>${groupSections(pageSections(blogPostSections, this.sections), ARTICLE).map((k) => (Array.isArray(k) ? html`<article>${k.map((a) => parts[a])}</article>` : parts[k]))}</main>
<footer class="border-t border-edge"><div class=${`${WRAP} py-10`}><spyglass-footer-row domain=${c.footer.domain} home-href="/" .links=${c.footer.links}></spyglass-footer-row></div></footer>
</div>`
}
}
define('blog-post-page', BlogPostPage)
Reference: Built from the library (site header, creative card, creative grid, offer block, footer row) and the brand's type.