diff --git a/users/sterni/blërg/README.md b/users/sterni/blërg/README.md index 0717f4ce5..70c286efc 100644 --- a/users/sterni/blërg/README.md +++ b/users/sterni/blërg/README.md @@ -3,6 +3,8 @@ ## dependencies - [CBQN][] (other [BQN][] implementations may work, but are untested) +- Marshall Lochbaum's [bqn-libs][] which blërg expects to find at the + location the `BQN_LIBS` environment variable points to. - //users/sterni/mn2html - [mblaze(7)][mblaze] - [execline][] @@ -12,3 +14,4 @@ [execline]: https://skarnet.org/software/execline/ [BQN]: https://mlochbaum.github.io/BQN/ [CBQN]: https://github.com/dzaima/cbqn +[bqn-libs]: https://github.com/mlochbaum/bqn-libs/ diff --git a/users/sterni/blërg/blërg.bqn b/users/sterni/blërg/blërg.bqn index ac92ebff9..37014055e 100755 --- a/users/sterni/blërg/blërg.bqn +++ b/users/sterni/blërg/blërg.bqn @@ -1,5 +1,5 @@ #!/usr/bin/env BQN -# SPDX-FileCopyrightText: Copyright © 2024 sterni +# SPDX-FileCopyrightText: Copyright © 2024-2025 sterni # SPDX-License-Identifier: GPL-3.0-only # # blërg is a reimplementation of mblog in BQN. BQN is used as a sort of bespoke @@ -34,6 +34,21 @@ Run ← { R ← {𝕊 exit‿stdout‿stderr: stderr!0=exit ⋄ stdout}∘Run LR ← Lines∘R +GetEnv ← {R "importas"‿"env"‿𝕩‿"printf"‿"%s"‿"$env"} + +RelPath ← •wdpath⊸•file.At + +# 3p dependencies + +j ← { + # Update README.md if dependency discovery changes + ⟨Parse⟩ ⇐ •Import (GetEnv "BQN_LIBS") •file.At "json.bqn" + + # TODO(sterni): default value + ObjGet ⇐ (⊏⊸(⊑∘⊐) ⊑ ⊏˜⟜1)⟜< + ObjGetPath ⇐ ObjGet˜´⟜⌽ +} + # (Apple) Mail Notes Backend # TODO(sterni): avoid argv limit by chunking @@ -41,7 +56,8 @@ Hdrs ← {LR "mhdr"‿"-dh"‿(':' _join 𝕨)∾𝕩} Dates ← {ReadPosDec¨ LR "mhdr"‿"-Dh"‿"Date"∾𝕩} headerNames ← "X-Uniform-Type-Identifier"‿"X-Universally-Unique-Identifier"‿"Subject" -MailNotesBackend ← {𝕊 mailDir: +MailNotesBackend ← {𝕊 config: + mailDir ← RelPath config j.ObjGet "maildir" Entries ⇐ {𝕊: ms ← LR "mlist"‿mailDir th ← ⟨≠ms,≠headerNames⟩⥊headerNames Hdrs ms @@ -55,6 +71,8 @@ MailNotesBackend ← {𝕊 mailDir: } } +backends ← ⍉>⟨"mail-notes"‿mailNotesBackend⟩ + # Rendering RenderPage ← { @@ -76,18 +94,26 @@ WriteEntry ← {outDir 𝕊 entry: # Main -mailDir‿outDir ← { - # Usage: blërg +configFile‿outDir ← { + # Usage: blërg ! 2=≠•args # TODO(sterni): expand ~/ - •wdpath⊸•file.At¨ •args + RelPath¨ •args } -m ← MailNotesBackend mailDir -entries ← (<"time") ((⍒∘(•ns.Get˜¨))⊏⊢) m.Entries @ +config ← { + raw ← j.Parse •FChars configFile -title ← "blërg" + [bns,bcs] ← raw j.ObjGet "backends" + bcs ↩ bcs ∾˘⟜{2‿1⊸⥊"name"‿𝕩}¨ bns + bts ← (j.ObjGet⟜"type")˜¨ bcs + backends ⇐ bcs {𝕏 𝕨}¨ backends⊸j.ObjGet¨ bts + + title ⇐ raw j.ObjGet "title" +} + +entries ← (<"time") ((⍒∘(•ns.Get˜¨))⊏⊢) ∾{𝕩.Entries @}¨ config.backends MkDirP outDir entryIndex ← outDir⊸WriteEntry¨ entries -(outDir •file.At "index.html") •file.Chars title RenderPage ∾"
    "∾entryIndex∾"
" +(outDir •file.At "index.html") •file.Chars config.title RenderPage ∾"
    "∾entryIndex∾"
" diff --git a/users/sterni/blërg/default.nix b/users/sterni/blërg/default.nix index 8980b41a3..688253a0f 100644 --- a/users/sterni/blërg/default.nix +++ b/users/sterni/blërg/default.nix @@ -5,13 +5,16 @@ let runtimeDependencies = [ depot.users.sterni.mn2html pkgs.mblaze - pkgs.execline # execline-cd + pkgs.execline # execline-cd, importas + # coreutils # for printf (assumed to be installed) ]; # … and this buildInputs = [ pkgs.cbqn ]; + + BQN_LIBS = depot.third_party.bqn-libs + "/lib"; in pkgs.runCommandNoCC "blerg" @@ -25,10 +28,13 @@ pkgs.runCommandNoCC "blerg" passthru.shell = pkgs.mkShell { name = "blërg-shell"; packages = runtimeDependencies ++ buildInputs; + inherit BQN_LIBS; }; } '' install -Dm755 "$src" "$out/bin/blërg" patchShebangs "$out/bin/blërg" - wrapProgram "$out/bin/blërg" --prefix PATH : "${lib.makeBinPath runtimeDependencies}" + wrapProgram "$out/bin/blërg" \ + --prefix PATH : "${lib.makeBinPath runtimeDependencies}" \ + --set BQN_LIBS "${BQN_LIBS}" ''