From 8170b6616c13828b434e0103b362ca0e056309d0 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Wed, 30 Dec 2020 19:20:36 +0100 Subject: Add template machinery *Of course* it's going to be an ugly Bash script. Is there anything else? --- Makefile | 16 +++++--- build.sh | 34 ++++++++++++++++ contact.html | 128 ++++++++++++++++------------------------------------------ contact.sh | 3 ++ template.html | 64 +++++++++++++++++++++++++++++ 5 files changed, 146 insertions(+), 99 deletions(-) create mode 100755 build.sh create mode 100644 contact.sh create mode 100644 template.html diff --git a/Makefile b/Makefile index 08319dc..59be5a8 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,27 @@ -pages = $(wildcard *.html) +pages_src = $(wildcard *.html) +pages = $(foreach p,$(pages_src),public/$(p)) + sheets = $(wildcard *.css) images = $(wildcard *.svg) feeds = $(wildcard *.xml) -resources = $(pages) $(sheets) $(images) $(feeds) -targets = $(foreach f,$(resources),public/$(f)) +resources_src = $(sheets) $(images) $(feeds) +resources = $(foreach f,$(resources_src),public/$(f)) + .PHONY: all clean site all: site -site: $(targets) +site: $(pages) $(resources) public: mkdir $@ -$(targets): public/%: % | public +$(resources): public/%: % | public cp $< $@ +$(pages): public/%.html: %.html | public + ./build.sh $< $@ + clean: rm -r public diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..62487bd --- /dev/null +++ b/build.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +set -eu + +input=$1 +output=$2 + +parameters=${input/%.html/.sh} + +if ! test -f ${parameters} +then + cp ${input} ${output} + exit +fi + +cp template.html ${output} +. ${parameters} + +sed -i s/'{TITLE}'/"${title}"/ ${output} + +link_stylesheets='' +for s in "${stylesheets[@]}" +do + link_stylesheets+=$(printf '\n' "${s}") +done + +sed -i /'{STYLESHEETS}'/'c\'"${link_stylesheets}" ${output} + +if test "${current_div}" +then + sed -i s"${current_div}" ${output} +fi + +sed -i -e /'{MAIN}'/"r ${input}" -e /'{MAIN}'/'c\' ${output} diff --git a/contact.html b/contact.html index 8983d7f..cf849a0 100644 --- a/contact.html +++ b/contact.html @@ -1,94 +1,34 @@ - - - - - Contact - Quatuor Camelot - - - - - - - -
-
-

Contact

-

Nos coordonnées :

-
-
Email : -
contact@example.com
- -
Téléphone : -
01 99 00 01 02
- -
-

- Tenez-vous au courant des actualités du - quatuor en vous abonnant à notre - flux. -

-
-
-

Partenaires

-

- Nous offrons nos plus sincères remerciements aux personnes à - qui nous avons emprunté des images, vidéos et musiques : - -

-
-
- - - - - - +
+
+

Contact

+

Nos coordonnées :

+
+
Email : +
contact@example.com
+ +
Téléphone : +
01 99 00 01 02
+ +
+

+ Tenez-vous au courant des actualités du + quatuor en vous abonnant à notre + flux. +

+
+
+

Partenaires

+

+ Nous offrons nos plus sincères remerciements aux personnes à + qui nous avons emprunté des images, vidéos et musiques : + +

+
+
diff --git a/contact.sh b/contact.sh new file mode 100644 index 0000000..e8a08b6 --- /dev/null +++ b/contact.sh @@ -0,0 +1,3 @@ +title=Contact +stylesheets=(contact) +current_div='/class="contact"/class="contact current"/' diff --git a/template.html b/template.html new file mode 100644 index 0000000..bfb1550 --- /dev/null +++ b/template.html @@ -0,0 +1,64 @@ + + + + + {TITLE} - Quatuor Camelot + +{STYLESHEETS} + + + + + +{MAIN} + + + + + + -- cgit v1.2.3