129 lines
4.0 KiB
Makefile
129 lines
4.0 KiB
Makefile
SOURCE_FOLDER := sources
|
||
DOCUMENTS_FOLDER := $(SOURCE_FOLDER)/documents
|
||
SLIDES_FOLDER := $(SOURCE_FOLDER)/slides
|
||
OUTPUT_FILENAME := document
|
||
SLIDES_OUTPUT_FOLDER := présentations
|
||
|
||
TEMPLATE_REPOSITORY := https://git.milhit.ch/igor/bunige-pagedjs-template/releases/download
|
||
|
||
# Liste les fichiers sources.
|
||
MD_UNSORTED := $(wildcard $(DOCUMENTS_FOLDER)/*.md)
|
||
# Ordonne les fichiers sources sur la base du début numérique du nom des
|
||
# fichiers.
|
||
MD_SORTED := $(shell printf '%s\n' $(MD_UNSORTED) | sort -t- -k1,1n)
|
||
|
||
# Sources pour les slides
|
||
SLIDES_SOURCES := $(wildcard $(SLIDES_FOLDER)/*.md)
|
||
SLIDES_TARGETS := $(patsubst $(SLIDES_FOLDER)/%.md,$(SLIDES_OUTPUT_FOLDER)/%.html,$(SLIDES_SOURCES))
|
||
SLIDES_BASENAMES := $(basename $(notdir $(SLIDES_SOURCES)))
|
||
|
||
.PHONY: all
|
||
all: pdf slides
|
||
|
||
# Construit le fichier HTML.
|
||
.PHONY: html
|
||
html: $(MD_SORTED)
|
||
pandoc \
|
||
--to=html --standalone \
|
||
--template=static/template.html --css=static/style.css \
|
||
-V static='./static' \
|
||
--toc --toc-depth=2 \
|
||
--out=$(OUTPUT_FILENAME).html $(MD_SORTED)
|
||
|
||
# Construit le fichier PDF.
|
||
.PHONY: pdf
|
||
pdf: $(MD_SORTED)
|
||
pandoc \
|
||
--to=pdf --pdf-engine=pagedjs-cli --embed-resources=true \
|
||
--template=static/template.html --css=static/style.css \
|
||
-V noscript=true -V static='./static' \
|
||
--toc --toc-depth=2 \
|
||
--out=$(OUTPUT_FILENAME).pdf $(MD_SORTED)
|
||
|
||
# Construit les slides
|
||
$(SLIDES_OUTPUT_FOLDER)/%.html: $(SLIDES_FOLDER)/%.md
|
||
@mkdir -p $(SLIDES_OUTPUT_FOLDER)
|
||
pandoc --to=revealjs --standalone --embed-resources \
|
||
--template=présentations/revealjs-template.html \
|
||
--css=dist/theme/bunige.css \
|
||
--slide-level=2 \
|
||
--output=$@ $<
|
||
|
||
.PHONY: slides
|
||
slides: $(SLIDES_TARGETS)
|
||
|
||
# Génération d'une présentation spécifique
|
||
.PHONY: slide-%
|
||
slide-%: $(SLIDES_OUTPUT_FOLDER)/%.html
|
||
@echo "Présentation $* générée dans $(SLIDES_OUTPUT_FOLDER)/"
|
||
|
||
# Watch amélioré pour les slides
|
||
.PHONY: watch_slides
|
||
watch_slides:
|
||
watchexec -r -w $(SLIDES_FOLDER) -f "*.md" \
|
||
-i "$(SLIDES_OUTPUT_FOLDER)/*.html" \
|
||
-- make slides
|
||
|
||
# Template pour générer les cibles de watch spécifiques
|
||
define WATCH_SLIDE_TEMPLATE
|
||
.PHONY: watch-slide-$(1)
|
||
watch-slide-$(1):
|
||
@echo "Surveillance de $(1).md..."
|
||
watchexec -r -w $(SLIDES_FOLDER)/$(1).md \
|
||
-i "$(SLIDES_OUTPUT_FOLDER)/$(1).html" \
|
||
-- make slide-$(1)
|
||
endef
|
||
|
||
# Génération automatique des cibles de watch
|
||
$(foreach slide,$(SLIDES_BASENAMES),$(eval $(call WATCH_SLIDE_TEMPLATE,$(slide))))
|
||
|
||
# Reconstruit le fichier HTML à la modification des autres fichiers.
|
||
.PHONY: watch
|
||
watch:
|
||
watchexec -r -w . -i document.html \
|
||
-- make html
|
||
|
||
# Supprime les fichiers construits lorsqu'ils ne sont plus nécessaire.
|
||
.PHONY: clean
|
||
clean:
|
||
rm -f *.html *.pdf
|
||
|
||
# Lance un serveur web pour servir le HTML.
|
||
.PHONY: serve
|
||
serve:
|
||
watchexec -r -w . "python -m http.server"
|
||
|
||
# Mets à jour le modèle de document
|
||
# Usage : make update VERSION=v1.0.0
|
||
.PHONY: update
|
||
update:
|
||
curl -o modèle.zip $(TEMPLATE_REPOSITORY)/$(VERSION)/$(VERSION).zip
|
||
unzip -f -o modèle.zip
|
||
rm modèle.zip
|
||
|
||
# Aide
|
||
.PHONY: help
|
||
help:
|
||
@echo "Cibles disponibles :"
|
||
@echo " all - Génère le PDF et toutes les présentations."
|
||
@echo " pdf - Génère le document PDF."
|
||
@echo " html - Génère le document HTML."
|
||
@echo " slides - Génère toutes les présentations."
|
||
@echo " slide-<filename> - Génère une présentation spécifique."
|
||
@echo " watch - Surveille les changements du document."
|
||
@echo " watch-slides - Surveille tous les fichiers slides."
|
||
@echo " watch-slide-<filename> - Surveille une présentation spécifique."
|
||
@echo " debug - Vérifie la contenu de certaines variables."
|
||
@echo " clean - Supprime les fichiers générés."
|
||
@echo ""
|
||
@echo "Documents détectés : $(notdir $(MD_SORTED))"
|
||
@echo "Présentations détectées : $(SLIDES_BASENAMES)"
|
||
|
||
.PHONY: debug
|
||
debug:
|
||
@echo "MD_UNSORTED: $(MD_UNSORTED)"
|
||
@echo "MD_SORTED: $(MD_SORTED)"
|
||
@echo "SLIDES_SOURCES: $(SLIDES_SOURCES)"
|
||
@echo "SLIDES_BASENAMES: $(SLIDES_BASENAMES)"
|
||
|