diff --git a/README.md b/README.md index c94c99e..10261e8 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,9 @@ clone this repo ``` chmod +x genlog.sh ``` -put your files in the "content" folder - your .gmi files are converted in html and concatenated with the html/header.html and the html/footer.html the .html file is witen in the directory of the .gmi file which has been treated -this script will recursively search all .gmi files contained in the "content" folder, even in the other folders it includes +this script will recursively search all .gmi files contained in the "content" folder or a path given as an argument to the script, even in the other folders it includes feel free to customize the html/header.html and the html/footer.html as you like @@ -23,3 +21,18 @@ please keep the ``` in the html/header.html file if you want your generated pages to have a properly defined title in the HTML + +## usage + +put your files to be processed in the "content" folder then lauch the script +``` ./genlog.sh ``` + +or + +you can also put the path to your folder with the files to be processed as the first argument +``` ./genlog.sh /path/to/your/choosen/folder ``` + +or + +you can optionally add a text at the end of the HTML page title as the second argument +```./genlog.sh /path/to/your/choosen/folder "Your custom title"``` diff --git a/content/PUT YOUR FILES HERE b/content/PUT YOUR FILES HERE deleted file mode 100644 index e69de29..0000000 diff --git a/genlog.sh b/genlog.sh index 250b929..1072244 100755 --- a/genlog.sh +++ b/genlog.sh @@ -1,44 +1,57 @@ #!/bin/bash # on créé un répertoire de taff temporaire pour foutre nos fichiers en cours de traitement dedans -mkdir "${PWD}"/temp/ +tempdir="$(mktemp -d)" -# on cherche récursivement tous les fichiers ".gmi" dans le dossier "content" -find "${PWD}"/content -wholename "*.gmi" -type f | while read gmi_file + +# on vérifie s'il y a un argument passé à notre script +if [ -n "$1" ] +then + # si oui, on l'utilise comme path ou aller taffer + source_path="$1" +else + # sinon on utilise le dossier "content" à la racine de notre script + source_path=content +fi + + +# on génère la date et on la fout dans le footer +date="$(date)" +sed "s/GEN_DATE/$date/" html/footer.html > "$tempdir/footer.html" + + +# on cherche récursivement tous les fichiers ".gmi" dans le dossier de taff +find "$source_path" -wholename "*.gmi" -type f | while read -r gmi_file do # récupérer la 1ère ligne du fichier .gmi et remplacer "# " par "" - title="$(sed -n '1{s/# //p}' $gmi_file)" + title="$(sed -n '1{s/# //p}' "$gmi_file") $2" # dans le header.html, remplacer "<\-- TITLE -->" par le titre récupéré # puis enregistrer le fichier ainsi modifié dans "temp/header.html" - sed "s#<\!-- TITLE -->#$title#" "${PWD}"/html/header.html > "${PWD}"/temp/header.html - - # on génère la date et on la fout dans le footer - date="$(date)" - sed "s/GEN_DATE/$date/" "${PWD}"/html/footer.html > "${PWD}"/temp/footer.html + sed "s#<\!-- TITLE -->#$title#" html/header.html > "$tempdir/header.html" # conversion du .gmi en .html - gmnitohtml < $gmi_file > "${PWD}"/temp/body.html + gmnitohtml < "$gmi_file" > "$tempdir/body.html" # on récupère juste le path du dossier qui contient le .gmi - path="$(dirname $gmi_file)" + file_path="$(dirname "$gmi_file")" # on récupère juste le nom du fichier .gmi sans son extenstion ".gmi" - filename="$(basename $gmi_file .gmi)" + file_name="$(basename "$gmi_file" .gmi)" # on assemble les 3 morceaux et on l'écrit dans le dossier du .gmi qui est traité - cat "${PWD}"/temp/header.html "${PWD}"/temp/body.html "${PWD}"/temp/footer.html > $path/$filename.html - - # on nettoie le dossier de taff - rm "${PWD}"/temp/* + cat "$tempdir/header.html" "$tempdir/body.html" "$tempdir/footer.html" > "$file_path/$file_name.html" # je crois c'est bon - echo "OK: $gmi_file" + echo "OK: $title" + echo " ⤷ $file_path/$file_name.html" done + # on vire le dossier de taff devenu inutile -rm -r "${PWD}"/temp/ +rm -r "$tempdir" + # cette fois c'est vraiment fini -echo "Done." +echo "All done." diff --git a/html/header.html b/html/header.html index b933854..dca2cbb 100644 --- a/html/header.html +++ b/html/header.html @@ -52,7 +52,7 @@ @media only screen and (max-width: 1000px) { body { margin: 0 1em 0 1em; - font-size: 3em; + font-size: 2em; } blockquote {