You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. # Generate my website out of org-mode/gemini files
  2. all: site
  3. SRC_DIR ?= src
  4. DST_DIR ?= _site
  5. CACHE_DIR ?= .cache
  6. # we don't want to publish files in drafts
  7. NO_DRAFT := -not -path '$(SRC_DIR)/drafts/*'
  8. # we don't copy source files
  9. NO_SRC_FILE := ! -name '*.org'
  10. # Prevent path/nix bugs
  11. ENV_VARS := ./engine/envvars.sh
  12. NIX_FILES := ./shell.nix $(shell find nix -type f)
  13. $(ENV_VARS): $(NIX_FILES)
  14. $(info Build ${ENV_VARS})
  15. @echo "export PATH=\"${PATH}\"" >> ./engine/envvars.sh
  16. .PHONY: envvars
  17. envvars: $(ENV_VARS)
  18. ALL += envvars
  19. # ASSETS
  20. SRC_RAW_FILES := $(shell find $(SRC_DIR) -type f $(NO_DRAFT) $(NO_SRC_FILE))
  21. DST_RAW_FILES := $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%,$(SRC_RAW_FILES))
  22. $(DST_DIR)/%: $(SRC_DIR)/% $(ENV_VARS)
  23. @mkdir -p "$(dir $@)"
  24. cp "$<" "$@"
  25. .PHONY: assets
  26. assets: $(DST_RAW_FILES)
  27. ALL += assets
  28. # CSS
  29. SRC_CSS_FILES := $(shell find $(SRC_DIR) -type f -name '*.css')
  30. DST_CSS_FILES := $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%,$(SRC_RAW_FILES))
  31. $(DST_DIR)/%.css: $(SRC_DIR)/%.css $(ENV_VARS)
  32. @mkdir -p "$(dir $@)"
  33. minify "$<" > "$@"
  34. css: $(DST_CSS_FILES)
  35. ALL += css
  36. # ORG -> HTML
  37. EXT ?= .org
  38. SRC_PANDOC_FILES ?= $(shell find $(SRC_DIR) -type f -name "*$(EXT)" $(NO_DRAFT))
  39. DST_PANDOC_FILES ?= $(patsubst %$(EXT),%.html, \
  40. $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%, \
  41. $(SRC_PANDOC_FILES)))
  42. PANDOC_TEMPLATE ?= templates/post.html
  43. PANDOC_LUA_FILTER ?= engine/links-to-html.lua
  44. MK_HTML := engine/mk-html.sh
  45. PANDOC := $(MK_HTML) $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER)
  46. $(DST_DIR)/%.html: $(SRC_DIR)/%.org $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER) $(MK_HTML) $(ENV_VARS)
  47. @mkdir -p "$(dir $@)"
  48. $(PANDOC) "$<" "$@.tmp"
  49. minify --mime text/html "$@.tmp" > "$@"
  50. @rm "$@.tmp"
  51. .PHONY: html
  52. html: $(DST_PANDOC_FILES)
  53. ALL += html
  54. # INDEXES
  55. SRC_POSTS_DIR ?= $(SRC_DIR)/posts
  56. DST_POSTS_DIR ?= $(DST_DIR)/posts
  57. SRC_POSTS_FILES ?= $(shell find $(SRC_POSTS_DIR) -type f -name "*$(EXT)")
  58. RSS_CACHE_DIR ?= $(CACHE_DIR)/rss
  59. DST_XML_FILES ?= $(patsubst %.org,%.xml, \
  60. $(patsubst $(SRC_POSTS_DIR)/%,$(RSS_CACHE_DIR)/%, \
  61. $(SRC_POSTS_FILES)))
  62. $(RSS_CACHE_DIR)/%.xml: $(DST_POSTS_DIR)/%.html $(ENV_VARS)
  63. @mkdir -p "$(dir $@)"
  64. hxclean "$<" > "$@"
  65. .PHONY: indexcache
  66. indexcache: $(DST_XML_FILES)
  67. ALL += indexcache
  68. # HTML INDEX
  69. DST_INDEX_FILES ?= $(patsubst %.xml,%.index, $(DST_XML_FILES))
  70. MK_INDEX_ENTRY := ./engine/mk-index-entry.sh
  71. INDEX_CACHE_DIR ?= $(CACHE_DIR)/rss
  72. $(INDEX_CACHE_DIR)/%.index: $(INDEX_CACHE_DIR)/%.xml $(MK_INDEX_ENTRY) $(ENV_VARS)
  73. @mkdir -p $(INDEX_CACHE_DIR)
  74. $(MK_INDEX_ENTRY) "$<" "$@"
  75. HTML_INDEX := $(DST_DIR)/index.html
  76. MKINDEX := engine/mk-index.sh
  77. INDEX_TEMPLATE ?= templates/index.html
  78. $(HTML_INDEX): $(DST_INDEX_FILES) $(MKINDEX) $(INDEX_TEMPLATE) $(ENV_VARS)
  79. @mkdir -p $(DST_DIR)
  80. $(MKINDEX)
  81. .PHONY: index
  82. index: $(HTML_INDEX)
  83. ALL += index
  84. # RSS
  85. DST_RSS_FILES ?= $(patsubst %.xml,%.rss, $(DST_XML_FILES)) $(ENV_VARS)
  86. MK_RSS_ENTRY := ./engine/mk-rss-entry.sh
  87. $(RSS_CACHE_DIR)/%.rss: $(RSS_CACHE_DIR)/%.xml $(MK_RSS_ENTRY)
  88. @mkdir -p $(RSS_CACHE_DIR)
  89. $(MK_RSS_ENTRY) "$<" "$@"
  90. RSS := $(DST_DIR)/rss.xml
  91. MKRSS := engine/mkrss.sh
  92. $(RSS): $(DST_RSS_FILES) $(MKRSS) $(ENV_VARS)
  93. $(MKRSS)
  94. .PHONY: rss
  95. rss: $(RSS)
  96. ALL += rss
  97. # ORG -> GEMINI
  98. EXT := .org
  99. SRC_GMI_FILES ?= $(shell find $(SRC_DIR) -type f -name "*$(EXT)" $(NO_DRAFT))
  100. DST_GMI_FILES ?= $(subst $(EXT),.gmi, \
  101. $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%, \
  102. $(SRC_GMI_FILES)))
  103. GMI := engine/org2gemini.sh
  104. $(DST_DIR)/%.gmi: $(SRC_DIR)/%.org $(GMI) engine/org2gemini_step1.sh
  105. @mkdir -p $(dir $@)
  106. $(GMI) "$<" "$@"
  107. ALL += $(DST_GMI_FILES)
  108. .PHONY: gmi
  109. gmi: $(DST_GMI_FILES)
  110. # GEMINI INDEX
  111. GMI_INDEX := $(DST_DIR)/index.gmi
  112. MK_GMI_INDEX := engine/mk-gemini-index.sh
  113. $(GMI_INDEX): $(DST_GMI_FILES) $(MK_GMI_INDEX) $(ENV_VARS)
  114. @mkdir -p $(DST_DIR)
  115. $(MK_GMI_INDEX)
  116. ALL += $(GMI_INDEX)
  117. .PHONY: gmi-index
  118. gmi-index: $(GMI_INDEX)
  119. # RSS
  120. GEM_ATOM := $(DST_DIR)/gem-atom.xml
  121. MK_GEMINI_ATOM := engine/mk-gemini-atom.sh
  122. $(GEM_ATOM): $(DST_GMI_FILES) $(MK_GEMINI_ATOM)
  123. $(MK_GEMINI_ATOM)
  124. ALL += $(GEM_ATOM)
  125. .PHONY: gmi-atom
  126. gmi-atom: $(GMI_ATOM)
  127. .PHONY: gemini
  128. gemini: $(DST_GMI_FILES) $(GMI_INDEX) $(GEM_ATOM)
  129. # Images
  130. SRC_IMG_FILES ?= $(shell find $(SRC_DIR) -type f -name "*.jpg" -or -name "*.jpeg" -or -name "*.gif" -or -name "*.png")
  131. DST_IMG_FILES ?= $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%, $(SRC_IMG_FILES))
  132. OPTIM_IMG := engine/optim-img.sh
  133. $(DST_DIR)/%.jpg: $(SRC_DIR)/%.jpg $(OPTIM_IMG)
  134. @mkdir -p $(dir $@)
  135. $(OPTIM_IMG) "$<" "$@"
  136. $(DST_DIR)/%.jpg: $(SRC_DIR)/%.jpeg $(OPTIM_IMG)
  137. @mkdir -p $(dir $@)
  138. $(OPTIM_IMG) "$<" "$@"
  139. $(DST_DIR)/%.gif: $(SRC_DIR)/%.gif $(OPTIM_IMG)
  140. @mkdir -p $(dir $@)
  141. $(OPTIM_IMG) "$<" "$@"
  142. $(DST_DIR)/%.png: $(SRC_DIR)/%.png $(OPTIM_IMG)
  143. @mkdir -p $(dir $@)
  144. $(OPTIM_IMG) "$<" "$@"
  145. .PHONY: img
  146. img: $(DST_IMG_FILES)
  147. ALL += $(DST_IMG_FILES)
  148. # DEPLOY
  149. .PHONY: site
  150. site: $(ALL)
  151. .PHONY: deploy
  152. deploy: $(ALL)
  153. engine/sync.sh # deploy to her.esy.fun
  154. engine/ye-com-fastpublish.hs # deploy to yannesposito.com (via github pages)
  155. .PHONY: clean
  156. clean:
  157. -[ -f $(ENV_VARS) ] && rm $(ENV_VARS)
  158. -[ ! -z "$(DST_DIR)" ] && rm -rf $(DST_DIR)/*
  159. -[ ! -z "$(CACHE_DIR)" ] && rm -rf $(CACHE_DIR)/*