va1en0k va1en0k
roguelikeT roguelikeT
Built with Haskell using Slick
Hello world + Slick tutorial
September 22, 2018

The problem with my usual blogging attempts is that I tried only to document successes. Let's be honest: there's no real success in writing, nor have I ever experienced any real success in programming. Thus, I'd only blog whenever I'd fool myself into being successful for a moment.

This blog will hopefully be dedicated mostly to my failures. I fail a lot, so here's that. I've found that documenting as much as possible is nice for me sometimes – helps me with coming back to things. Those things will hopefully include Haskell, gamedev, videogame criticism and philosophy.

This site is built using Slick, a Haskell static site builder. It seems nice. The build time is quite slow – probably because it uses more than a hungred packages. I used heroku to host this.

A little tutorial for the laziest, like me:

  1. You'll need stack.

  2. We're only interested in the example-site from the git repo:

    git clone https://github.com/ChrisPenner/Slick
    cp -R Slick/example-site/* .
    rm -rf Slick
  3. Edit stack.yaml, you want those two options:

    packages:
    - .
    # - .. # comment this out
    
    extra-deps:
    - slick-0.1.1.0 # add this one
  4. Run stack build for the first time, to get the packages. It will take 15 minutes or so: a lot of packages.

    stack build
  5. There're two different things to build: the haskell program, and then the website itself using this program. The program will take a couple minutes to build every time. You can build it with stack build. Or better, to rebuild the executable on every change to the *.hs files, in an extra terminal run and keep running:

    stack build --file-watch --fast
  6. Now that you have the executable, run it to build the website:

    stack exec example-site-exe site -- --rebuild

    The website will be in the dist/ folder. (Change the package.yaml to rename the executable if you ever get around to it).

  7. OK, here's your website. Now, two heroku tricks for easy serving.

  8. Create a file called dist/index.php, contents:

    <?php header('Location: /index.html');  ?>

    Yep, this is the simplest way to serve a static site on heroku: by pretending it's PHP.

  9. To push only the dist/ folder, you can do: git subtree push --prefix dist heroku master. A fancier push (e.g. for --force) can be done like this: git push heroku `git subtree split --prefix dist master`:master --force

  10. stack exec example-site-exe site && git add dist && gca -m "site update"
    && git subtree push --prefix dist heroku master

    does the whole trick, provided you've built the up-to-date executable as in pt. 5.