orgmode-to-gemini-blog/converters.sh

228 lines
7.3 KiB
Bash
Raw Permalink Normal View History

2024-11-02 18:30:04 +01:00
#!/bin/bash
# conversion des pages d'articles depuis le dossier source en orgmode
2024-11-03 11:06:34 +01:00
# liste des dossiers à convertir
2024-11-04 14:14:28 +01:00
# blogs_folders=("dragonfeu_blog" "tykayn_blog" "cipherbliss_blog" "qzine_blog" "cil_gometz")
2024-11-05 00:35:49 +01:00
blogs_folders=()
2024-11-04 10:48:39 +01:00
# blogs_folders=("tykayn_blog" "qzine_blog" "dragonfeu_blog")
2024-11-04 09:35:31 +01:00
# blogs_folders=("cil_gometz")
2024-11-04 11:52:45 +01:00
# blogs_folders=("qzine_blog")
2024-11-04 00:13:58 +01:00
# blogs_folders=("cipherbliss_blog")
2024-11-19 13:49:39 +01:00
root_folder="/home/poule/encrypted/stockage-syncable/www/development/html/orgmode-to-gemini-blog"
2024-11-03 11:06:34 +01:00
source_file_extension="org"
2024-11-08 23:19:39 +01:00
style_file="templates/styles/style_general.css"
2024-11-10 18:03:31 +01:00
destination_gemini="gemini-capsules/$website_name/"
2024-11-04 14:14:28 +01:00
# Boucle à travers tous les arguments passés en entrée
for arg in "$@"
do
# Si l'argument est connu, ajouter le nom de blog correspondant à la liste
blogs_folders+=("$arg")
done
# Afficher la liste des noms de blogs
echo "----------- La liste des noms de blogs est :"
2024-11-04 14:14:28 +01:00
for blog in "${blogs_folders[@]}"
do
echo "- $blog"
2024-11-05 00:35:49 +01:00
done
2024-11-04 14:14:28 +01:00
2024-11-08 17:40:06 +01:00
first_wd=$PWD
2024-11-03 12:32:08 +01:00
convert_sources() {
2024-11-10 15:58:11 +01:00
2024-11-19 13:49:39 +01:00
echo "argument : $1"
2024-11-03 12:32:08 +01:00
source_file_extension="org"
2024-11-19 13:49:39 +01:00
website_full_path=$1
2024-11-03 12:32:08 +01:00
2024-11-10 18:03:31 +01:00
echo "----------- convert_sources : convertir les fichiers orgmode vers gemini et html dans le dossier source/nom_du_blog/ racine, lang_fr et lang_en"
2024-11-19 13:49:39 +01:00
mkdir -p "${website_full_path}/converted/"
2024-11-11 00:02:50 +01:00
2024-11-19 13:49:39 +01:00
cd "${website_full_path}"
pwd
# ls -l *.${source_file_extension}
2024-11-10 15:58:11 +01:00
2024-11-19 13:49:39 +01:00
for i in *.${source_file_extension} ; do
# echo "----------- $i"
#
# # Transformer en html et en markdown
# echo "----------- convert_sources : conversion vers ${website_full_path}/converted/${i%.${source_file_extension}}.html"
#
pandoc --from "${source_file_extension}" --to html -s "${i}" -o "${website_full_path}/converted/${i%.${source_file_extension}}.html" --metadata title="$website_name"
2024-11-10 15:58:11 +01:00
2024-11-19 13:49:39 +01:00
# ls -l "${website_full_path}/converted/${i%.${source_file_extension}}.html"
2024-11-10 15:58:11 +01:00
2024-11-19 13:49:39 +01:00
pandoc --from "${source_file_extension}" --to markdown -s "${i}" -o "${website_full_path}/converted/${i%.${source_file_extension}}.md" --metadata title="$website_name"
2024-11-03 12:32:08 +01:00
done
2024-11-19 13:49:39 +01:00
cd $first_wd
2024-11-10 15:58:11 +01:00
}
2024-11-10 15:58:11 +01:00
2024-11-03 11:06:34 +01:00
# Définition de la fonction generate_website
generate_website() {
2024-11-10 18:03:31 +01:00
echo "----------- convert_sources :Génération du site $1..."
2024-11-18 13:10:30 +01:00
cp $style_file html-websites/$website_name/style.css
2024-11-03 11:42:44 +01:00
2024-11-10 00:01:15 +01:00
if [ ! -d "sources/$website_name" ]; then
mkdir -p sources/$website_name/img
mkdir -p sources/$website_name/lang_fr
mkdir -p sources/$website_name/lang_en
2024-11-10 15:58:11 +01:00
mkdir -p sources/$website_name/templates
cp templates/$website_name/$source_file_extension/* sources/$website_name/templates
2024-11-10 00:01:15 +01:00
fi
2024-11-03 11:06:34 +01:00
2024-11-10 15:58:11 +01:00
mkdir -p html-websites/$website_name
2024-11-18 11:18:50 +01:00
mkdir -p html-websites/$website_name/feed
2024-11-10 15:58:11 +01:00
rm -rf html-websites/$website_name/*
2024-11-11 00:02:50 +01:00
rm -rf sources/$website_name/converted/*
rm -rf sources/$website_name/lang_fr/converted/*
rm -rf sources/$website_name/lang_en/converted/*
mkdir -p html-websites/$website_name/lang_fr
2024-11-10 15:58:11 +01:00
mkdir -p html-websites/$website_name/lang_fr
2024-11-10 18:03:31 +01:00
echo "----------- convert_sources :Le site $1 a été généré avec succès."
2024-11-03 12:32:08 +01:00
# conversion des pages statiques
2024-11-19 13:49:39 +01:00
convert_sources "$root_folder/sources/$website_name"
#
convert_sources "$root_folder/sources/$website_name/templates"
echo "----------- convert_sources : pages template $website_name converties"
2024-11-03 12:32:08 +01:00
# traduction fr
2024-11-19 13:49:39 +01:00
convert_sources "$root_folder/sources/$website_name/lang_fr"
echo "----------- convert_sources :pages en français du site web $website_name converties"
2024-11-03 13:16:33 +01:00
2024-11-03 12:32:08 +01:00
# traduction en
2024-11-19 13:49:39 +01:00
convert_sources "$root_folder/sources/$website_name/lang_en"
echo "----------- pages en anglais du site web $website_name converties"
#
#
# echo " ____________________________________ "
# echo " ____________________________________ "
# echo " ____________________________________ "
# pwd
#
# echo " ____________________________________ "
# echo " ____________________________________ "
# echo " ____________________________________ "
ls -l "$root_folder/sources/$website_name/converted"
2024-11-18 13:10:30 +01:00
2024-11-03 11:06:34 +01:00
}
2024-11-10 15:58:11 +01:00
convert_markdown_to_gmi() {
2024-11-10 18:03:31 +01:00
2024-11-11 00:02:50 +01:00
destination_gemini="gemini-capsules/$website_name"
2024-11-10 18:03:31 +01:00
echo "----------- convert_sources : convert_markdown_to_gmi : $website_name"
2024-11-10 15:58:11 +01:00
2024-11-19 14:18:41 +01:00
rm -rf gemini-capsules/$website_name/*
2024-11-11 00:02:50 +01:00
mkdir -p gemini-capsules/$website_name
2024-11-10 15:58:11 +01:00
mkdir -p gemini-capsules/$website_name/lang_fr
mkdir -p gemini-capsules/$website_name/lang_en
2024-11-14 13:32:56 +01:00
# echo "----------- convert_markdown_to_gmi : $PWD"
# echo "----------- convert_markdown_to_gmi : destination: $destination_gemini"
2024-11-10 18:03:31 +01:00
2024-11-14 13:32:56 +01:00
# echo "----------- convert_markdown_to_gmi : fichiers markdown présents dans le dossier de base: "
2024-11-10 18:03:31 +01:00
ls -l sources/$website_name/converted/*.md |wc
2024-11-10 15:58:11 +01:00
# # faire les fichiers gemini à partir du markdown
2024-11-10 18:03:31 +01:00
# pages de base
# pages fr
# pages en
for fichier in sources/$website_name/converted/*.md ; do
2024-11-10 15:58:11 +01:00
if [ -f "$fichier" ]; then
echo "----------- convert_markdown_to_gmi : md2gemini : $destination_gemini : $fichier"
2024-11-11 00:02:50 +01:00
md2gemini "$fichier" -w -d $destination_gemini/
2024-11-10 15:58:11 +01:00
fi
done
2024-11-11 00:02:50 +01:00
cp sources/$website_name/converted/*.gmi "$destination_gemini/lang_fr"
2024-11-10 18:03:31 +01:00
for fichier in sources/$website_name/lang_fr/converted/*.md ; do
if [ -f "$fichier" ]; then
echo "----------- convert_markdown_to_gmi : md2gemini : $fichier"
2024-11-10 18:03:31 +01:00
md2gemini "$fichier" -w -d sources/$website_name/lang_fr/converted/
fi
done
2024-11-11 00:02:50 +01:00
cp sources/$website_name/lang_fr/converted/*.gmi "$destination_gemini/lang_fr"
2024-11-10 18:03:31 +01:00
for fichier in sources/$website_name/lang_en/converted/*.md ; do
if [ -f "$fichier" ]; then
echo "----------- convert_markdown_to_gmi : md2gemini : $fichier"
2024-11-10 18:03:31 +01:00
md2gemini "$fichier" -w -d sources/$website_name/lang_fr/converted/
fi
done
2024-11-11 00:02:50 +01:00
cp sources/$website_name/lang_en/converted/*.gmi "$destination_gemini/lang_en"
2024-11-10 15:58:11 +01:00
echo "----------- génération des fichiers gemini faite."
2024-11-19 13:49:39 +01:00
2024-11-18 13:10:30 +01:00
pwd
2024-11-10 15:58:11 +01:00
2024-11-10 18:03:31 +01:00
# echo "fichiers gmi présents:"
# ls -l $destination_gemini*.gmi |wc -l
2024-11-10 15:58:11 +01:00
}
2024-11-03 11:06:34 +01:00
# regrouper les types de fichiers générés
2024-11-10 15:58:11 +01:00
bash sass_styles.sh
2024-11-08 23:19:39 +01:00
2024-11-03 11:06:34 +01:00
# Boucle à travers la liste des sites Web
2024-11-03 11:42:44 +01:00
for website_name in "${blogs_folders[@]}"; do
2024-11-18 13:10:30 +01:00
2024-11-19 13:49:39 +01:00
export website_name=$website_name
2024-11-03 11:06:34 +01:00
generate_website $website_name
2024-11-10 22:35:03 +01:00
convert_markdown_to_gmi $website_name
2024-11-10 15:58:11 +01:00
2024-11-14 13:32:56 +01:00
# création de l'index listant les articles pour le html et la capsule gemini:
2024-11-10 18:03:31 +01:00
# prendre les fichiers markdown du dossier md/ ,
# et créer un index des fichiers situés dedans, rangés par nom de fichier décroissant,
# sauver le tout dans un fichier index.gmi
2024-11-14 13:32:56 +01:00
python3 build_indexes.py $website_name
2024-11-10 18:03:31 +01:00
# créer les pages de tags
2024-11-18 16:01:34 +01:00
mkdir -p "html-websites/$website_name/tags"
mkdir -p "html-websites/$website_name/tag"
python3 gather_tags_in_json.py $website_name
2024-11-10 18:03:31 +01:00
# déplacer les fichiers générés en html dans le dossier statique
2024-11-14 13:32:56 +01:00
mv sources/$website_name/converted/*.html html-websites/$website_name/
2024-11-10 18:03:31 +01:00
2024-11-18 16:01:34 +01:00
python3 enrich_html.py $website_name --style $style_file
2024-11-10 18:03:31 +01:00
2024-11-14 13:32:56 +01:00
# copier le style dans le dossier html
2024-11-10 18:03:31 +01:00
cp $style_file html-websites/$website_name/style.css
# copier le script permettant la recherche
cp templates/js/main_script.js html-websites/$website_name/main_script.js
2024-11-08 17:40:06 +01:00
# traiter les réductions d'images dans l'inbox
python3 pictures_resize.py
2024-11-18 16:01:34 +01:00
# régénérer le flux Atom du blog
2024-11-18 13:10:30 +01:00
mkdir -p "html-websites/$website_name/feed"
2024-11-18 11:18:50 +01:00
python3 atom_generate.py $website_name
2024-11-03 11:06:34 +01:00
done