From 89be4eee2947c882c9b272e1a4fca9832e84b107 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 11 May 2025 15:41:02 +0200 Subject: add makefile to fetch live document --- _make/hedgedoc.mk | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 _make/hedgedoc.mk (limited to '_make') diff --git a/_make/hedgedoc.mk b/_make/hedgedoc.mk new file mode 100644 index 0000000..88c8936 --- /dev/null +++ b/_make/hedgedoc.mk @@ -0,0 +1,52 @@ +# Make snippet for exchanging data with a HedgeDoc pad +# +# Copyright 2024, Jonas Smedegaard +# SPDX-License-Identifier: GPL-3+ +# +# Setup: +# in main Makefile... +# * set variable PAD_LIST +# * set variable PAD_REPLACE if supported and wanted +# * include this make snippet +# +# Dependencies: +# * hedgedoc +# * perl v5.36 or newer + +# 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 + +# resolve files and URIs from PAD_LIST +_PADFILES = $(foreach i,$(PAD_LIST),$(firstword $(subst :,$() ,$i))) +_padfile2uri = $(patsubst $1:%,%,$(filter $1:%,$(PAD_LIST))) + +# 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-%) -- cgit v1.2.3