From 27978a2c4597fc13d60a06df49d180a8ba867480 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Wed, 13 Apr 2022 23:35:38 +0200 Subject: [PATCH 01/19] usage de mktemp -d --- genlog.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/genlog.sh b/genlog.sh index 250b929..ad3bd28 100755 --- a/genlog.sh +++ b/genlog.sh @@ -1,7 +1,7 @@ #!/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 @@ -12,14 +12,14 @@ do # 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 + sed "s#<\!-- TITLE -->#$title#" "${PWD}"/html/header.html > "$tempdir/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/GEN_DATE/$date/" "${PWD}"/html/footer.html > "$tempdir/footer.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)" @@ -27,10 +27,10 @@ do filename="$(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 + cat "$tempdir/header.html" "$tempdir/body.html" "$tempdir/footer.html" > $path/$filename.html # on nettoie le dossier de taff - rm "${PWD}"/temp/* + rm "$tempdir/*" # je crois c'est bon echo "OK: $gmi_file" @@ -38,7 +38,7 @@ do done # on vire le dossier de taff devenu inutile -rm -r "${PWD}"/temp/ +rm -rf "$tempdir" # cette fois c'est vraiment fini echo "Done." From da7feea04e99fc1d2f20355d698903a479fd8fda Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Wed, 13 Apr 2022 23:36:52 +0200 Subject: [PATCH 02/19] security fix --- genlog.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/genlog.sh b/genlog.sh index ad3bd28..a5625d1 100755 --- a/genlog.sh +++ b/genlog.sh @@ -4,11 +4,11 @@ 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 +find "${PWD}"/content -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")" # dans le header.html, remplacer "<\-- TITLE -->" par le titre récupéré # puis enregistrer le fichier ainsi modifié dans "temp/header.html" @@ -19,15 +19,15 @@ do sed "s/GEN_DATE/$date/" "${PWD}"/html/footer.html > "$tempdir/footer.html" # conversion du .gmi en .html - gmnitohtml < $gmi_file > "$tempdir/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)" + path="$(dirname "$gmi_file")" # on récupère juste le nom du fichier .gmi sans son extenstion ".gmi" - filename="$(basename $gmi_file .gmi)" + filename="$(basename "$gmi_file" .gmi)" # on assemble les 3 morceaux et on l'écrit dans le dossier du .gmi qui est traité - cat "$tempdir/header.html" "$tempdir/body.html" "$tempdir/footer.html" > $path/$filename.html + cat "$tempdir/header.html" "$tempdir/body.html" "$tempdir/footer.html" > "$path/$filename.html" # on nettoie le dossier de taff rm "$tempdir/*" From 2060f8044b11f20928af491894328211dc5bb8ae Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 6 May 2022 21:59:45 +0200 Subject: [PATCH 03/19] =?UTF-8?q?ajout=20fonctionnalit=C3=A9=20choix=20dos?= =?UTF-8?q?sier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 ++++++++++--- genlog.sh | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c94c99e..5f52e51 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,12 @@ 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 in the "content" folder +``` ./genlog.sh ``` + +or + +``` ./genlog.sh /path/to/your/choosen/folder ``` diff --git a/genlog.sh b/genlog.sh index a5625d1..db597e5 100755 --- a/genlog.sh +++ b/genlog.sh @@ -3,8 +3,18 @@ # on créé un répertoire de taff temporaire pour foutre nos fichiers en cours de traitement dedans tempdir="$(mktemp -d)" -# on cherche récursivement tous les fichiers ".gmi" dans le dossier "content" -find "${PWD}"/content -wholename "*.gmi" -type f | while read -r gmi_file +# on vérifie s'il y a un argument passé à notre script +if "$1" +then + # si oui, on l'utilise comme path ou aller taffer + source_path="$1" +else + # sinon on utilise le dossier "content" + source_path="${PWD}"/content +fi + +# 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 "" From c60ce7610111728302661cf28322ff42eb976def Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 6 May 2022 22:11:14 +0200 Subject: [PATCH 04/19] fix mise en page --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f52e51..c0aa454 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ in the html/header.html file if you want your generated pages to have a properly ## usage -put your files in the "content" folder +put your files in the "content" folder ``` ./genlog.sh ``` or From 355c7d858d004025761371c520aba17cfc861826 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 6 May 2022 22:19:18 +0200 Subject: [PATCH 05/19] =?UTF-8?q?correction=20d=C3=A9tection=20argument?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- genlog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genlog.sh b/genlog.sh index db597e5..04b30e6 100755 --- a/genlog.sh +++ b/genlog.sh @@ -4,7 +4,7 @@ tempdir="$(mktemp -d)" # on vérifie s'il y a un argument passé à notre script -if "$1" +if [ -n "$1" ] then # si oui, on l'utilise comme path ou aller taffer source_path="$1" From 4d90b1d649cb1a39b68909fd394c684d251fc0f7 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 6 May 2022 22:23:31 +0200 Subject: [PATCH 06/19] ajout titre dans l'echo de fin --- genlog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genlog.sh b/genlog.sh index 04b30e6..7fe2fb4 100755 --- a/genlog.sh +++ b/genlog.sh @@ -43,7 +43,7 @@ do rm "$tempdir/*" # je crois c'est bon - echo "OK: $gmi_file" + echo "OK: $title -> $gmi_file" done From afe9b455627c72c599ba5e97b70edd36ef768833 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 6 May 2022 22:27:41 +0200 Subject: [PATCH 07/19] =?UTF-8?q?2=20=C3=A9chos=20de=20fin=20au=20lieu=20d?= =?UTF-8?q?'un?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- genlog.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/genlog.sh b/genlog.sh index 7fe2fb4..24e1752 100755 --- a/genlog.sh +++ b/genlog.sh @@ -43,7 +43,8 @@ do rm "$tempdir/*" # je crois c'est bon - echo "OK: $title -> $gmi_file" + echo "OK: $title" + echo "⤷ $gmi_file" done From 2f449a81b32d24cd92a74a258bd784a9e97b753c Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 6 May 2022 22:40:08 +0200 Subject: [PATCH 08/19] suppression rm inutile --- genlog.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/genlog.sh b/genlog.sh index 24e1752..fd46baf 100755 --- a/genlog.sh +++ b/genlog.sh @@ -39,9 +39,6 @@ do # on assemble les 3 morceaux et on l'écrit dans le dossier du .gmi qui est traité cat "$tempdir/header.html" "$tempdir/body.html" "$tempdir/footer.html" > "$path/$filename.html" - # on nettoie le dossier de taff - rm "$tempdir/*" - # je crois c'est bon echo "OK: $title" echo "⤷ $gmi_file" @@ -49,7 +46,7 @@ do done # on vire le dossier de taff devenu inutile -rm -rf "$tempdir" +rmdir "$tempdir" # cette fois c'est vraiment fini echo "Done." From cac626b4bc240bf0b811b835c1e4b1b8d0a5a76f Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 6 May 2022 22:41:59 +0200 Subject: [PATCH 09/19] fix suppression dossier --- genlog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genlog.sh b/genlog.sh index fd46baf..3749567 100755 --- a/genlog.sh +++ b/genlog.sh @@ -46,7 +46,7 @@ do done # on vire le dossier de taff devenu inutile -rmdir "$tempdir" +rm -r "$tempdir" # cette fois c'est vraiment fini echo "Done." From 2868a52e0898c76602c81fbc0e72e20e6392c42f Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 6 May 2022 22:44:17 +0200 Subject: [PATCH 10/19] modif echos --- genlog.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/genlog.sh b/genlog.sh index 3749567..24ae9ca 100755 --- a/genlog.sh +++ b/genlog.sh @@ -41,7 +41,7 @@ do # je crois c'est bon echo "OK: $title" - echo "⤷ $gmi_file" + echo " ⤷ $gmi_file" done @@ -49,4 +49,4 @@ done rm -r "$tempdir" # cette fois c'est vraiment fini -echo "Done." +echo "All done." From f6110ce727694fe9c8da5065fb25452007de4bce Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 6 May 2022 22:48:41 +0200 Subject: [PATCH 11/19] modif commentaire (plusse explicite) --- genlog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genlog.sh b/genlog.sh index 24ae9ca..b5f3387 100755 --- a/genlog.sh +++ b/genlog.sh @@ -9,7 +9,7 @@ then # si oui, on l'utilise comme path ou aller taffer source_path="$1" else - # sinon on utilise le dossier "content" + # sinon on utilise le dossier "content" à la racine de notre script source_path="${PWD}"/content fi From 847a16d34d28001fced6bdf661d8261e512865f5 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 6 May 2022 22:53:02 +0200 Subject: [PATCH 12/19] =?UTF-8?q?d=C3=A9sambiguisation=20de=20variables=20?= =?UTF-8?q?et=20fix=20nom=20fichier=20=C3=A9crit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- genlog.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/genlog.sh b/genlog.sh index b5f3387..d908771 100755 --- a/genlog.sh +++ b/genlog.sh @@ -32,16 +32,16 @@ do 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 "$tempdir/header.html" "$tempdir/body.html" "$tempdir/footer.html" > "$path/$filename.html" + cat "$tempdir/header.html" "$tempdir/body.html" "$tempdir/footer.html" > "$file_path/$file_name.html" # je crois c'est bon echo "OK: $title" - echo " ⤷ $gmi_file" + echo " ⤷ $file_path/$file_name.html" done From f37c0cb962793dddd889d578aab68cee82f7c6a7 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 6 May 2022 22:57:00 +0200 Subject: [PATCH 13/19] =?UTF-8?q?footer=20g=C3=A9n=C3=A9r=C3=A9=201=20fois?= =?UTF-8?q?=20au=20lieu=20de=20chaque=20fois?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- genlog.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/genlog.sh b/genlog.sh index d908771..7f8c80a 100755 --- a/genlog.sh +++ b/genlog.sh @@ -3,6 +3,7 @@ # on créé un répertoire de taff temporaire pour foutre nos fichiers en cours de traitement dedans tempdir="$(mktemp -d)" + # on vérifie s'il y a un argument passé à notre script if [ -n "$1" ] then @@ -13,6 +14,12 @@ else source_path="${PWD}"/content fi + +# on génère la date et on la fout dans le footer +date="$(date)" +sed "s/GEN_DATE/$date/" "${PWD}"/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 @@ -24,10 +31,6 @@ do # puis enregistrer le fichier ainsi modifié dans "temp/header.html" sed "s#<\!-- TITLE -->#$title#" "${PWD}"/html/header.html > "$tempdir/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 > "$tempdir/footer.html" - # conversion du .gmi en .html gmnitohtml < "$gmi_file" > "$tempdir/body.html" @@ -45,8 +48,10 @@ do done + # on vire le dossier de taff devenu inutile rm -r "$tempdir" + # cette fois c'est vraiment fini echo "All done." From 4921b15074ea7b2f7c9fa7caf20c89ac01edec84 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Fri, 6 May 2022 23:52:16 +0200 Subject: [PATCH 14/19] =?UTF-8?q?ajout=20fonctionnalit=C3=A9=20de=20titre?= =?UTF-8?q?=20custom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++++ genlog.sh | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c0aa454..c8c5e1c 100644 --- a/README.md +++ b/README.md @@ -30,3 +30,8 @@ put your files in the "content" folder or ``` ./genlog.sh /path/to/your/choosen/folder ``` + +or + +you can optionally add a text at the end of the HTML page title +```./genlog.sh /path/to/your/choosen/folder "Your custom title"``` diff --git a/genlog.sh b/genlog.sh index 7f8c80a..0b09ba9 100755 --- a/genlog.sh +++ b/genlog.sh @@ -25,7 +25,7 @@ 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" From f162f321d1aa07ba0eafa3582c4d716f6791f896 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Sat, 7 May 2022 00:59:51 +0200 Subject: [PATCH 15/19] ajout commentaires sur les usages possibles --- genlog.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 genlog.py diff --git a/genlog.py b/genlog.py new file mode 100644 index 0000000..3d44f5e --- /dev/null +++ b/genlog.py @@ -0,0 +1,23 @@ +import subprocess +import os + +entree = os.open("./index.gmi", os.O_RDONLY) +sortie = os.open("./temp.html", os.O_WRONLY) + +subprocess.run( + "gmnitohtml", + stdin=entree, + stdout=sortie, + stderr=None, + shell=True, + timeout=None, +) + +header = os.open("./html/header.html", os.O_RDONLY) +body = os.open("./temp.html", os.O_RDONLY) +footer = os.open("./html/footer.html", os.O_RDONLY) +fichier = os.open("./out.html", os.O_APPEND) + +fichier = header + body + footer +for line in header: + print(line) From 0219df17df2092c1da04944b2b387a42094a579a Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Sat, 7 May 2022 01:02:10 +0200 Subject: [PATCH 16/19] Revert "ajout commentaires sur les usages possibles" This reverts commit f162f321d1aa07ba0eafa3582c4d716f6791f896. --- genlog.py | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 genlog.py diff --git a/genlog.py b/genlog.py deleted file mode 100644 index 3d44f5e..0000000 --- a/genlog.py +++ /dev/null @@ -1,23 +0,0 @@ -import subprocess -import os - -entree = os.open("./index.gmi", os.O_RDONLY) -sortie = os.open("./temp.html", os.O_WRONLY) - -subprocess.run( - "gmnitohtml", - stdin=entree, - stdout=sortie, - stderr=None, - shell=True, - timeout=None, -) - -header = os.open("./html/header.html", os.O_RDONLY) -body = os.open("./temp.html", os.O_RDONLY) -footer = os.open("./html/footer.html", os.O_RDONLY) -fichier = os.open("./out.html", os.O_APPEND) - -fichier = header + body + footer -for line in header: - print(line) From 1b364404fb7a50bb206278fdbbb5a8b531b1e4ee Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Sat, 7 May 2022 01:02:40 +0200 Subject: [PATCH 17/19] ajout commentaires sur les usages possibles --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c8c5e1c..10261e8 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,15 @@ in the html/header.html file if you want your generated pages to have a properly ## usage -put your files in the "content" folder +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 +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"``` From 341f9da5a2a43837226cff78ca3eec195364115b Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Sat, 7 May 2022 17:43:35 +0200 Subject: [PATCH 18/19] suppression des pwd inutiles --- content/PUT YOUR FILES HERE | 0 genlog.sh | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 content/PUT YOUR FILES HERE 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 0b09ba9..1072244 100755 --- a/genlog.sh +++ b/genlog.sh @@ -11,13 +11,13 @@ then source_path="$1" else # sinon on utilise le dossier "content" à la racine de notre script - source_path="${PWD}"/content + source_path=content fi # on génère la date et on la fout dans le footer date="$(date)" -sed "s/GEN_DATE/$date/" "${PWD}"/html/footer.html > "$tempdir/footer.html" +sed "s/GEN_DATE/$date/" html/footer.html > "$tempdir/footer.html" # on cherche récursivement tous les fichiers ".gmi" dans le dossier de taff @@ -29,7 +29,7 @@ do # 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 > "$tempdir/header.html" + sed "s#<\!-- TITLE -->#$title#" html/header.html > "$tempdir/header.html" # conversion du .gmi en .html gmnitohtml < "$gmi_file" > "$tempdir/body.html" From 77db9b19a4c4f39dba56e5c1189ddc5fdf82bf3e Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Sat, 8 Oct 2022 23:57:09 +0200 Subject: [PATCH 19/19] fix affichage mobile --- html/header.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/header.html b/html/header.html index 76d4cdc..d60e0d1 100644 --- a/html/header.html +++ b/html/header.html @@ -51,7 +51,7 @@ @media only screen and (max-width: 1000px) { body { margin: 0 1em 0 1em; - font-size: 3em; + font-size: 2em; } blockquote {