Site / Creating a site

60 seconds: two nodes and a link

ts
import { Site } from 'foldkit-site'

const Home = Site.route(homeRouter, AppRoute.Home, { title: () => 'Routing' })
const Person = Site.route(personRouter, AppRoute.Person, {
  title: ({ personId }) => `Person ${personId} | Routing`,
  section: 'People',
})

const AppSite = Site.make(Home, Site.mount(People, [Person]))

Site.route takes an existing full Foldkit Router — literal, slash, query, mapTo, all of it — and the route case it builds. The router stays the whole URL story; the Site adds hierarchy, metadata, and inspection without re-parsing anything. Site.make freezes the topology and refuses two nodes sharing a tag or one node mounted twice, since both would make chain inspection ambiguous.

One declaration builds the value and the address together, so a link can never point where the parser would not go:

ts
const target = Site.target(Person, { personId: 3 })
target.route // AppRoute.Person({ personId: 3 })
target.url // '/people/3'

Site.chainOf(AppSite, target.route) // [People, Person]
Site.titleOf(AppSite, target.route) // 'Person 3 | Routing'
Site.sectionOf(AppSite, target.route) // 'People'

A built URL parses back to the target's route (there is a test proving the round trip). Navigation renders from the tree instead of keeping parallel tables: sections in tree order, hrefs from Site.landing, titles from Site.titleOf, the current section by comparing tags.