-
Notifications
You must be signed in to change notification settings - Fork 60
Move from Bash/sed to Haskell/Hakyll for site generation #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Impressive work @ulysses4ever! 👏 I don't think I will have time to review before new year, but I will make time before the 5th for sure. Looking forward to approve this! :) |
|
@pierluc-codes no rush! Thanks for replying and happy holidays! |
62e1723 to
087d686
Compare
|
@ulysses4ever My apologies. Coming back from the holiday was much more difficult than anticipated. I will do a first round of review this weekend. |
|
@pierluc-codes no worries! Thanks for the update and looking forward to it! |
Co-authored-by: ulysses4ever <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Hey all and happy holidays! I've spent my holidays (in part) porting the shell script (
generate.sh) that converts Markdown to HTML to Haskell using the Hakyll library that assists in producing static websites.I submit two commits: one just moves stuff from the
markdowndirectory to the top level (makes sense after markdown became the only way to work with the website) and the other does the thing; this should ease reading the diff. In sections below, I discuss some high-level questions because I don't expect people to dive too deep in the Haskell implementation. Also, eyeballing the result is very welcome (see https://ulysses4ever.github.io/learnyouahaskell.github.io/).Those who are interested in the implementation, though, can find it in the single Haskell file (sans
templates),site.hs, which I tried to document with comments as much as possible. The resulting script has grown about 1.5x in size relative togenerate.sh, but I think it's more readable, and you can follow it even if you're not familiar with Hakyll. The code is co-authored by GitHub Copilot.Why move away from the shell script
Hard to maintain (subjectively). It uses pretty gnarly
sedexpressions to generate the table of contents (chapters.html), for instance.It's not entirely portable (e.g. MacOS users reported some troubles, although they can be resolved).
Why use Haskell/Hakyll
First in class conversion tools: Pandoc, Hakyll's high-level DSL to describe routes and transformations, templating system
More portable.
It makes a point to use Haskell to produce a book about Haskell.
Downsides of using Haskell
Haskell is less known than Bash among the general population, so contributions and maintenance may be trickier. But there are challenges with bash/sed as well, as noted above. Overall, I think we are in profit. Also, casual contributors don't have to build the site: in most cases, editing markdown should be enough.
Bash/sed are omnipresent (the other side of the portability issue of course), whereas to build a Haskell application, you need special tools (I explain it in detail in the README). Again, just like with (1), I believe this downside is outweighed by the benefits.
Changes in HTML
We still use Pandoc, so the results are mostly intact. There are two simplifications I made to make the whole thing simpler.
Small margins for some H1 headers are gone. There were (seemingly) arbitrary margins for the chapter headings. They looked like artifacts from the past (e.g. WYSIWYG tools sometimes produce this sort of small random adjustments). So, I removed them.
Img-tags are left wrapped in p-tags. Generate.sh patched those with sed, and I could certainly re-implement it in Haskell but I see no point in this: visually, the result seems the same.
I believe these changes don't have any negative effect while simplifying the whole picture.