Website structure

Start with a project directory, one entry for each page and a small shared package for code used across pages. Moth's source tree determines which modules may depend on each other and which entries produce output.

These examples use the final language design. The progress matrix records current implementation support.

Choose the explanation level: A multi-page website

A multi-page website

A larger Moth website is a tree of pages and shared code. Each page has an @entry.moth file. Reusable navigation and layout helpers live in a scoped support package.

One site, several pages

moth-site/
  @config.moth
  @entry.moth
  components/
    @package.moth
    navigation.moth
    sidebar.moth
    sidebar.css
  docs/
    @entry.moth
    functions/
      @entry.moth
      introduction.mtf

Each directory containing @entry.moth produces a page. The HTML builder derives the route from the directory, so docs/functions/@entry.moth produces docs/functions/index.html.

@config.moth holds optional build settings. It never becomes a page or joins the module graph.

The components/ directory holds an @package.moth root, which makes @components a scoped support package. Pages import its exported declarations without copying source or running the package as a page.

A page that composes content

-- docs/functions/@entry.moth

@components navbar, sidebar
@introduction content as introduction

[$in title:Functions]
[$in description:Functions, parameters and returns.]

[navbar]
[sidebar]

[$md:
    # Functions

    Functions declare their parameters and results.
]

[introduction]

The page mixes authored Markdown with imported templates. A .mtf asset supplies a compile-time content String, so a longer chapter can stay in introduction.mtf instead of making the entry file unwieldy.

Direct entry templates fold at compile time. A direct ~[...] fragment asks for runtime evaluation instead. A template stored in a binding stays an ordinary String value, and it becomes page output only when something inserts it.

Publish a small helper surface

The support package facade exposes only what pages should use:

-- components/@package.moth

$export
@navigation navbar

$export
@sidebar sidebar

Each $export publishes one declaration or one selected re-export. Private helpers stay inside the package.

Where shared code goes

Templates and constants used by several pages belong in the support package. Functions that only the package calls belong in ordinary .moth files beside it.

@mod.moth publishes a normal API to the parent module, while @package.moth publishes a scoped support API. Both facades use $export, and neither can expose entry work.

Start with this shape. Add a module only when it marks a real visibility or ownership boundary, not for every template or stylesheet.

The important division is between source ownership and entry activation. A root file selects a role. Importing a public declaration never runs an imported module's entry.

Who owns each piece?

  • @config.moth supplies optional project and builder settings. It never joins the module graph.
  • @entry.moth owns one selected page's direct fragments, builder slots and runtime start. It publishes no API.
  • @package.moth publishes a scoped support surface to eligible sibling branches and their descendants.
  • @mod.moth publishes a normal module surface to its parent.
  • Ordinary .moth files hold shared implementation inside their module. They stay private by default.
  • .mtf files produce compile-time String content. They never read the entry's private bindings.

A directory can have any subset of the three root files. Each root keeps its own declaration scope even when the files share one structural module. $export belongs to the two facade roles and cannot expose entry work.

Compilation is not activation

A build compiles the modules it needs. Only the chosen page's entry runs.

build selects entries
  -> compile each module once
  -> bind public declarations
  -> activate the selected page entry

Checking a project, importing a package or reading a facade exposes declarations. None of those steps start page work.

Keep module dependencies deliberate

The example's @components support package is visible to the site root, the docs branch and its child pages because of where it sits. It stays a scoped package, not a global import. Another support package at the same level cannot import it merely because the two sit side by side.

A dependency clause selects names, not a runnable file. Organise components behind a facade when several pages need the same public surface. Keep private markup helpers close to the package's implementation. Move a declaration into a child module when that module has its own meaningful public API.

Do not use an old +*.moth root or invent page names such as @functions.moth. Only @mod.moth, @package.moth and @entry.moth establish root roles.

Why the entry stays simple

Direct top-level [...] fragments must fold at compilation. The compiler keeps their source order and the builder assembles them into the final document, so startup never builds static content.

A direct ~[...] fragment opts into runtime output. The page's entry runs once when selected. The builder publishes runtime fragments only after a successful start, so a failed start cannot publish half of that invocation. Earlier static fragments remain.

Use #= when a folded template needs a name, a field or an importable value. That binding stays data: declaring it emits no page.

HTML belongs to the builder

The HTML builder owns directory routes, metadata destinations, resource output and URL rendering. Only a direct entry-root [$in title:...] or another registered builder contribution reaches it. An ordinary nested $in targets its immediate template receiver.

Resources stay structural Strings until the consuming output has a URL context. A shared component can carry a stylesheet reference without guessing the URL for each page. Reusing one resource origin across several pages does not duplicate the file.

See Project structure, Packages and Constants for the precise source and builder contracts.