Discussion
Loading...

Post

  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
embedding-shapes
@embedding_shapes@mastodon.social  ·  activity timestamp last week

I published my first #Nix / #NixOS library!

Niccup: Hiccup-like HTML Generation in ~120 Lines of Pure Nix.

Transforms Nix expressions into HTML.

The website has some cool examples, I'm especially proud of the quine one that was slightly tricky to get right: https://embedding-shapes.github.io/niccup/examples/quine/

Website: https://embedding-shapes.github.io/niccup/

And a softer introduction blog post with motivation and more background: https://embedding-shapes.github.io/introducing-niccup/

Examples

let h = inputs.niccup.lib; in
h.render [
  "div#main.container"
  { lang = "en"; class = [ "app" "dark" ]; }
  [ "h1" "Hello from Nix" ]
  [ "p" "Hiccup-style HTML in Nix." ]
  (h.comment "List example")
  [ "ul" (map (x: [ "li.item" x ]) [ "one" "two" "three" ]) ]
]

Write to file (use nixpkgs writeText):

{ pkgs, inputs, ... }:
pkgs.writeText "index.html" (inputs.niccup.lib.render [ "p" "Hello" ])

Some more involved examples:

    art - Generative SVG (Sierpinski triangle)
    blog - Multi-page blog with navigation
    docs - NixOS module documentation generator
    quine - Self-rendering page

The website for niccup is generated dynamically with niccup too, the whole source is ~120 lines of Nix as well
Examples let h = inputs.niccup.lib; in h.render [ "div#main.container" { lang = "en"; class = [ "app" "dark" ]; } [ "h1" "Hello from Nix" ] [ "p" "Hiccup-style HTML in Nix." ] (h.comment "List example") [ "ul" (map (x: [ "li.item" x ]) [ "one" "two" "three" ]) ] ] Write to file (use nixpkgs writeText): { pkgs, inputs, ... }: pkgs.writeText "index.html" (inputs.niccup.lib.render [ "p" "Hello" ]) Some more involved examples: art - Generative SVG (Sierpinski triangle) blog - Multi-page blog with navigation docs - NixOS module documentation generator quine - Self-rendering page The website for niccup is generated dynamically with niccup too, the whole source is ~120 lines of Nix as well
Examples let h = inputs.niccup.lib; in h.render [ "div#main.container" { lang = "en"; class = [ "app" "dark" ]; } [ "h1" "Hello from Nix" ] [ "p" "Hiccup-style HTML in Nix." ] (h.comment "List example") [ "ul" (map (x: [ "li.item" x ]) [ "one" "two" "three" ]) ] ] Write to file (use nixpkgs writeText): { pkgs, inputs, ... }: pkgs.writeText "index.html" (inputs.niccup.lib.render [ "p" "Hello" ]) Some more involved examples: art - Generative SVG (Sierpinski triangle) blog - Multi-page blog with navigation docs - NixOS module documentation generator quine - Self-rendering page The website for niccup is generated dynamically with niccup too, the whole source is ~120 lines of Nix as well
  • Copy link
  • Flag this post
  • Block
Log in

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.1-alpha.8 no JS en
Automatic federation enabled
  • Explore
  • About
  • Members
  • Code of Conduct
Home
Login