make(1) website §

make website with make, cut, sed, date, sh, openrsync, ssh ~ 71 LOC

make-website.tgz

FR §

Voici une méthode pour créer un site web uniquement avec un Makefile et éventuellement un convertisseur markdown ou autre langage markup..

Makefile

Le site consiste en une structure de dossiers/fichiers. Les pages web sont des fichiers markdown avec l'extension .md. Tout ceci réside dans un dossier portant le nom de domaine du site foo.tld.

Fichiers §

Les fichiers ''head.tpl'' et ''foot.tpl'' contiennent le code html qui sera au début et à la fin de chaque page.

''foo.tld'' est la structure du site web avec des dossiers, des images et des fichiers markdown.

Avec le fichier Makefile suivant, on peut convertir si besoin tous les fichiers markdown en page html dans le dossier foo.tld. L'outil lowdown est utilisé ici (MDTOHTML) en guise d'exemple. Ce fichier doit être édité pour convenir à vos besoins.

https://kristaps.bsd.lv/lowdown/

.SUFFIXES: .md .html

# markdown converter
MDTOHTML = lowdown \
    -D html-skiphtml \
    -D html-head-ids \
    -E smarty \
    -d metadata \
    --html-no-skiphtml \
    --html-no-escapehtml
SRCDIR = foo.tld
SRC != find $(SRCDIR) -type f -name \*.md
OUT = ${SRC:.md=.html}


all: $(OUT) $(SRCDIR)/sitemap.xml $(SRCDIR)/all.html

clean:
    find . -name \*.html -delete

.md.html:
    @echo $<
    @cat head.tpl > $@
    @$(MDTOHTML) $< >> $@
    @cat foot.tpl  >> $@
    @bin/title.sh $@

$(SRCDIR)/sitemap.xml: $(OUT)
    @echo sitemap
    @bin/sitemap.sh $(OUT) > $(SRCDIR)/sitemap.xml
    @gzip --best -c $(SRCDIR)/sitemap.xml > $(SRCDIR)/sitemap.gz

$(SRCDIR)/all.html: $(OUT)
    @echo $@
    @cat head.tpl > $@
    @bin/sch.sh $(OUT) | $(MDTOHTML) >> $@
    @cat foot.tpl  >> $@
    @bin/title.sh $@

serve:
    cd $(SRCDIR) && python3 -m http.server

upload:
    openrsync -e "ssh" -av $(SRCDIR)/ user@foo.tld:/var/www/htdocs/foo.tld/

Le dossier bin contient des scripts permettant d'ajouter quelques fonctionnalités.

Pour exclure certains fichiers de la liste, find dispose de toutes les options qu'il faut :

SRC != find $(SRCDIR) -type f -name \*.txt -a \
    ! -name robots.txt -a \
    ! -name twtxt.txt

EN §

Create a website only with make and a markdown converter.

https://man.openbsd.org/make

The website is a file/directory structure containing .md files to convert and pictures and stuff. All of this is in a directory named foo.tld.

Files §

''head.tpl'' and ''foot.tpl'' are templates inserted before and after the content of each page generated from ''.md'' files.

''foo.tld'' is the website structure.

Makefile should be edited to suit your needs. (change MDTOHTML if you want, default is using lowdown). It helps to :

bin directory contains scripts to add some features :