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:
parent
1a0d20b417
commit
5e3e62c87d
3 changed files with 46 additions and 11 deletions
|
|
@ -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/
|
||||
|
|
|
|||
|
|
@ -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 <maildir> <out dir>
|
||||
configFile‿outDir ← {
|
||||
# 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 ∾˘⟜{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 ∾"<ul>"∾entryIndex∾"</ul>"
|
||||
(outDir •file.At "index.html") •file.Chars config.title RenderPage ∾"<ul>"∾entryIndex∾"</ul>"
|
||||
|
|
|
|||
|
|
@ -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}"
|
||||
''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue