summaryrefslogtreecommitdiff
path: root/_make/hedgedoc.mk
blob: 7ae31b7913c904679d9793d6eed4480dc14db052 (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. # * set variable PAD_LIST
  8. # * set variable PAD_REPLACE if supported and wanted
  9. # * include this make snippet
  10. #
  11. # whitespace-delimited list of file-URI pairs,
  12. # each consisting of a relative path to a local file
  13. # and a relative URI to a HedgeDoc pad,
  14. # separated by a colon.
  15. #PAD_LIST = \
  16. # README.md:Xg5jgtkWQNqRzobI0qwrtw \
  17. # our_project/subdir/foo.data:XxgHj9yCQ_e6bsETro5DMA
  18. #
  19. # when set to a non-empty value (and HedgeDoc service supports it),
  20. # importing from local file will attempt to replace existing pad,
  21. # instead of creating a new pad
  22. #PAD_REPLACE = yes
  23. #
  24. # Dependencies:
  25. # * hedgedoc <https://github.com/hedgedoc/cli>
  26. # * perl v5.36 or newer
  27. # resolve files and URIs from PADLIST
  28. _PADFILES = $(foreach i,$(PADLIST),$(firstword $(subst :,$() ,$i)))
  29. _padfile2uri = $(patsubst $1:%,%,$(filter $1:%,$(PADLIST)))
  30. # register with HedgeDoc service
  31. pad-login:
  32. hedgedoc login --email
  33. # list available pads at HedgeDoc service
  34. pad-list:
  35. hedgedoc history
  36. pad-export-all: $(_PADFILES:%=pad-export-to-%)
  37. # export from pad to local file, and ensure it ends with a newline
  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. $(_PADFILES:%=pad-import-from-%): pad-import-from-%: %
  43. hedgedoc import $< $(if $(PAD_WANTED),$(call _padfile2uri,$*))
  44. .PHONY: pad-login pad-list pad-export-all $(_PADFILES:%=pad-export-to-%) $(_PADFILES:%=pad-import-from-%)