diff options
author | Jonas Smedegaard <dr@jones.dk> | 2024-09-15 11:36:10 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2024-09-15 11:36:10 +0200 |
commit | c2f85c284b81c3aabe7f4fa9794f72c6dade4b4a (patch) | |
tree | 92b07ffb1be42f4cec7b7648a1d6e0cbf8260fe0 | |
parent | d6f7d263731095824440499d3ac86a29de1ee115 (diff) |
setup make rules to handle HedgeDoc
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | _make/hedgedoc.mk | 51 |
3 files changed, 60 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ed12ce --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/_hedgedoc/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bdc5983 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +PADLIST = \ + _NOTES.qmd:bp3data + +# config hints used by helper script hedgedoc +export HEDGEDOC_SERVER = https://pad.degrowth.net/ +export HEDGEDOC_CONFIG_DIR = $(CURDIR)/_hedgedoc + +include _make/*.mk diff --git a/_make/hedgedoc.mk b/_make/hedgedoc.mk new file mode 100644 index 0000000..7ae31b7 --- /dev/null +++ b/_make/hedgedoc.mk @@ -0,0 +1,51 @@ +# Make snippet for exchanging data with a HedgeDoc pad +# +# Copyright 2024, Jonas Smedegaard <dr@jones.dk> +# SPDX-License-Identifier: GPL-3+ +# +# Setup: +# * set variable PAD_LIST +# * set variable PAD_REPLACE if supported and wanted +# * include this make snippet +# +# whitespace-delimited list of file-URI pairs, +# each consisting of a relative path to a local file +# and a relative URI to a HedgeDoc pad, +# separated by a colon. +#PAD_LIST = \ +# README.md:Xg5jgtkWQNqRzobI0qwrtw \ +# our_project/subdir/foo.data:XxgHj9yCQ_e6bsETro5DMA +# +# when set to a non-empty value (and HedgeDoc service supports it), +# importing from local file will attempt to replace existing pad, +# instead of creating a new pad +#PAD_REPLACE = yes +# +# Dependencies: +# * hedgedoc <https://github.com/hedgedoc/cli> +# * perl v5.36 or newer + +# resolve files and URIs from PADLIST +_PADFILES = $(foreach i,$(PADLIST),$(firstword $(subst :,$() ,$i))) +_padfile2uri = $(patsubst $1:%,%,$(filter $1:%,$(PADLIST))) + +# register with HedgeDoc service +pad-login: + hedgedoc login --email + +# list available pads at HedgeDoc service +pad-list: + hedgedoc history + +pad-export-all: $(_PADFILES:%=pad-export-to-%) + +# export from pad to local file, and ensure it ends with a newline +$(_PADFILES:%=pad-export-to-%): pad-export-to-%: + $(if $(wildcard $(dir $*)),,mkdir --parents $(dir $*)) + hedgedoc export --md $(call _padfile2uri,$*) $* + perl -gpi -e 's/\s*\z/\n/' $* + +$(_PADFILES:%=pad-import-from-%): pad-import-from-%: % + hedgedoc import $< $(if $(PAD_WANTED),$(call _padfile2uri,$*)) + +.PHONY: pad-login pad-list pad-export-all $(_PADFILES:%=pad-export-to-%) $(_PADFILES:%=pad-import-from-%) |