Read the posts
Everything this website knows about polis passes through one file. createPolis makes a reader for the
site. Give it fetch: polisFetch so every read is cached, and tagged so a webhook can refresh exactly what
changed:
// The one place this website meets polis.
//
// Everything below reads vdibart.polis.pub's own published files: its index,
// its signed markdown, its profile, its follow list. No API key, no account.
// polisFetch tags each read so the publish webhook (app/polis-webhook) can
// refresh exactly the pages a new post changes.
import { createPolis, type Post } from '@polis-pub/sdk';
import { polisFetch } from '@polis-pub/next';
export const SITE = process.env.POLIS_SITE ?? 'https://vdibart.polis.pub';
export const DISPLAY = process.env.POLIS_DISPLAY ?? 'https://vdibart.com';
export const SITE_HOST = new URL(SITE).host;
/** A post's address here, from its page on the polis site: /posts/<date>/<slug>, no .html. */
export function ourPath(polisPage: string): string | null {
const m = polisPage.match(/^https:\/\/[^/]+\/posts\/(\d{8})\/([^/?#]+?)(?:\.html)?(?:[?#].*)?$/);
return m ? `/posts/${m[1]}/${m[2]}` : null;
}
export const polis = createPolis({
site: SITE,
display: DISPLAY,
fetch: polisFetch,
hooks: {
// The posts carry their title as a leading "# Title" line; this design
// sets the title itself, so it comes off the body.
transformPost(post: Post) {
const lines = post.markdown.split('\n');
const first = lines.findIndex((l) => l.trim() !== '');
if (first >= 0 && lines[first].replace(/^#\s+/, '').trim() === post.title.trim() && lines[first].startsWith('# ')) {
post.markdown = lines.slice(first + 1).join('\n');
}
return post;
},
// A link to one of the site's own posts goes to that post HERE.
resolveLink(href: string) {
const abs = href.startsWith('/') ? SITE + href : href;
if (abs.startsWith(SITE + '/posts/')) return DISPLAY + (ourPath(abs) ?? '');
return abs;
},
},
});
/** The route params for a post, from its page on the polis site. */
export function paramsFor(polisPage: string): { date: string; slug: string } | null {
const p = ourPath(polisPage);
if (!p) return null;
const [, , date, slug] = p.split('/');
return { date, slug };
}
/** The polis site's page for route params (what comments point at). */
export const polisPage = (date: string, slug: string) => `${SITE}/posts/${date}/${slug}.html`;
/** Reading time, at 230 words a minute. */
export function readingTime(markdown: string): number {
return Math.max(1, Math.round(markdown.split(/\s+/).filter(Boolean).length / 230));
}
/** "2026-03-03T20:10:50Z" → "3 Mar 2026". */
export function formatDate(iso: string): string {
const d = new Date(iso);
if (Number.isNaN(d.getTime())) return '';
return d.toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', timeZone: 'UTC' });
}
/** The verification page for one of the site's files. */
export const validateURL = (source: string) => `https://validate.polis.pub/?url=${encodeURIComponent(source)}`;The two hooks in there are step 6's subject; skip them for now. The front page is then one call,
polis.getPosts(), which reads the site's index (content/pub.polis.core/index.jsonl) and returns its posts
newest first: title, date, the post's page on the polis site (url), and its signed source (source).
// The home page: the polis site's posts, newest first, grouped by year.
// One SDK call (getPosts) reads the site's published index.
import { polis, ourPath, formatDate, SITE, SITE_HOST } from '@/lib/polis';
export default async function Home() {
const [posts, profile] = await Promise.all([polis.getPosts(), polis.getProfile().catch(() => ({}) as Record<string, any>)]);
const years = new Map<string, typeof posts>();
for (const p of posts) {
const y = p.published.slice(0, 4) || '—';
years.set(y, [...(years.get(y) ?? []), p]);
}
// The name the site itself publishes (its profile, .well-known/polis).
const name = String(profile.author_name || SITE_HOST.split('.')[0]);
return (
<>
<section className="hero">
<div>
<span className="eyebrow">Writing · polis · the open web</span>
<h1>
{name}
<span className="soft">.com</span>
</h1>
<p>
Notes on building polis: a protocol for owning what you write and who you talk to. Every word here is
written and signed on my own polis site, then shown here, in a shape of my choosing.
</p>
</div>
<div className="circuit" aria-label="How this page is made">
<div><span className="k">source </span><span className="t">{SITE_HOST}</span></div>
<div><span className="k"> ├─ </span>signed markdown, an index, a profile</div>
<div><span className="k"> └─ </span><span className="w">webhook</span> on publish</div>
<div><span className="k">render </span><span className="t">vdibart.com</span></div>
<div><span className="k"> └─ </span>@polis-pub/sdk · Next.js · Vercel</div>
</div>
</section>
<div className="section-head">
<h2>Writing</h2>
<a className="eyebrow" href={SITE}>{posts.length} posts on {SITE_HOST} ↗</a>
</div>
{[...years].map(([year, list]) => (
<section className="year" key={year} aria-label={year}>
<div className="label">{year}</div>
<ul className="posts">
{list.map((p) => (
<li key={p.path}>
<a href={ourPath(p.url) ?? p.url}>
<span className="d">{formatDate(p.published)}</span>
<span className="t">{p.title}</span>
<span className="m">→</span>
</a>
</li>
))}
</ul>
</section>
))}
</>
);
}That's a working blog front page. It runs on the server, so the HTML arrives complete, crawlers see the writing, and the polis site is read once per change rather than once per visitor.