Giter VIP home page Giter VIP logo

hakyll-nix-template's Introduction

hakyll-nix-template

Hakyll + Nix template

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:

    nix build --print-build-logs && \
      nix run . clean && \
      nix run . watch
    

Features

  • Build your site into the ./result/dist folder:

    λ nix build
    
  • Start hakyll's dev server that reloads when changes are made:

    λ nix run . watch
    Listening on http://127.0.0.1:8000
    ...more logs
    
  • Run any hakyll command through nix run .!

    λ 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
    • 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
    λ nix develop
    
    [hakyll-nix]λ hakyll-site build
    ...
    Success
    
    [hakyll-nix]λ ghci
    ...
    [1 of 1] Compiling Main    ( ssg/src/Main.hs, interpreted )
    ...
    
    λ >
    

hakyll

All of this is custmomizable, and here are some things that are already done for you:

  • pandoc markdown customization to make it as close to GitHub's markdown style as possible
  • slugger module is included that makes nice link URIs based on post titles
  • 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 with cachix, and it deploys to a GitHub Pages 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

If you don't have nix, follow the nix installation instructions.

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 cachix, so you'll need to generate a signing key to be able to do this.

  1. Create a cache on cachix for your project
  2. Follow cachix's instructions to generate a signing keypair
  3. Copy the signing keypair value to a new CACHIX_SIGNING_KEY secret on https://github.com/settings/secrets

hakyll-nix-template's People

Contributors

dependabot[bot] avatar rkbethke avatar rpearce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hakyll-nix-template's Issues

Add shell.nix for Nix Env Selector 🙏🏻

Hi, thanks for this template! I'm using vscode with the Nix Env Selector and it does not seem to pick up correctly HLS by default, I guess if we had some shell.nix to point the extension to that had all the libs that we already built in flake.nix we could make the integration with this editor quite seamless, but unfortunately I do not know enough Nix to do it myself 😢.

Thanks in advance and do let me know if you think this might be a useful addition to the template! 🙏🏻

Why is `ignoreFile` set to `const False`? For me this resulted in emacs temp files not being ignored in testing

, ignoreFile = const False

I'm following the instructions as per the readme. I originally expected

src = prev.nix-gitignore.gitignoreSourcePure [
to be enough, but I guess it isn't. Perhaps for the initial nix build But I guess it can't really work for live rebuilding anyway. So my question is, why set this to const False in the template and have Emacs users run into problems?

Extract Slug module and custom hakyll title to separate module

Extract https://github.com/rpearce/hakyll-nix-template/blob/main/ssg/src/Slug.hs and

-- TITLE HELPERS
replaceAmp :: String -> String
replaceAmp =
replaceAll "&" (const "&")
replaceTitleAmp :: Metadata -> String
replaceTitleAmp =
replaceAmp . safeTitle
safeTitle :: Metadata -> String
safeTitle =
fromMaybe "no title" . lookupString "title"
updatedTitle :: Item a -> Compiler String
updatedTitle =
fmap replaceTitleAmp . getMetadata . itemIdentifier
to separate, shareable module.

Error with "nix run . watch": attribute 'defaultApp.x86_64-linux' should have type 'derivation'

Steps to reproduce:

  1. Clone this repository
  2. Use nix 2.8
  3. Run nix build
  4. nix run . watch

Unexpected Result:

error: attribute 'defaultApp.x86_64-linux' should have type 'derivation'

Relevant System Information:

❯ nixos-version
22.11.20220603.236cc29 (Raccoon)
❯ nix-info -m
 - system: `"x86_64-linux"`
 - host os: `Linux 5.18.0, NixOS, 22.11 (Raccoon), 22.11.20220603.236cc29`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.8.1`
 - nixpkgs: `/nix/store/3ds4cwrnkgfvpjgf80vr2dbw9yfrrnsv-source`

This appears to be an issue/deprecation introduced in Nix 2.8: NixOS/nix#6448

The suggested solution (I'll submit a PR with these changes): NixOS/nix#6448 (comment)

Problem building `cwf-ssg-exe-hakyll-site` with Nix

Yesterday I run run nix . watch and it was working correctly, today it does not work :S

error: builder for '/nix/store/qhs8gcbas45hmliwpik01qz0rffz2cwf-ssg-exe-hakyll-site-0.1.0.0.drv' failed with exit code 1;
       last 10 log lines:
       >   |
       > 6 | import Data.Text qualified as T
       >   |                  ^^^^^^^^^
       >
       > src/Main.hs:7:26: error:
       >     Found ‘qualified’ in postpositive position.
       >     To allow this, enable language extension 'ImportQualifiedPost'
       >   |
       > 7 | import Data.Text.Slugger qualified as Slugger
       >   |                          ^^^^^^^^^
       For full logs, run 'nix log /nix/store/qhs8gcbas45hmliwpik01qz0rffz2cwf-ssg-exe-hakyll-site-0.1.0.0.drv'.

feat: add static asset content hashing

We need to be able to break local browser caches easily, and files like styles.abc123.css that are also automatically referenced in templates would be useful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.