Sites
@peleda-app/site turns React pages into a static site: each page is prerendered to HTML at build time and hydrated in the browser. peleda.dev, ui.peleda.dev and favicons.peleda.dev are built with it.
Define the site
// src/site.tsx
import type { SiteDefinition } from '@peleda-app/site'
import { identity } from '@peleda-app/tokens/identities'
import { HomePage } from './pages/home.tsx'
const id = identity('ui')
export const site: SiteDefinition = {
origin: id.url,
name: id.name,
pages: [{ path: '/', title: id.name, description: id.tagline, render: () => <HomePage /> }],
}A page has a path, title, description, an optional image for link previews and a render function. The site has an origin, a name, an optional lang (default en) and optional extra sitemaps.
// src/client.tsx
import './styles.css'
import { mountSite } from '@peleda-app/site/client'
import { site } from './site.tsx'
mountSite(site)mountSite finds the page for location.pathname (falling back to /) and hydrates #app when it already holds prerendered HTML, or renders into it otherwise.
index.html holds two markers, <!--site-head--> in <head> and <!--site-html--> inside <div id="app">, and the Vite config comes from siteVite({ port }) in @peleda-app/site/vite: React, Tailwind 4, deduplicated React, Radix, Motion and Lucide, and @peleda-app/* bundled for server rendering.
Build
// scripts/build.ts
import { buildSite } from '@peleda-app/site/build'
await buildSite({
root: new URL('..', import.meta.url).pathname,
docs: 'docs',
copy: [{ from: '../../storybook-static', to: 'storybook' }],
})buildSite runs, in order:
- clears
distand runs the optionalbeforehook; - builds the client with Vite;
- builds
src/site.tsxfor the server and imports it; - renders every page with
prerenderfromreact-dom/staticand writes it into the builtindex.htmlwith the page's title, description, canonical URL, Open Graph and Twitter tags andlang; - writes
sitemap.xmlandrobots.txt; - builds the VitePress docs when
docsis set; - copies each
copyentry intodist.
Pages render twice, on the server and in the browser, so they must render the same output on both: no window, document, localStorage, Date.now() or Math.random() during render. Read the URL or fetch data in effects.
Docs from another repository
syncDocs from @peleda-app/site/docs copies Markdown files from a project's repository into the site's docs folder before the build. Each page gets a slug and an optional title; links between synced pages are rewritten to the new slugs, links to listed asset folders stay relative, and every other relative link points at the file on GitHub. The content is wrapped in v-pre, so Vue syntax in the source is left alone.
import { syncDocs } from '@peleda-app/site/docs'
await syncDocs({
from: '../favicons/docs',
to: 'docs',
source: {
repo: 'peleda-app/favicons',
dir: 'docs',
pages: [{ file: 'API.md', slug: 'api', title: 'HTTP API' }],
assets: ['brand'],
},
})favicons.peleda.dev passes a function like this as before to buildSite, so its docs are always built from the current repository.