From 5cd3d9e3ac2d7ad6a2288ef40bee4d91423fb881 Mon Sep 17 00:00:00 2001 From: sterni Date: Wed, 5 Feb 2025 00:12:09 +0100 Subject: [PATCH] =?UTF-8?q?feat(sterni/bl=C3=ABrg/git):=20render=20html,?= =?UTF-8?q?=20org=20and=20md=20entries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Markup for the git backend is implemented as a lookup table to commands that read markup on stdin and write it to stdout. Markdown uses lowdown, Org pandoc and HTML doesn't need to be altered. Future Work: - Title extraction from the files instead of the file name. Since we use the file name as ids in the git backend, it is currently impossible to change the title without breaking links. - Use emacs for Org. Unfortunately, it is really slow, so we may need to do something drastic, like writing an sourcegraph style markup conversion service or dumping an emacs image. - Copy post dependencies, e.g. included images. Change-Id: I88ad4cc18ada1d68d81fdecf685096f105e3fef3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/13110 Tested-by: BuildkiteCI Autosubmit: sterni Reviewed-by: sterni --- users/sterni/blërg/README.md | 12 ++++++++++-- users/sterni/blërg/blërg.bqn | 26 +++++++++++++++++++++----- users/sterni/blërg/default.nix | 4 +++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/users/sterni/blërg/README.md b/users/sterni/blërg/README.md index 70c286efc..552543c71 100644 --- a/users/sterni/blërg/README.md +++ b/users/sterni/blërg/README.md @@ -5,13 +5,21 @@ - [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][] - POSIX `printf(1)` (e.g. from GNU coreutils) +- `mail-notes` backend + - //users/sterni/mn2html + - [mblaze(7)][mblaze] +- `git` backend + - [git][] + - [lowdown][] for Markdown support + - [pandoc][] for Org Mode support [mblaze]: https://github.com/leahneukirchen/mblaze/ [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/ +[lowdown]: https://kristaps.bsd.lv/lowdown/ +[pandoc]: https://pandoc.org/ +[git]: https://git-scm.com/ diff --git a/users/sterni/blërg/blërg.bqn b/users/sterni/blërg/blërg.bqn index 593b3e29c..6b251cb75 100755 --- a/users/sterni/blërg/blërg.bqn +++ b/users/sterni/blërg/blërg.bqn @@ -42,6 +42,7 @@ LR ← Lines∘R GetEnv ← {R "importas"‿"env"‿𝕩‿"printf"‿"%s"‿"$env"} RelPath ← •wdpath⊸•file.At +Ext ← '.'⊸(⊑∘1⊸↑∘/∘(=∧∊∘⊢)↑⊢)⌾⌽ •file.Name # 3p dependencies @@ -79,27 +80,42 @@ MailNotesBackend ← {𝕊 config: # Git Backend +converters ← ⍉>⟨ +# TODO(sterni): avoid cat +⟨"html", ⋈"cat"⟩, +⟨"md", "lowdown"‿"-T"‿"html"‿"--html-no-skiphtml"‿"--html-no-escapehtml"‿"--html-callout-mdn"⟩, +# TODO(sterni): use emacs +⟨"org", "pandoc"‿"-f"‿"org"‿"-t"‿"html5"⟩, +⟩ + +# TODO(sterni): don't assemble blocks in this ad hoc fashion +# TODO(sterni): pipefail +PipelineCmd ← {"pipeline"⋈⊸∾(' '⊸∾¨𝕨)∾""⋈⊸∾𝕩} + GitBackend ← {𝕊 config: repo ← RelPath •file.At config j.ObjGet "repository" path ← ∾⟜'/' '/' StripRight config "." j._ObjGetDef "path" # We use zero separated fields when dealing with paths, so quoting is unnecessary - Git ← {R "git"‿"-c"‿"core.quotePath=false"‿"-C"‿repo∾𝕩} - rev ← Git "rev-parse"‿"HEAD" + GitCmd ← {"git"‿"-c"‿"core.quotePath=false"‿"-C"‿repo∾𝕩} + rev ← R GitCmd "rev-parse"‿"HEAD" # Use the author date of the latest commit on the file to establish the date # of the file. The author date is easier to arbitrarily change and survives # history rewrites. It could be interesting to ignore commits that touch # multiple files (especially treewide ones). - PathDate ← {ReadPosDec Git "log"‿"--date=unix"‿"--pretty=tformat:%ad"‿"-1"‿rev‿"--"‿𝕩} + PathDate ← {ReadPosDec R GitCmd "log"‿"--date=unix"‿"--pretty=tformat:%ad"‿"-1"‿rev‿"--"‿𝕩} Entries ⇐ {𝕤⋄ - blobs ← ∘‿2⥊@ SplitChar Git "ls-tree"‿"-zr"‿"--format=%(path)%x00%(objectname)"‿rev‿path + blobs ← ∘‿2⥊@ SplitChar R GitCmd "ls-tree"‿"-zr"‿"--format=%(path)%x00%(objectname)"‿rev‿path {𝕊 p‿b: id ⇐ Slugify path DropPrefix p # TODO(sterni): extract from file if possible title ⇐ •file.Name p time ⇐ PathDate p - Render ⇐ {𝕤 ⋄ {"
"∾𝕩∾"
"} Git "cat-file"‿"blob"‿b} + Render ⇐ {𝕤 + conv ← converters j.ObjGet Ext p + R (GitCmd "cat-file"‿"blob"‿b) PipelineCmd conv + } }˘blobs } } diff --git a/users/sterni/blërg/default.nix b/users/sterni/blërg/default.nix index 688253a0f..0dacf5e15 100644 --- a/users/sterni/blërg/default.nix +++ b/users/sterni/blërg/default.nix @@ -5,8 +5,10 @@ let runtimeDependencies = [ depot.users.sterni.mn2html pkgs.mblaze - pkgs.execline # execline-cd, importas + pkgs.execline # execline-cd, importas, pipeline # coreutils # for printf (assumed to be installed) + pkgs.pandoc + pkgs.lowdown ]; # … and this