aboutsummaryrefslogtreecommitdiff
path: root/_make/hedgedoc.mk
blob: 62844af498684f413c9d3f6ea381a7963a7273b9 (plain)
  1. # Make snippet for exchanging data with a HedgeDoc pad
  2. #
  3. # Copyright 2024, Jonas Smedegaard <dr@jones.dk>
  4. # SPDX-License-Identifier: GPL-3+
  5. #
  6. # Setup:
  7. # in main Makefile...
  8. # * set variable PAD_LIST
  9. # * set variable PAD_REPLACE if supported and wanted
  10. # * include this make snippet
  11. #
  12. # Dependencies:
  13. # * hedgedoc <https://github.com/hedgedoc/cli>
  14. # * perl v5.36 or newer
  15. # whitespace-delimited list of file-URI pairs,
  16. # each consisting of a relative path to a local file
  17. # and a relative URI to a HedgeDoc pad,
  18. # separated by a colon
  19. #PAD_LIST = \
  20. # README.md:Xg5jgtkWQNqRzobI0qwrtw \
  21. # our_project/subdir/foo.data:XxgHj9yCQ_e6bsETro5DMA
  22. # when set to a non-empty value (and HedgeDoc service supports it),
  23. # importing from local file will attempt to replace existing pad,
  24. # instead of creating a new pad
  25. #PAD_REPLACE = yes
  26. # resolve files and URIs from PAD_LIST
  27. _PADFILES = $(foreach i,$(PAD_LIST),$(firstword $(subst :,$() ,$i)))
  28. _padfile2uri = $(patsubst $1:%,%,$(filter $1:%,$(PAD_LIST)))
  29. # register with HedgeDoc service
  30. pad-login:
  31. hedgedoc login --email
  32. # list available pads at HedgeDoc service
  33. pad-list:
  34. hedgedoc history
  35. pad-export-all: $(_PADFILES:%=pad-export-to-%)
  36. # export from pad to local file, and ensure it ends with a newline
  37. # for *.md files, strip YAML preamble
  38. $(_PADFILES:%=pad-export-to-%): pad-export-to-%:
  39. $(if $(wildcard $(dir $*)),,mkdir --parents $(dir $*))
  40. hedgedoc export --md $(call _padfile2uri,$*) $*
  41. perl -gpi -e 's/\s*\z/\n/' $*
  42. $(if $(filter %.md,$*),perl -gpi -e 's/^\s*---\n.*?\n---\n+//sm' $*)
  43. $(_PADFILES:%=pad-import-from-%): pad-import-from-%: %
  44. hedgedoc import $< $(if $(PAD_WANTED),$(call _padfile2uri,$*))
  45. .PHONY: pad-login pad-list pad-export-all $(_PADFILES:%=pad-export-to-%) $(_PADFILES:%=pad-import-from-%)