aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-05-11 15:41:02 +0200
committerJonas Smedegaard <dr@jones.dk>2025-05-11 15:41:02 +0200
commit89be4eee2947c882c9b272e1a4fca9832e84b107 (patch)
tree1a84e544a3fd9bddda4c43f8bb55d72874832126
parentbe84dc0995d3c79f9ee901669abcbd066a6650de (diff)
add makefile to fetch live document
-rw-r--r--Makefile7
-rw-r--r--_make/hedgedoc.mk52
2 files changed, 59 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a1673b3
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,7 @@
+PAD_LIST = README.md:KtR5fUhXRuS_XnNEo_gpow
+
+# config hints used by helper script hedgedoc
+export HEDGEDOC_SERVER = https://hackmd.io/
+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..88c8936
--- /dev/null
+++ b/_make/hedgedoc.mk
@@ -0,0 +1,52 @@
+# Make snippet for exchanging data with a HedgeDoc pad
+#
+# Copyright 2024, Jonas Smedegaard <dr@jones.dk>
+# 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 <https://github.com/hedgedoc/cli>
+# * 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-%)