Site layout
A site is a directory with a config file, a source directory and an optional
public/ directory:
Gemfile
klenod.config.rb
public/ copied as it is
src/
site.rb site metadata
posts.rb a module that pages import
components/ Haml components
routes/
+layout.haml the HTML document
+page.haml /
+not-found.haml 404.html
blog/+page.haml /blog
blog/_posts/*.md Markdown posts
blog/[slug]/+page.haml /blog/:slug
feed.xml/+route.rb /feed.xml
Only klenod.config.rb and src/routes/ have fixed names. The rest is a
convention this site follows.
Route files
Routing follows Klenod’s router. Inside src/routes/, a file whose name starts
with + has a role:
| File | Role |
|---|---|
+page.haml, +page.rb or +page.md | the page at this directory’s path |
+layout.haml | wraps every page in this directory and below |
+not-found.haml | the 404 page for this directory and below |
+route.rb | a handler whose return value is written as a file |
A directory named in brackets, such as [slug], is a param. See
Dynamic routes.
Any other file in src/routes/ is an ordinary module. This site keeps
Markdown files in _posts and _pages directories next to the routes that
render them. A file there must not start with +.
What the build writes
| Source | Output |
|---|---|
routes/+page.haml | index.html |
routes/blog/+page.haml | blog/index.html |
routes/feed.xml/+route.rb | feed.xml |
routes/+not-found.haml | 404.html |
| imported CSS, scripts, images, fonts | assets/<name>.<hash>.<ext> |
public/robots.txt | robots.txt |
Each page is a directory with an index.html, and links to it have no
trailing slash: /blog, not /blog/. That works on plain file hosts, and
the generated nginx config follows the same rule.
Imports
A module imports another with import, and several with import_glob:
Site = import("/site") # src/site.rb
Card = import("./Card.haml") # next to this file
Posts = import_glob("./_posts/*.md").values # every match
A path that starts with / is relative to the source directory. A Ruby module
exports the constant named Default.