diff options
-rw-r--r-- | flake.nix | 35 | ||||
-rwxr-xr-x | md2saait/frontmatter2cfg | 11 | ||||
-rwxr-xr-x | md2saait/getdate | 4 |
3 files changed, 49 insertions, 1 deletions
diff --git a/flake.nix b/flake.nix index 7c9f2e9..d88cbe6 100644 --- a/flake.nix +++ b/flake.nix @@ -6,13 +6,46 @@ let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; overlays = [ nur.overlay ]; }; + + kronika = pkgs.fetchFromGitHub { + repo = "kronika"; + owner = "19pdh"; + rev = "master"; + sha256 = "1pafahvq8xhpba2hgpipkbnhjr3j9zchnxfq4pnxqvidwz5rqr51"; + }; + + md2saait = pkgs.stdenv.mkDerivation { + name = "md2saait"; + src = ./md2saait; + installPhase = '' + mkdir -p $out/bin + cp ./* $out/bin + sed -i 's:yq:${pkgs.yq}/bin/yq:g' $out/bin/frontmatter2cfg + ''; + }; + in { defaultPackage.${system} = self.packages.${system}.low-puszcza; packages.${system}.low-puszcza = pkgs.stdenv.mkDerivation { name = "low-puszcza"; src = self; - nativeBuildInputs = [ pkgs.zip pkgs.nur.repos.pn.saait ]; + nativeBuildInputs = with pkgs; [ + md2saait + zip + pandoc + nur.repos.pn.saait + ]; + + buildPhase = '' + cp ${kronika}/wpisy wpisy -r + for f in `find wpisy -name *.md`; do + name=$(basename $f .md) + date=$(getdate $f) + frontmatter2cfg $f > pages/$date_$name.cfg + pandoc $f > pages/$date_$name.html + make + ''; installPhase = '' cp -r output $out diff --git a/md2saait/frontmatter2cfg b/md2saait/frontmatter2cfg new file mode 100755 index 0000000..c53a905 --- /dev/null +++ b/md2saait/frontmatter2cfg @@ -0,0 +1,11 @@ +#!/bin/sh +#/usr/bin/env nix-shell +#nix-shell -i sh -p yq +## Script for extracting frontmatter data and converting it into .cfg files required by saait +## +## Usage: +## $ ./frontmatter2cfg [.md FILE] + +INPUT=$1 + +sed -n '/---/,/---/p' $INPUT | tail -n +2 | head -n -1 | yq '{title: .title, created: .date, updated: .date, keywords: .title, image: .image}' -y | sed "/\(created\|updated\)/s/T.*'/'/" | sed "s/:/ =/" diff --git a/md2saait/getdate b/md2saait/getdate new file mode 100755 index 0000000..280d5cc --- /dev/null +++ b/md2saait/getdate @@ -0,0 +1,4 @@ +#!/bin/sh + +frontmatter2cfg $1 | grep created | \ + cut -d' ' -f 3 | cut -c 2- | rev | cut -c 2- | rev |