makefile 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Environment vars
  2. DIST_DIR := dist
  3. DIR_OF_PROJECTS := src/projets
  4. # Computed vars
  5. SRC_HTMLS := $(shell find src -name '*.src.html')
  6. SRC_MDS := $(shell find src -name '*.src.md')
  7. SRC_TEMPLATES := $(shell find src/templates -name '*.html')
  8. SRC_LIST_YML := $(shell echo $(DIR_OF_PROJECTS)/*/*.meta.yml)
  9. GEN_HTMLS := $(SRC_HTMLS:%.src.html=%.gen.html)
  10. GEN_MDS := $(SRC_MDS:%.src.md=%.gen.html)
  11. GEN_LIST_YML := $(DIR_OF_PROJECTS)/list.gen.yml
  12. GEN_CONTENT_FILES := $(GEN_HTMLS) $(GEN_MDS)
  13. GEN_FILES := $(GEN_CONTENT_FILES) $(GEN_LIST_YML)
  14. INCLUDED_FILES := $(shell find src/include -type f)
  15. EMBEDDED_FILES := $(shell find src -name '*.png' -or -name '*.svg' -or -name '*.pdf')
  16. DIST_GEN_FILES := $(GEN_CONTENT_FILES:src/%.gen.html=$(DIST_DIR)/%.html)
  17. DIST_INC_FILES := $(INCLUDED_FILES:src/%=$(DIST_DIR)/%)
  18. DIST_EMB_FILES := $(EMBEDDED_FILES:src/%=$(DIST_DIR)/%)
  19. DIST_FILES := $(DIST_GEN_FILES) $(DIST_INC_FILES) $(DIST_DWN_FILES) $(DIST_EMB_FILES) $(DIST_DIR)/favicon.ico
  20. BUILD_VERSION := $(shell git describe)
  21. BUILD_DATE := $(shell date "+%F")
  22. PANDOC_GEN := pandoc --template src/templates/main.html --metadata-file src/meta.yml --metadata=build-date:$(BUILD_DATE) --metadata=build-version:$(BUILD_VERSION) --wrap=none
  23. LIST_GEN := yq eval-all '{"data": ., "target": {"content": filename | sub("meta.yml", "html") | sub(".*/", ""), "dir": filename | sub("$(DIR_OF_PROJECTS)/", "") | sub("/[^/]*.yml", "")}} as $$item ireduce ([]; . + $$item) | {"list": .}'
  24. # Functions
  25. extract_category = $(word 2, $(subst /, ,$(1)))
  26. extract_update_date = $(shell git log -1 --pretty="format:%cs" $(1))
  27. # Build
  28. .PHONY: build
  29. build: $(GEN_CONTENT_FILES)
  30. $(info HTML generated)
  31. %.gen.html: %.src.html %.meta.yml $(SRC_TEMPLATES)
  32. $(PANDOC_GEN) --metadata-file $*.meta.yml --metadata=category-$(call extract_category,$*) --metadata=update-date:$(call extract_update_date,$<) --output $@ $<
  33. %.gen.html: %.src.md %.meta.yml $(SRC_TEMPLATES)
  34. $(PANDOC_GEN) --metadata-file $*.meta.yml --metadata=category-$(call extract_category,$*) --metadata=update-date:$(call extract_update_date,$<) --output $@ $<
  35. # Build lists
  36. $(GEN_LIST_YML): $(SRC_LIST_YML)
  37. $(LIST_GEN) $(SRC_LIST_YML) > $@
  38. $(DIR_OF_PROJECTS)/content.gen.html: $(DIR_OF_PROJECTS)/content.src.html $(DIR_OF_PROJECTS)/content.meta.yml $(GEN_LIST_YML) $(SRC_TEMPLATES)
  39. $(PANDOC_GEN) --metadata-file $(DIR_OF_PROJECTS)/content.meta.yml --metadata-file $(GEN_LIST_YML) --metadata=category-projets --metadata=update-date:$(call extract_update_date,$<) --output $@ $<
  40. # Distribution
  41. .PHONY: install
  42. install: $(DIST_DIR)
  43. $(info Distributed folder generated)
  44. $(DIST_DIR): $(DIST_FILES)
  45. $(DIST_DIR)/%.html: src/%.gen.html
  46. mkdir --parents $(dir $@)
  47. cp $< $@
  48. $(DIST_DIR)/%: src/%
  49. mkdir --parents $(dir $@)
  50. cp $< $@
  51. # Cleaning
  52. .PHONY: clean
  53. clean:
  54. rm -f $(GEN_FILES)
  55. .PHONY: clean-dist
  56. clean-dist:
  57. rm -rf $(DIST_DIR)/*
  58. .PHONY: clean-all
  59. clean-all: clean clean-dist
  60. .PHONY: debug
  61. debug:
  62. $(info SRC_HTMLS $(SRC_HTMLS))
  63. $(info SRC_MDS $(SRC_MDS))
  64. $(info SRC_TEMPLATES $(SRC_TEMPLATES))
  65. $(info GEN_HTMLS $(GEN_HTMLS))
  66. $(info GEN_MDS $(GEN_MDS))
  67. $(info GEN_FILES $(GEN_FILES))
  68. $(info GEN_CONTENT_FILES $(GEN_CONTENT_FILES))
  69. $(info INCLUDED_FILES $(INCLUDED_FILES))
  70. $(info EMBEDDED_FILES $(EMBEDDED_FILES))
  71. $(info DIST_FILES $(DIST_FILES))