summaryrefslogtreecommitdiff
path: root/Makefile
blob: 6109d8fd5449e9b1d7a113535ba8bee91581b472 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Pandoc-SSP https://github.com/infologie/pandoc-ssp/
# by Arthur Perret https://www.arthurperret.fr
# custom by Roch Delannay https://github.com/RochDLY/pandoc-site

########################VARIABLES##############################

POSTS := $(sort $(shell find src/posts -type f -iname '*.md'))
POSTS_DOCS := $(patsubst %.md, docs/posts/%.html, $(notdir $(POSTS)))

PAGES := $(sort $(shell find src/pages -type f -iname '*.md'))
PAGES_DOCS := $(patsubst %.md, docs/pages/%.html, $(notdir $(PAGES)))

# Copy static files recursively :
# (Adapted from https://stackoverflow.com/questions/41993726/)
STATIC := $(shell find static -type f)
STATIC_DOCS := $(patsubst static/%, docs/%, $(STATIC))
$(foreach s,$(STATIC),$(foreach t,$(filter %$(notdir $s),$(STATIC_DOCS)),$(eval $t: $s)))
$(STATIC_DOCS):; $(if $(wildcard $(@D)),,mkdir -p $(@D) &&) cp $^ $@

references = src/bibliography/references.bib
csl_file = templates/csl/apa.csl
metadata_site = src/metadata.yml

PANDOCFLAGS = \
	--from markdown \
	--to html \
	--standalone \
	--citeproc \
	--wrap none \
	--bibliography $(references) \
	--metadata-file $(metadata_site) \
	--csl $(csl_file)


#############################COMMANDS###########################


.PHONY: all html clean #pdf

all: clean html serve #pdf

clean:
	@ rm -rf docs/*

serve:
	@ python3 -m http.server -d docs/

# Pandoc conversions
# HTML
html: $(STATIC_DOCS) docs/index.html docs/index-cache.html $(POSTS_DOCS) $(PAGES_DOCS)

docs/index-cache.html: src/index-cache.md templates/index.html $(metadata_site)
	@ echo "Production de l'index caché."
	@ pandoc \
  	$< \
		$(PANDOCFLAGS) \
		--template templates/index-cache.html \
		--output $@
	@ echo "L'index caché est construit."


docs/index.html: src/index.md templates/index.html $(metadata_site)
	@ echo "Production de l'index."
	@ pandoc \
  	$< \
		$(PANDOCFLAGS) \
		--template templates/index.html \
		--output $@
	@ echo "L'index est construit."

docs/pages/%.html: src/pages/%.md $(metadata_site) templates/page.html
	@ mkdir -p "$(@D)"
	@ echo "Production de la page \"$@\"..."
	@ pandoc \
  	$< \
		$(PANDOCFLAGS) \
		--template templates/page.html \
		--output $@
	@ echo "La page \"$@\" est construite."
	

docs/posts/%.html: src/posts/%.md $(metadata_site) templates/post.html
	@ mkdir -p "$(@D)"
	@ echo "Production du billet \"$@\"..."
	@ pandoc \
  	$< \
		$(PANDOCFLAGS) \
		--template templates/post.html \
		--table-of-content \
		--output $@
	@ echo "Le billet \"$@\" est construit."

# PDF
#pdf: docs/these.pdf

#docs/these.pdf: src/introduction.md $(POSTS) src/conclusion.md
#	pandoc $^ [options] -o docs/these.pdf



##########################SOUS-RECETTES############################

# Actuellement les recettes ne dépendent que des fichiers sources.
# Si on modifie un template, le site n'est pas recompilé.
# Pour ça il faut créer des sous-recettes pour indiquer les dépendances
# des pages aux templates

# sous-recette pour le template des posts
posts-partials = \
	templates/partials/footer.html \
	templates/partials/head.html \
	templates/partials/header.html \
	templates/partials/nav.html

templates/post.html: $(posts-partials)
	@ touch $@

# sous-recette pour le template de l'index
index-partials = \
	templates/partials/footer.html \
	templates/partials/head.html \
	templates/partials/header.html \
	templates/partials/nav.html

templates/index.html: $(index-partials)
	@ touch $@

templates/index-cache.html: $(index-partials)
	@ touch $@

pages-partials = \
	templates/partials/footer.html \
	templates/partials/head.html \
	templates/partials/header.html \
	templates/partials/nav.html

templates/page.html: $(pages-partials)
	@ touch $@