commit 4d1663e588a50b7e251d31439922e83b337f12af Author: noe Date: Mon Apr 21 17:24:14 2025 -0700 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..af1da56 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result/ \ No newline at end of file diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..dbc9a70 --- /dev/null +++ b/default.nix @@ -0,0 +1,10 @@ +{ + pkgs ? import {}, + inputs ? {}, +}: rec { + default = brewTea; + brewTea = import ./pkgs/brewTea.nix { inherit pkgs inputs; }; + mkMarkdollPlugin = import ./pkgs/mkMarkdollPlugin.nix { inherit pkgs; }; + + example_quickstart = import ./examples/quickstart { inherit pkgs brewTea mkMarkdollPlugin; }; +} \ No newline at end of file diff --git a/examples/quickstart/blog/today.doll b/examples/quickstart/blog/today.doll new file mode 100644 index 0000000..1248d47 --- /dev/null +++ b/examples/quickstart/blog/today.doll @@ -0,0 +1 @@ +&hello world!! \ No newline at end of file diff --git a/examples/quickstart/default.nix b/examples/quickstart/default.nix new file mode 100644 index 0000000..f276344 --- /dev/null +++ b/examples/quickstart/default.nix @@ -0,0 +1,7 @@ +{ pkgs, brewTea, ... }: brewTea { + name = "examples_quickstart"; + version = "0.0.0"; + + src = ./.; + layoutSrc = ./layouts; +} \ No newline at end of file diff --git a/examples/quickstart/index.doll b/examples/quickstart/index.doll new file mode 100644 index 0000000..b5bfde9 --- /dev/null +++ b/examples/quickstart/index.doll @@ -0,0 +1,16 @@ +--- +title: awawa! +layout: alt.html +--- + +this is markdoll! + +&so it is really gay to use other doll's software right? + yeah......... + +&look at this + [link(/page2.html):there's another page!!!!] + + [img(https://codeberg.org/0x57e11a/markdoll/raw/branch/main/button.png):: + alt text goes here (88x31 button that says MADE WITH MARKDOLL) + ] \ No newline at end of file diff --git a/examples/quickstart/layouts/alt.html b/examples/quickstart/layouts/alt.html new file mode 100644 index 0000000..e5935ad --- /dev/null +++ b/examples/quickstart/layouts/alt.html @@ -0,0 +1,12 @@ + +%%TITLE%% | alt layout + + + +
%%CONTENT%%
+ diff --git a/examples/quickstart/layouts/default.html b/examples/quickstart/layouts/default.html new file mode 100644 index 0000000..562e84a --- /dev/null +++ b/examples/quickstart/layouts/default.html @@ -0,0 +1,6 @@ + +%%TITLE%% | default layout + + +
%%CONTENT%%
+ diff --git a/examples/quickstart/page2.doll b/examples/quickstart/page2.doll new file mode 100644 index 0000000..14007d4 --- /dev/null +++ b/examples/quickstart/page2.doll @@ -0,0 +1,6 @@ +--- +title: AWAWAWA +--- + +&real awawa shit + haha gottem \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..19229e1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,168 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1744386647, + "narHash": "sha256-DXwQEJllxpYeVOiSlBhQuGjfvkoGHTtILLYO2FvcyzQ=", + "owner": "ipetkov", + "repo": "crane", + "rev": "d02c1cdd7ec539699aa44e6ff912e15535969803", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "markdoll": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1745093370, + "narHash": "sha256-M4Nal2SQ9hW08VVjgV80V5KqC3W/8flsc9hUluIYdYM=", + "ref": "refs/heads/main", + "rev": "fb42921ee9a4592b5f055a4e8c4fe244275e4fef", + "revCount": 79, + "type": "git", + "url": "https://codeberg.org/0x57e11a/markdoll.git" + }, + "original": { + "type": "git", + "url": "https://codeberg.org/0x57e11a/markdoll.git" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1744536153, + "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1744868846, + "narHash": "sha256-5RJTdUHDmj12Qsv7XOhuospjAjATNiTMElplWnJE9Hs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ebe4301cbd8f81c4f8d3244b3632338bbeb6d49c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "markdoll": "markdoll", + "nixpkgs": "nixpkgs_2" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "markdoll", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1744770893, + "narHash": "sha256-RMyTyFHN3w8zwfpgvcfRHQ4vX4zTqhuZbif/MXROtx8=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "1633514603fc0ed15ea0aef7327e26736ec003c0", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..18205a8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,16 @@ +{ + description = "teapot is a static site generator using pure nix"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + markdoll.url = "git+https://codeberg.org/0x57e11a/markdoll.git"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }@inputs: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { inherit system; }; + in { + packages = import ./default.nix { inherit pkgs inputs; }; + }); +} \ No newline at end of file diff --git a/pkgs/brewTea.nix b/pkgs/brewTea.nix new file mode 100644 index 0000000..40b06da --- /dev/null +++ b/pkgs/brewTea.nix @@ -0,0 +1,91 @@ +{ pkgs, inputs }: +{ + name, + version, + + # TODO: do not require flakes + markdollParser ? inputs.markdoll.packages.${pkgs.system}.markdoll, + markdollPlugins ? [], + src, + + layoutSrc, + # otherwise set by frontmatter + defaultLayout ? "default.html", +}: let + markdoll = "${markdollParser}/bin/markdoll"; +in pkgs.stdenvNoCC.mkDerivation { + inherit name version src; + + buildPhase = '' + mkdir dist + + layout_inject() { + layoutFile=$1 + placeholder=$2 + content=$3 + + layout=$(cat $layoutFile) + echo ''${layout/"$placeholder"/"$content"} + } + + get_frontmatter() { + key=$1 + file=$2 + + keyLine=$(grep -e "$key: " $file || echo "") + sed "s/.*: //" <<<$keyLine | xargs + } + + render_final() { + file=$1 + content=$2 + outFile=$3 + + ### Frontmatter: Get Layout + layout="${defaultLayout}" + layoutFm=$(get_frontmatter layout $file) + if [ ! -z $layoutFm ]; then + layout="$layoutFm" + fi + + layoutPath="${layoutSrc}/$layout" + if [ ! -f $layoutPath ]; then + echo "Layout file $layout not found" + exit 1 + fi + + ### Frontmatter: Title + title=$(get_frontmatter title $file) + if [ -z $title ]; then + title=$(basename $file | sed -e 's/.doll$//') + fi + + ### Layout: Title + Content + mkdir -p $(dirname $outFile) + layout_inject $layoutPath %%TITLE%% "$title" > $outFile.tmp.1 + layout_inject $outFile.tmp.1 %%CONTENT%% "$content" > $outFile.tmp.final + + ### Layout: Cleanup Tmpfiles + cp $outFile.tmp.final $outFile + rm $outFile.tmp* + } + + echo ">>> DOLLFILES" + dollFiles=$(find . -name '*.doll') + echo $dollFiles + + for file in $dollFiles; do + outFile=$(realpath -m "dist/$(echo $file | sed -e 's/.doll$/.html/')") + echo "reading $file; plopping $outFile" + + ### Markdoll: Convert + content=$(cat $file | ${markdoll} convert) + + render_final $file $content $outFile + done + ''; + + installPhase = '' + cp -rv dist $out + ''; +} \ No newline at end of file diff --git a/pkgs/mkMarkdollPlugin.nix b/pkgs/mkMarkdollPlugin.nix new file mode 100644 index 0000000..b2da8d1 --- /dev/null +++ b/pkgs/mkMarkdollPlugin.nix @@ -0,0 +1,7 @@ +{ pkgs }: binPath: pkgs.stdenvNoCC.mkDerivation { + src = binPath; + buildPhase = '' + mkdir -p $out + cp $src $out/plugin + ''; +} \ No newline at end of file