feat(sterni/blërg/git): render html, org and md entries
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 <sternenseemann@systemli.org> Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
09c0d75bf9
commit
5cd3d9e3ac
3 changed files with 34 additions and 8 deletions
|
|
@ -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/
|
||||
|
|
|
|||
|
|
@ -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 ⇐ {𝕤 ⋄ {"<pre>"∾𝕩∾"</pre>"} Git "cat-file"‿"blob"‿b}
|
||||
Render ⇐ {𝕤
|
||||
conv ← converters j.ObjGet Ext p
|
||||
R (GitCmd "cat-file"‿"blob"‿b) PipelineCmd conv
|
||||
}
|
||||
}˘blobs
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue