Site / Creating a site

Two nodes and a link

This builds a three-route tree (Home, People, and Person), creates a typed target for person 3, and inspects its URL, ancestor chain, title, and navigation section:

ts
import { Schema, pipe } from 'effect'
import { defineRouteUnion, int, literal, mapTo, root, slash } from 'foldkit/route'
import { Site } from 'foldkit-site'

const AppRoute = defineRouteUnion({
  Home: {},
  People: {},
  Person: { personId: Schema.Number },
})

const Home = Site.route(pipe(root, mapTo(AppRoute.Home)), AppRoute.Home, { title: () => 'Routing' })
const People = Site.route(pipe(literal('people'), mapTo(AppRoute.People)), AppRoute.People)
const Person = Site.route(
  pipe(literal('people'), slash(int('personId')), mapTo(AppRoute.Person)),
  AppRoute.Person,
  { title: ({ personId }) => `Person ${personId} | Routing`, section: 'People' },
)

const AppSite = Site.make(Home, Site.mount(People, [Person]))
const target = Site.target(Person, { personId: 3 })

Evaluating target and the tree helpers gives:

  • 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'

Site.route wraps an existing Foldkit Router (literal, slash, query, mapTo) and attaches hierarchy and metadata without re-parsing URLs. Site.make freezes the topology and rejects duplicate route tags or nodes mounted twice so chain inspection stays unambiguous. Every built URL parses back to its target's route, and navigation menus read sections, Site.landing hrefs, and Site.titleOf directly from the tree instead of parallel tables.