Skip to content

Commit bfb4a3b

Browse files
ulysses4everCopilot
andcommitted
Replace generate.sh with Hakyll static site generator
Co-authored-by: ulysses4ever <6832600+ulysses4ever@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 1a7f5fa commit bfb4a3b

28 files changed

+377
-162
lines changed

.github/workflows/deploy-pages.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: Deploy GitHub Pages
1+
name: Build and Deploy
22

33
on:
44
push:
55
branches:
6-
- main
6+
- '**' # Build on all branches
77
workflow_dispatch:
88

99
jobs:
@@ -12,17 +12,24 @@ jobs:
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v5
15-
- name: Install pandoc
15+
16+
- name: Install Nix
17+
uses: cachix/install-nix-action@v24
18+
with:
19+
nix_path: nixpkgs=channel:nixos-unstable
20+
21+
- name: Build site with Nix
1622
run: |
17-
sudo apt install pandoc
18-
- name: Generate HTML from Markdown
19-
run: make
23+
make nix-site
24+
2025
- name: Upload artifact
26+
if: github.ref == 'refs/heads/main'
2127
uses: actions/upload-pages-artifact@v4
2228
with:
23-
path: static/
29+
path: _site/
2430

2531
deploy:
32+
if: github.ref == 'refs/heads/main'
2633
environment:
2734
name: github-pages
2835
url: ${{steps.deployment.outputs.page_url}}

.gitignore

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
static/*.html
2-
!static/index.html
3-
41
.DS_Store
2+
3+
# Hakyll
4+
_site/
5+
_cache/
6+
_tmp/
7+
dist-newstyle/
8+
site
9+
10+
# Nix
11+
result

Makefile

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
##
2-
# Build LYAH web site from Markdown sources using Pandoc and sed
2+
# Build LYAH web site from Markdown sources using Hakyll.
3+
# Requires GHC and Cabal (for cabal-based builds) or Nix (for nix-based builds).
34
#
45

56
all: site
7+
./site build
68

7-
site:
8-
cd markdown && ./generate.sh
9+
site: site.hs lyah-site.cabal
10+
cabal build
11+
cp $$(cabal list-bin site) ./site
912

1013
clean:
11-
find ./docs -name '*.html' -not -name 'index.html' -delete
14+
rm -rf _site _cache _tmp
15+
cabal clean
16+
rm -f site
17+
18+
rebuild: clean site
19+
./site rebuild
20+
21+
watch: site
22+
./site watch
23+
24+
# Nix-based build rules
25+
nix-build:
26+
nix-build
27+
28+
nix-site: nix-build
29+
result/bin/site build
30+
31+
nix-clean:
32+
rm -rf result _site _cache _tmp
1233

1334
# end

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,70 @@ Discuss the ideas with the community.
3838
* Reddit - https://www.reddit.com/r/haskell/comments/sogi3s/learn_you_a_haskell_a_community_version/
3939
* Haskell Discourse - https://discourse.haskell.org/t/learn-you-a-haskell-a-community-version/4056
4040

41+
## Contributing
42+
43+
We are happy to get your contributions!
44+
For the most part, you can simply edit Markdown files and open a PR with the edits.
45+
If you want to preview the changes locally, you need to build the site as discussed below.
46+
47+
### Building the site
48+
49+
The site is built using [Hakyll](https://jaspervdj.be/hakyll/), a static site generator in the form of a Haskell library.
50+
With Hakyll, you first build a Haskell application `site`, and then run it to generate HTML for the website.
51+
You can build the application in two ways common for Haskell software: with `cabal` (standard, slow first build) or `nix` (advanced, fast first build).
52+
Both of them rely on the same Haskell package description (the `.cabal` file), so they should produce the same result.
53+
54+
#### Option 1: Using Cabal
55+
56+
You will need the Haskell toolchain, GHC and Cabal, installed (e.g. via [GHCup][ghcup]).
57+
After that you can use `cabal` to build the website as follows:
58+
59+
[ghcup]: https://www.haskell.org/ghcup/
60+
61+
```bash
62+
# Update package list (first time only)
63+
cabal update
64+
65+
# Build and run the site generator
66+
cabal run site -- build
67+
68+
# Preview the site locally (optional)
69+
cabal run site -- watch
70+
# Then visit http://localhost:8000
71+
```
72+
73+
A variation of these commands is used in the `Makefile`: run `make` to generate the site.
74+
75+
#### Option 2: Using Nix
76+
77+
[Nix][nix] is less straightforward to obtain usually, so it's not recommended for newcomers.
78+
Nix provides pre-compiled binary packages for all dependencies, which significantly speeds up the first build.
79+
This is what we use in our GitHub CI for expediency.
80+
81+
[nix]: https://nixos.org/
82+
83+
```bash
84+
# Build the site application binary with Nix
85+
nix-build
86+
87+
# Run the site generator to build the site
88+
result/bin/site build
89+
90+
# Preview the site locally (optional)
91+
result/bin/site watch
92+
# Then visit http://localhost:8000
93+
```
94+
95+
Alternatively, you can use the `Makefile`:
96+
```bash
97+
# Build the binary and generate the site
98+
make nix-site
99+
```
100+
101+
### Build results
102+
103+
No matter how you build the site, it will end up in the `_site/` directory.
104+
41105
## Licence
42106
This domain and repository is in no way affiliated with Miran Lipovača (the original author) and is being extended and modified with his permission as per the licence the original work was released under ([Creative Commons Attribution-Noncommercial-ShareAlike 3.0 Unported License](http://creativecommons.org/licenses/by-nc-sa/3.0/)) as well as his literal statement encouraging modifications to be made ([FAQ](http://learnyouahaskell.com/faq)).
43107

config/file-list.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

config/pandoc-defaults.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

default.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{ pkgs ? import <nixpkgs> {} }:
2+
3+
pkgs.haskellPackages.callCabal2nix "lyah-site" ./. {}

generate.sh

Lines changed: 0 additions & 101 deletions
This file was deleted.

lyah-site.cabal

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cabal-version: 3.0
2+
name: lyah-site
3+
version: 0.1.0.0
4+
license: BSD-3-Clause
5+
author: LYAH Community
6+
maintainer: lyah-community@example.com
7+
build-type: Simple
8+
tested-with: GHC ==9.10
9+
10+
executable site
11+
main-is: site.hs
12+
build-depends: base >= 4 && < 5
13+
, hakyll >= 4.16 && < 4.17
14+
, pandoc
15+
, pandoc-types
16+
, filepath
17+
, containers
18+
, text
19+
, directory
20+
ghc-options: -threaded
21+
default-language: Haskell2010

0 commit comments

Comments
 (0)