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

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