Comment le site est fabriqué ?

Ici tout est simple, en essayant de pouvoir être compris et modifié/adapté par le plus grand nombre.

Un grand merci à @prx pour le travail initial avec son make website.

Le site se décompose en plusieurs parties:

Les fichiers *.tpl viennent entourer les fichiers sources pour qu’ils puissent être proprement rendus en html, en y ajoutant un entête avec un menu ainsi qu’un pied de page avec différents liens.

La conversion markdown > html est assuré par lowdown.

Le Makefile

Le Makefile permet avec la commande make d’interagir facilement avec le site. Il permet ainsi de nettoyer entièrement les fichiers générés (make clean), de générer le site (make) ou encore d’envoyer le tout sur le serveur (make upload).

SSHCRED = justin@bloguslibrus.fr
REMOTEDIR = ~/blog

all:
    @./build

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

serve:
    python3 -m http.server -d dst

upload:
    rsync-e "ssh" -apv --del ./ $(SSHCRED):$(REMOTEDIR)/
get:
    rsync-e "ssh" -apv $(SSHCRED):$(REMOTEDIR)/ ./

./build

#!/bin/sh

MDTOHTML="lowdown --html-no-skiphtml --html-no-escapehtml --html-no-head-ids --parse-no-metadata"

orphans() {
rm src/orphelines.md
(
echo "# Pages Orphelines"
echo ""
for f in $(find src -type f -name \*.md -a ! -name \*_*.md)
do
name=$(basename $f)
if [[ -z $(grep -l "$name" src/*.md) ]]
then
    echo "  - [${name%%.*}]($name)"
fi
done
) > src/orphelines.md
}

lists() {

### sort et uniq peuvent être replacés par awk '!a[$0]++'

for p in $(find src -type f -name \*_*.md | sort | cut -c 5- | cut -d "_" -f1 | uniq)
do
    (cat head.tpl
    echo "<h1>$p</h1>"
    echo "<ul>"
    for f in $(find src -type f -name $p*.md -a ! -name $p.md -exec ls -r "{}" +)
    do
        TITLE="$(grep -m1 "# " "$f" | cut -c 3-)"
        echo "<li><a href=\"$(basename ${f%%.*}).html\">$TITLE</a></li>"
    done
    echo "</ul"
    cat foot.tpl) > dst/$p.html
done
}

changelog() {
    ((cat head.tpl
    echo "<article>"
    echo "<h1>Journal des modifications</h1>"
    echo "<small><em>Seulement les nouveaux ajouts et les modifications importantes.</em></small>"
    while read line;
    do
    date=$(echo "$line" | cut -d' ' -f1)
    page=$(echo "$line" | awk -F' ' '{print $2}')
    text=$(echo "$line" | cut -f3- | tr -d '\t')
    if test -f "src/${page}.html"
    then
        echo "<br><b>$date</b>: <a href=\"${page}.html\">$text</a>"
    else
        echo "<br><b>$date</b>: $text"
    fi
    done < src/log.tbtl
    cat foot.tpl) > dst/log.html)

    ((echo "<blockquote>"
      echo "<em>Modifications récentes</em>"
    while read line;
    do
    date=$(echo "$line" | cut -d' ' -f1)
    page=$(echo "$line" | awk -F' ' '{print $2}')
    text=$(echo "$line" | cut -f3- | tr -d '\t')
    if test -f "src/${page}.html"
    then
        echo "<br><b>$date</b>: <a href=\"${page}.html\">$text</a>"
    else
        echo "<br><b>$date</b>: $text"
    fi
done < src/log.tbtl
echo "</blockquote>") | sed -i '32r/dev/stdin' dst/home.html)

    ((echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
    echo "<feed xmlns=\"http://www.w3.org/2005/Atom\">"
    echo "<title>Blogus Librus Journal Feed</title>"
    echo "<link rel=\"self\" href=\"https://bloguslibrus.fr\"/>"
    echo "<link rel=\"self\" type=\"application/atom+xml\" href=\"https://bloguslibrus.fr/atom.xml\"/>"
    echo "<updated>$(date +%Y-%m-%dT%TZ)</updated>"
    echo "<author><name>jbz, jnb</name></author>"
    echo "<id></id>"
    while read line;
    do
    date=$(echo "$line" | cut -d' ' -f1)
    page=$(echo "$line" | awk -F' ' '{print $2}')
    text=$(echo "$line" | cut -f3- | tr -d '\t')
    if test -f "src/${page}.html"
    then
        echo "<entry>"
        echo "<id>\"https://bloguslibrus.fr/$page.html\"</id>"
        echo "<title></title>"
        echo "<link rel=\"absolute\" href=\"\"/>"
        echo "<published>$(arvelie $date)T00:00:00TZ</published>"
        echo "<updated>$(date +%Y-%m-%dT%TZ)</updated>"
        echo "<summary>$text</summary>"
        echo "<content></content>"
        echo "</entry>"
    fi
    done < src/log.tbtl
    echo "</feed>") > dst/feed.xml)
}

main() {
    for f in $(find src -type f -name \*.md -exec ls -r "{}" +)
    do
    if [ "$(basename ${f%.*})" = "home" ]
    then
        (cat head.tpl
         $MDTOHTML $f | sed 's/.md\"/.html\"/g'
         cat foot.tpl) > dst/$(basename ${f%.*}).html
    else
    name=$(basename ${f%.*})
    (cat head.tpl
    if [[ "$name" == "*_*" ]]
    then
    topic=$(echo $name | cut -d'_' -f1)
    echo "<a href=\"${topic}.html\">./$topic</a>"
    fi
    if test -f "src/imgs/headers/$(basename ${f%.*}).jpg"
    then
    echo "<img src=\"imgs/headers/${name%.*}.jpg\">"
    fi
     echo "<article>"
     $MDTOHTML $f | sed 's/.md\"/.html\"/g'
     echo "Liens entrants:"
     for i in $(grep -l "$name" src/*.md | cut -c 5-)
     do
        #title=$(head -1 src/$i | cut -c 3-)
        echo " <a href=\"${i%%.*}.html\">${i%%.*}</a> |"
     done
     cat foot.tpl) > dst/${name%%.*}.html
    fi
    done
}

assets() {
    cp src/style.css dst/
    cp -r src/imgs dst/
    cp src/webring.svg dst/
}

orphans "$@"
lists "$@"
main "$@"
changelog "$@"
assets "$@"


Liens entrants: home |