website/README.md

109 lines
3.2 KiB
Markdown
Raw Permalink Normal View History

2020-09-22 20:59:56 -04:00
# hakyll-nix-template
2020-09-21 22:03:52 -04:00
2021-06-13 00:02:29 -04:00
[Hakyll](https://jaspervdj.be/hakyll/) + [Nix](https://nixos.org) template
2020-11-01 21:50:24 -05:00
2023-02-22 13:53:13 +13:00
## Quick tips
* Read the tutorial to get started! https://robertwpearce.com/the-hakyll-nix-template-tutorial.html
* If you make changes to anything inside of `ssg/`, you'll need to clean the
hakyll cache and rebuild. This is the preferred series of commands for
rebuilding (with logs), cleaning the cache, and re-running the dev server:
```default
nix build --print-build-logs && \
nix run . clean && \
nix run . watch
```
## Features
2020-11-01 21:50:24 -05:00
2021-06-13 00:02:29 -04:00
* Build your site into the `./result/dist` folder:
```
2021-06-13 00:02:29 -04:00
λ nix build
```
* Start hakyll's dev server that reloads when changes are made:
```
2021-06-13 00:02:29 -04:00
λ nix run . watch
Listening on http://127.0.0.1:8000
...more logs
```
* Run any hakyll command through `nix run .`!
```
2021-06-13 00:02:29 -04:00
λ nix run . clean
Removing dist...
Removing ssg/_cache...
Removing ssg/_tmp...
```
* Start a development environment that
* has your shell environment
* has `hakyll-site` (for building/watching/cleaning hakyll projects)
* has `hakyll-init` (for generating new projects)
* can have anything else you put in the `shell.buildInputs` of the
`hakyllProject` in `flake.nix`
2021-06-13 00:02:29 -04:00
* is set up to run `ghci` with some defaults and the modules loaded so you can
make your own changes and test them out in the ghci REPL
```
2021-06-13 00:02:29 -04:00
λ nix develop
2023-01-28 20:36:30 +13:00
[hakyll-nix]λ hakyll-site build
2021-06-13 00:02:29 -04:00
...
Success
2023-01-28 20:36:30 +13:00
[hakyll-nix]λ ghci
2021-06-13 00:02:29 -04:00
...
2021-09-25 23:56:13 +00:00
[1 of 1] Compiling Main ( ssg/src/Main.hs, interpreted )
2021-06-13 00:02:29 -04:00
...
2023-01-28 18:35:18 +13:00
2021-09-25 23:57:40 +00:00
λ >
2021-06-13 00:02:29 -04:00
```
### hakyll
All of this is custmomizable, and here are some things that are already done for
you:
* [pandoc](https://github.com/jgm/pandoc/) markdown customization to make it as
close to GitHub's markdown style as possible
2021-09-25 23:56:13 +00:00
* [`slugger`](https://hackage.haskell.org/package/slugger) module is included that makes nice link URIs based on post titles
2021-06-13 00:02:29 -04:00
* RSS & Atom XML feed generation
* Sitemap generation
* Code syntax highlighting customization
* ...other reasonable defaults
Configure the dev server, cache & tmp directories, and more in
`./ssg/src/Main.hs`.
### Deployment
Deployment is set up through a [GitHub
Action](https://github.com/features/actions) with [cachix](https://cachix.org),
and it deploys to a [GitHub Pages](https://pages.github.com/) branch,
`gh-pages`, when you merge code into your main branch.
Setup information can be found below in the "Cachix" section.
Note: If your main branch's name isn't `main`, ensure `'refs/heads/main'` gets
updated to `'refs/heads/my-main-branch'` in `./github/workflows/main.yml`.
## Setup
### Nix & Flakes
2021-06-13 00:02:29 -04:00
2023-01-28 18:35:18 +13:00
If you don't have [nix](https://nixos.org), follow [the nix installation
instructions](https://nixos.org/download.html).
2021-06-13 00:02:29 -04:00
Once you have nix installed, follow the instructions here to get access to
flakes: https://nixos.wiki/wiki/Flakes.
### Cachix
The `./.github/workflows/main.yml` file builds with help from
2023-01-28 18:35:18 +13:00
[cachix](https://app.cachix.org), so you'll need to generate a signing key to be
able to do this.
2021-06-13 00:02:29 -04:00
1. Create a cache on cachix for your project
1. Follow cachix's instructions to generate a signing keypair
1. Copy the signing keypair value to a new `CACHIX_SIGNING_KEY` secret on
https://github.com/settings/secrets