Skip to content

Instantly share code, notes, and snippets.

@ixv
Created June 5, 2018 17:18
Show Gist options
  • Save ixv/12b15c4cf5c87b0db74b112ccd26569c to your computer and use it in GitHub Desktop.
Save ixv/12b15c4cf5c87b0db74b112ccd26569c to your computer and use it in GitHub Desktop.
# Static Site Builder
We now have a static site builder. This takes a set of resource files, most likely udon or sail in hoon files and outputs html. Why might we do this, you ask, since Urbit already builds and serves files?
We wanted something that could be used to generate a site, without neccesarily requiring that it be served by an Urbit. This is essentially Urbit's answer to Jekyll.
To use it call
```
> :static|build %/path/to/top/level/input/file %/path/to/output/dir
```
This will take the top level file, which could be `html`, `md`, `umd`, or a `hoon` file containing sail, then crawl all the relative links, and build and write out the set of files linked as `html`. Linked `js` and `css` files will also be included.
As an example, say we have the following file tree:
```
%/web/site/index.hoon
%/web/site/posts/post1.umd
%/web/site/posts/post2.md
%/web/site/posts/post3.html
%/web/site/resources/script.js
%/web/site/resources/style.css
```
Where the above files form a connected graph, reachable from `index.hoon`,
Then calling:
```
> :static|build %/web/site/index %/web/output
```
Will produce:
```
%/web/output/index.html
%/web/output/posts/post1.html
%/web/output/posts/post2.html
%/web/output/posts/post3.html
%/web/output/resources/script.js
%/web/output/resources/style.css
```
This program currently exists as an app, so `|start %static` first. Though perhaps it makes more sense to be a generator, it may be rewritten in the near future.
### Ford includes
Here is a reminder/crash course on how to include one file as a component of another file.
The container file must be hoon, since no other file-type knows how to make sense of ford runes. The good news is you can write udon directly in a hoon file by prefixing the udon portion with `;>`. The contained file however may be anything that can be converted to a manx
At the top of the hoon file, write the following
```
/= include1 /: /===/path/to/hoon/file /!hymn/
/= include2 /: /===/path/to/html/file /&hymn&/html/
/= include3 /: /===/path/to/umd/file /&elem&/umd/
/= include4 /: /===/path/to/md/file /&elem&/md/
```
Those are the syntaxes for including hoon file that produces a manx, a raw html file, a umd file, and a md file respectively. If you want to know the details, check out [the ford rune docs](https://urbit.org/docs/arvo/internals/ford/runes/).
And then in the body of our hoon file, we can include those components like so:
```
;+ include1
;+ include2
;+ include3
;+ include4
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment