summaryrefslogtreecommitdiff
path: root/Makefile
blob: ec330824d69711bf5214d9181c5ce7feaa043431 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

MD_CMD=npx remark --rc-path remarkrc
# pup is from github.com/ericchiang/pup
CATCH_CMD=pup
HTML_MINIFIER_CMD=htmlmin
BASE_HTML=tmp/left.htm tmp/headers.htm
ALL_ARTICLES=$(wildcard articles/*.md)
ALL_ARTICLES_OUT=$(ALL_ARTICLES:.md=.html)
ALL_ARTICLES_INTRO_OUT=$(addprefix articles/tmp/,$(shell cat articles_intro_out))
ALL_NOTES_OUT=$(addprefix notes/,$(shell cat notes/notes_out))
ALL_NOTES_TMP=$(addprefix notes/tmp/,$(shell cat notes/notes_out))
ALL_NOTES_TMP_OUT=$(ALL_NOTES_TMP:.html=.hml)
ALL_NOTES_CARDS_OUT=$(ALL_NOTES_TMP:.html=_card.htm)

SCRIPT_JS=s/js/main.js
SHEET_CSS=s/css/style.css


# Creation des articles, puis des bases et enfin de l'index
# 	Les bases en premiers
# 	Puis les articles
# 	Et enfin index (qui possède une liste des introductions des articles)
all: $(ALL_ARTICLES_OUT) $(BASE_HTML) index.html contact/index.html $(SHEET_CSS) $(SCRIPT_JS) $(ALL_NOTES_OUT) notes/index.html
.PHONY: all

# > Création des articles depuis le markdown
# 	On compile le fichier md vers html (tmp/%.htm)
# 	On rajoute les headers (tmp/%_header.htm)
# 	On fini d'ajouter le squelette HTML (articles/%.html
articles/%.html: articles/%.md $(BASE_HTML) headers.m4 articles/article.m4
	@echo "> Création des articles"
	mkdir -p articles/tmp
	cat $< | $(MD_CMD) > $(addprefix articles/tmp/,$(notdir $(@:.html=.htm)))
	m4 -D TITLE_TITLE="`echo Licornes, hérissons et renards`" headers.m4  > $(addprefix articles/tmp/,$(notdir $(basename $@)_header.htm))
	m4 -D tmpFileNameArticle=$(addprefix articles/tmp/,$(notdir $(@:.html=.htm))) -D linkFileNameArticle=$(<:.md=) -D HEADER_HEADER=$(addprefix articles/tmp/,$(notdir $(basename $@)_header.htm)) -D CANONIC="https://ache.one/$@" articles/article.m4 | $(HTML_MINIFIER_CMD) > $@

# > Création des introductions des articles
# 	On conserve le titre principale (dans tmp/%_intro.htm)
# 	On y ajoute les deux premiers paragraphe (tmp/%_intro.html)
#
articles/tmp/%_intro.html: articles/%.html articles/intro.m4
	@echo "> Création des introductions d'articles"
	mkdir -p articles/tmp
	@cat $< | $(CATCH_CMD) "h1" > $(@:.html=.htm)
	@cat $< | $(CATCH_CMD) "h1 + p" | sed 's/res\//articles\/res\//' >> $(@:.html=.htm)
	m4 -D tmpFileNameArticle=$(@:.html=.htm) -D linkFileNameArticle=$(<:.html=) articles/intro.m4 > $@


# > Création de la liste des introductions d'articles pour la page principale
# 	On assemble juste les introductions d'articles ensemble
tmp/articles.htm: $(ALL_ARTICLES_INTRO_OUT) articles_intro_out
	@echo "> Création de la liste des introductions d'articles"
	mkdir -p tmp
	cat $(ALL_ARTICLES_INTRO_OUT) > $@

#####################################################################
####			NOTES
#####################################################################

notes/index.html: notes/tmp/index.htm notes/tmp/notes_cards.htm
# 	On rajoute les headers (tmp/%_header.htm)
# 	On fini d'ajouter le squelette HTML (notes/%.html
notes/%.html: notes/tmp/%.htm notes/tmp/notes_cards.htm
	@echo "> Création des notes ($@)"
	m4 -D tmpFileNameNote=$(addprefix notes/tmp/,$(notdir $(@:.html=.htm))) -D linkFileNameNote=$(<:.md=) -D HEADER_HEADER=$(addprefix notes/tmp/,$(notdir $(basename $@)_header.htm)) -D CANONIC="https://ache.one/$@" notes/note.m4 | $(HTML_MINIFIER_CMD) > $@

notes/tmp/%.htm: notes/%.md
	@echo
	@echo "# Compile temporaire de la note $@"
	mkdir -p notes/tmp
	cat $< | $(MD_CMD) > $@

# > Création des notes depuis le markdown
# 	On compile le fichier md vers html (tmp/%.htm)
# 	On rajoute les headers (tmp/%_header.htm)
# 	On fini d'ajouter le squelette HTML (notes/%.html
notes/%.html: notes/tmp/%.htm notes/tmp/notes_cards.htm
	@echo "> Création des notes ($@)"
	m4 -D TITLE_TITLE="`echo Licornes, hérissons et renards`" headers.m4  > $(addprefix notes/tmp/,$(notdir $(basename $@)_header.htm))
	m4 -D tmpFileNameNote=$(addprefix notes/tmp/,$(notdir $(@:.html=.htm))) -D linkFileNameNote=$(<:.md=) -D HEADER_HEADER=$(addprefix notes/tmp/,$(notdir $(basename $@)_header.htm)) -D CANONIC="https://ache.one/$@" notes/note.m4 | $(HTML_MINIFIER_CMD) > $@

# > Création de la liste des notes (format cartes)
# 	On assemble juste les cartes de notes ensemble
notes/tmp/notes_cards.htm: $(ALL_NOTES_CARDS_OUT)
	@echo "> Création de la liste des cartes de notes"
	mkdir -p tmp
	cat $(ALL_NOTES_CARDS_OUT) > $@

# > Création des cartes de chaque note
notes/tmp/%_card.htm: notes/tmp/%.htm notes/notes_out
	@echo "> Création de carte de note : $@  (need $<)"
	mkdir -p tmp
	cat $< | $(CATCH_CMD) "h1" > $@.tmp
	cat $< | $(CATCH_CMD) "p:last-child" | sed 's/res\//notes\/res\//' >> $@.tmp
	m4 -D tmpCard=$@.tmp notes/card.m4  > $@



####################################################################
###		MAIN PAGE
####################################################################

# > Création de la page principale
# 	On se sert du menu de gauche, du header, et de la liste des introductions
# 		d'articles
index.html: index.m4 $(BASE_HTML) tmp/articles.htm
	@echo "> Création de la page principale"
	m4 $< | $(HTML_MINIFIER_CMD) > $@


# > Création de la page de contact
# 	On compile le markdown en html (contact.htm)
# 	On ajoute l'entête avec m4 (contact_header.html)
# 	On ajoute le reste du squelette avec m4 (contact.html)
contact/index.html: contact/index.md headers.m4 articles/article.m4
	@echo "> Création de la page de contact"
	$(MD_CMD) $< > $(@:.html=.htm)
	m4 -D TITLE_TITLE="`grep h1 $(@:.html=.htm) | cut -d'>' -f 2 | cut -d'<' -f 1`" headers.m4  > $(basename $@)_header.html
	m4 -D tmpFileNameArticle=$(@:.html=.htm) -D linkFileNameArticle=$(<:.md=) -D HEADER_HEADER=$(basename $@)_header.html -D CANONIC="https://ache.one/contact" articles/article.m4 | $(HTML_MINIFIER_CMD) > $@


# > Création du menu de gauche
# 	En se servant des logo dans s/img, on assemble le tout avec m4.
tmp/left.htm: s/imgM/twitterLogo.svg s/imgM/mastoLogo.svg s/imgM/gitLogo.svg s/imgM/acheLogo.svg left.m4
	@echo "> Création du menu de gauche"
	mkdir -p tmp
	m4 left.m4 > $@


# > Création de l'entête principale
# 	Tout est fait par le fichier headers.m4. On définit simplement le titre.
tmp/headers.htm: headers.m4
	@echo "> Création de l'entête principale"
	m4 -D TITLE_TITLE="Licornes, hérissons et renards - 🦄 🦔 🦊" -D CANONIC="https://ache.one" headers.m4  > $@

# > Création du fichier principale JavaScript
# 	À partir du script `prepare` de npm.
# 	En utilisant babel puis uglify-js
$(SCRIPT_JS): src/js/*
	mkdir -p s/js
	npm run-script prepare

# > Création du fichier principale CSS
# 	À partir de sassc, un compilateur SCSS écrit en C.
$(SHEET_CSS): src/css/*
	mkdir -p s/css
	sassc -t compressed src/css/design.scss > s/css/style.css


# > Fonctions de nettoyage
# .PHONY sert à indiquer une commande (sinon un fichier clean poserait problème)
# Un tiret devant une commande indique d'ignorer une éventuelle erreur.
.PHONY: clean
clean:
	@echo "Clean"
	-rm -fr articles/*.html tag/ s/ index.html rss.xml