feat(sterni/blërg): yet another blog software

Currently, blërg is an incomplete reimplementation of
//users/sterni/mblog that uses mblaze(7) and //users/sterni/mn2html to
process the backing mail notes.

Now, why start from scratch again?

- mblog is depressingly slow at the moment which is due to
  //third_party/lisp/mime4cl. The performance problems are
  (probably) solvable, but this would require carefully
  redesigning the library's use of streams. I'm not motivated
  to look into that at the moment, unfortunately.

- I had an idea for intergrating additional storage backends
  for entries into an mblog like software. I've found experimenting
  with this in BQN to be quite pleasant as the backends can
  easily be expressed as namespaces.

Change-Id: I90c8ff7b5f7235d6fd7b0619338b553be8742e49
Reviewed-on: https://cl.tvl.fyi/c/depot/+/13015
Autosubmit: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
sterni 2024-12-20 01:56:02 +01:00 committed by clbot
parent ba2d2d3eea
commit 6479f9ae5e
2 changed files with 125 additions and 0 deletions

93
users/sterni/blërg/blërg.bqn Executable file
View file

@ -0,0 +1,93 @@
#!/usr/bin/env BQN
# SPDX-FileCopyrightText: Copyright © 2024 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
# scripting languages so we can rely on external tools for certain tasks (e.g.
# transforming HTML and parsing MIME messages).
#
# Specifically, blërg depends on:
# - mblaze
# - mn2html
# - execline (to work around the lack of cwd in BQN)
# Utilities
MkDirP •file.CreateDir(¬•file.Exists)
AsciiDown ('A'-'a')(-×('A''Z'))
nl @+10
SplitChar ((=(¯1˙)¨+`=))
Lines nlSplitChar
ReadPosInt {(𝕨×+)´-'0'𝕩} # ty leah2
ReadPosDec 10ReadPosInt
ApplyMany {fs 𝕊 arg: {𝕏 arg}¨ fs}
Chomp {nl¯1𝕩? ¯1𝕩; 𝕩}
Run {
𝕊 𝕩: 1 𝕊 𝕩;
doChomp 𝕊 cmd:
exitstdoutstderr •SH cmd
•term.ErrRaw(0exit) stderr
ChompdoChomp stdout, exit
}
R {𝕊 stdoutexit: !0=exit stdout}Run
LR LinesR
# (Apple) Mail Notes Backend
# TODO(sterni): avoid argv limit by chunking
Hdr {LR "mhdr""-dh"𝕨𝕩}
Date {ReadPosDec¨ LR "mhdr""-Dh""Date"𝕩}
MailNotesBackend {𝕊 mailDir:
Filter {𝕩 ("com.apple.mail-note"¨/) "X-Uniform-Type-Identifier" Hdr 𝕩}
Id AsciiDown "X-Universally-Unique-Identifier"Hdr
Title "Subject"Hdr
MkRenderer {𝕊 p: {R "execline-cd"𝕩"mshow""-x"p R "mn2html"p}}
# TODO(sterni): entries could become namespaces
Entries {𝕊: >Id,Title,Date,MkRenderer¨ApplyMany Filter LR "mlist"mailDir}
}
# Rendering
RenderPage {
"<!doctype html>
<html lang=""en"">
<head>
<meta charset=""utf-8"">
<title>"‿𝕨‿"</title>
<body>
<h1>"‿𝕨‿"</h1>"𝕩
}
WriteEntry {outDir 𝕊 idtitle·renderEntry:
entryDir MkDirP outDir •file.At id
(entryDir •file.At "index.html") •file.Chars title RenderPage RenderEntry entryDir
# TODO(sterni): urlencode
"<li><a href="""id""">"title"</a></li>"
}
# Main
mailDiroutDir {
# Usage: blërg <maildir> <out dir>
! 2=•args
# TODO(sterni): expand ~/
•wdpath•file.At¨ •args
}
m MailNotesBackend mailDir
entries (( 2˘)) m.Entries @
title "blërg"
MkDirP outDir
entryIndex (< outDirWriteEntry)˘ entries
(outDir •file.At "index.html") •file.Chars title RenderPage "<ul>"entryIndex"</ul>"

View file

@ -0,0 +1,32 @@
{ depot, pkgs, lib, ... }:
let
runtimeDependencies = [
depot.users.sterni.mn2html
pkgs.mblaze
pkgs.execline # execline-cd
];
buildInputs = [
pkgs.cbqn
];
in
pkgs.runCommandNoCC "blerg"
{
src = builtins.path {
name = "blerg.bqn";
path = ./. + "/blërg.bqn";
};
nativeBuildInputs = [ pkgs.buildPackages.makeWrapper ];
inherit buildInputs;
passthru.shell = pkgs.mkShell {
name = "blërg-shell";
packages = runtimeDependencies ++ buildInputs;
};
}
''
install -Dm755 "$src" "$out/bin/blërg"
patchShebangs "$out/bin/blërg"
wrapProgram "$out/bin/blërg" --prefix PATH : "${lib.makeBinPath runtimeDependencies}"
''