feat(sterni/blërg): generic, configurable backends

Change-Id: Iebec5caea9b780eb8ca2ec1f18bb4fa978f4bb95
Reviewed-on: https://cl.tvl.fyi/c/depot/+/13107
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Autosubmit: sterni <sternenseemann@systemli.org>
This commit is contained in:
sterni 2025-01-24 22:18:46 +01:00 committed by clbot
parent 1a0d20b417
commit 5e3e62c87d
3 changed files with 46 additions and 11 deletions

View file

@ -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/

View file

@ -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 {𝕊 exitstdoutstderr: stderr!0=exit stdout}Run
LR LinesR
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,headerNamesheaderNames Hdrs ms
@ -55,6 +71,8 @@ MailNotesBackend ← {𝕊 mailDir:
}
}
backends >"mail-notes"mailNotesBackend
# Rendering
RenderPage {
@ -76,18 +94,26 @@ WriteEntry ← {outDir 𝕊 entry:
# Main
mailDiroutDir {
# Usage: blërg <maildir> <out dir>
configFileoutDir {
# Usage: blërg <config file> <out dir>
! 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 ˘{21"name"𝕩}¨ bns
bts (j.ObjGet"type")˜¨ bcs
backends bcs {𝕏 𝕨}¨ backendsj.ObjGet¨ bts
title raw j.ObjGet "title"
}
entries (<"time") (((•ns.Get˜¨))) {𝕩.Entries @}¨ config.backends
MkDirP outDir
entryIndex outDirWriteEntry¨ entries
(outDir •file.At "index.html") •file.Chars title RenderPage "<ul>"entryIndex"</ul>"
(outDir •file.At "index.html") •file.Chars config.title RenderPage "<ul>"entryIndex"</ul>"

View file

@ -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}"
''