diff --git a/converters.sh b/converters.sh index cad19b52..396addce 100755 --- a/converters.sh +++ b/converters.sh @@ -50,25 +50,25 @@ convert_sources() { ls $website_full_path/*.org # echo "----------- convert_sources : aucun document dans converted" - if [ -z "$(ls -A /sources/$website_name/lang_fr/converted/)" ]; then - echo "coucou on convertit tout" - for i in $(find "$website_full_path" -maxdepth 1 -type f -name "*.$source_file_extension"); do - # echo "----------- convert_sources : org -> html et -> md : " - # echo " $i" - # echo "" - pandoc --from "${source_file_extension}" --to html -s "${i}" -o "${website_full_path}/converted/${i%.${source_file_extension}}.html" --metadata title="$i - $website_name" - pandoc --from "${source_file_extension}" --to markdown -s "${i}" -o "${website_full_path}/converted/${i%.${source_file_extension}}.md" --metadata title="$website_name" - done - else - echo "on ne convertit que les plus récents " - for i in $(find "$website_full_path" -maxdepth 1 -type f -name "*.$source_file_extension" -newermt "2024-11-20"); do - # echo "----------- convert_sources : org -> html et -> md : " - # echo " $i" - # echo "" - pandoc --from "${source_file_extension}" --to html -s "${i}" -o "${website_full_path}/converted/${i%.${source_file_extension}}.html" --metadata title="$i - $website_name" - pandoc --from "${source_file_extension}" --to markdown -s "${i}" -o "${website_full_path}/converted/${i%.${source_file_extension}}.md" --metadata title="$website_name" - done - fi + # if [ -z "$(ls -A /sources/$website_name/lang_fr/converted/)" ]; then + # echo "coucou on convertit tout" + # for i in $(find "$website_full_path" -maxdepth 1 -type f -name "*.$source_file_extension"); do + # # echo "----------- convert_sources : org -> html et -> md : " + # # echo " $i" + # # echo "" + # pandoc --from "${source_file_extension}" --to html -s "${i}" -o "${website_full_path}/converted/${i%.${source_file_extension}}.html" --metadata title="$i - $website_name" + # pandoc --from "${source_file_extension}" --to markdown -s "${i}" -o "${website_full_path}/converted/${i%.${source_file_extension}}.md" --metadata title="$website_name" + # done + # else + # echo "on ne convertit que les plus récents " + # for i in $(find "$website_full_path" -maxdepth 1 -type f -name "*.$source_file_extension" -newermt "2024-11-20"); do + # # echo "----------- convert_sources : org -> html et -> md : " + # # echo " $i" + # # echo "" + # pandoc --from "${source_file_extension}" --to html -s "${i}" -o "${website_full_path}/converted/${i%.${source_file_extension}}.html" --metadata title="$i - $website_name" + # pandoc --from "${source_file_extension}" --to markdown -s "${i}" -o "${website_full_path}/converted/${i%.${source_file_extension}}.md" --metadata title="$website_name" + # done + # fi # exit # convertir seulement les pages récentes @@ -213,7 +213,7 @@ for website_name in "${blogs_folders[@]}"; do # générer l'index montrant les posts les plus récents à la suite bash concat_list_billets.sh $website_name # sauver le tout dans un fichier index.gmi - python3 build_indexes.py $website_name + # python3 build_indexes.py $website_name # créer les pages de tags mkdir -p "html-websites/$website_name/tags" @@ -224,7 +224,7 @@ for website_name in "${blogs_folders[@]}"; do # déplacer les fichiers générés en html dans le dossier statique mv sources/$website_name/converted/*.html html-websites/$website_name/ - python3 enrich_html.py $website_name --style $style_file + # python3 enrich_html.py $website_name --style $style_file # copier le style dans le dossier html cp $style_file html-websites/$website_name/style.css diff --git a/enrich_html.py b/enrich_html.py index 2dbbab2c..d4ebe6ec 100755 --- a/enrich_html.py +++ b/enrich_html.py @@ -209,4 +209,6 @@ for root_path, dirs, files in liste_fichiers_du_blog_convertis : f.write(html_content) # mylog('\n ----------- enrich_html: html écrit ', html_path_enriched) +# traduire en html le fichier + print('articles listés :',count_articles) \ No newline at end of file diff --git a/linking_articles_prev_next.py b/linking_articles_prev_next.py index f41fa98e..490bf167 100644 --- a/linking_articles_prev_next.py +++ b/linking_articles_prev_next.py @@ -8,11 +8,14 @@ import os import json import re import argparse +import pypandoc +from jinja2 import Environment, FileSystemLoader # Configurer argparse pour prendre le blog en argument parser = argparse.ArgumentParser(description='Générer une liste des derniers articles de blog.') parser.add_argument('blog', type=str, help='Nom du dossier du blog à traiter', default='tykayn_blog') args = parser.parse_args() +limit_articles_on_index = 10 # Fonction pour extraire le basename d'un fichier def get_basename(file_name): @@ -21,6 +24,7 @@ def get_basename(file_name): # Chemin du dossier contenant les fichiers orgmode directory = f'sources/{args.blog}/lang_fr' destination_json = f'sources/{args.blog}/build' +destination_html = f'html-websites/{args.blog}/' # Dictionnaire pour stocker les informations des fichiers files_dict = {} @@ -33,11 +37,16 @@ for file_name in os.listdir(directory): basename = get_basename(file_name) date_str, annee, slug = find_year_and_slug_on_filename(basename) tags = extract_tags_from_file(file_path, global_config['excluded_tags']) + # Convertir les tags en liste si c'est un set if isinstance(tags, set): tags = list(tags) boom = basename.split('__') title = find_first_level1_title(content) + + # Convertir le contenu Org en HTML + html_content = pypandoc.convert_text(content, 'html', format='org') + files_dict[f"{annee}/{slug}"] = { 'path': file_path, 'basename': basename, @@ -48,7 +57,9 @@ for file_name in os.listdir(directory): 'tags': tags, # Assurez-vous que c'est une liste 'title': title, 'next': None, - 'previous': None + 'previous': None, + 'org_content': content, # Contenu Org original + 'html_content': html_content # Contenu HTML converti } # Trier les basenames par ordre décroissant @@ -67,6 +78,20 @@ with open(destination_json+'/articles_info.json', 'w', encoding='utf-8') as json json_file.write(files_dict_serialized) + +print(f"Nombre d'articles trouvés : {len(sorted_basenames)}") +count_articles_updated = 0 + +for basename, info in files_dict.items(): + date_str = info['date'] + + if date_str > '20240101': + count_articles_updated += 1 + +print(f"Nombre d'articles mis à jour après le 01 01 2024 : {count_articles_updated}") + + + # Afficher le dictionnaire pour vérification # for basename, info in files_dict.items(): # print(f"Article: {basename}") @@ -76,3 +101,38 @@ with open(destination_json+'/articles_info.json', 'w', encoding='utf-8') as json # print(f" Previous: {info['previous']}") # print(f" Next: {info['next']}") # print("-" * 40) + +def generate_blog_index(json_file, template_file, output_file): + """ + Génère la page d'index du blog à partir des informations JSON et d'un template Jinja2. + + :param json_file: Chemin du fichier JSON contenant les informations des articles. + :param template_file: Chemin du fichier template Jinja2. + :param output_file: Chemin du fichier HTML de sortie. + """ + # Charger les données JSON + with open(json_file, 'r', encoding='utf-8') as f: + articles_info = json.load(f) + + # Trier les articles par date (ou par slug) et prendre les 10 derniers + sorted_articles = sorted(articles_info.values(), key=lambda x: x['date'], reverse=True)[:10] + + # Configurer Jinja2 + env = Environment(loader=FileSystemLoader('.')) + template = env.get_template(template_file) + + # Rendre le template avec les données + output_html = template.render( + template_content=configs_sites[args.blog], + articles=sorted_articles[:global_config['posts_per_page']], + articles_info=articles_info + ) + + # Écrire le fichier de sortie + with open(output_file, 'w', encoding='utf-8') as f: + f.write(output_html) + + print(f"Page d'index générée dans {output_file}") + +# Appel de la fonction pour générer la page d'index +generate_blog_index(destination_json + '/articles_info.json', 'templates/html/index_template.html.jinja', destination_html + '/index.html') diff --git a/templates/html/index_template.html.jinja b/templates/html/index_template.html.jinja new file mode 100644 index 00000000..d706fd26 --- /dev/null +++ b/templates/html/index_template.html.jinja @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + {{template_content['TITLE']}} + + + + + + + + + + + +
+ +
+ {% for article in articles %} + + {% endfor %} +
+ +
+ + + + \ No newline at end of file diff --git a/templates/html/static.html b/templates/html/static.html deleted file mode 100644 index 64c47536..00000000 --- a/templates/html/static.html +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - - - - - - - - - - - - $$TITLE$$ - - - - - - - - - - - -
-
- -
- $$BANNIERE_ENTETE$$ - -
- -
-
-
- $$ARTICLE$$ -
-
- -
- - - \ No newline at end of file diff --git a/templates/html/static.html.jinja b/templates/html/static.html.jinja new file mode 100644 index 00000000..af5d4d44 --- /dev/null +++ b/templates/html/static.html.jinja @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + {template_content['TITLE']} + + + + + + + + + + + +
+ +
+
+ {html_content} +

+ {after_article} +

+
+
+ +
+ + + + \ No newline at end of file diff --git a/utils.py b/utils.py index 0c968a51..c4df5cc0 100644 --- a/utils.py +++ b/utils.py @@ -221,8 +221,8 @@ def extract_tags_from_file(file_path, excluded_tags): tags.add(tag) tag_found = True - if not tag_found: - print('no tag in the article', file_path) + # if not tag_found: + # print('no tag in the article', file_path) return tags def remove_properties_section(text): diff --git a/website_config.py b/website_config.py index 10cf49b8..82557d33 100644 --- a/website_config.py +++ b/website_config.py @@ -19,6 +19,9 @@ global_config = { "wanda","bouffe","anniversaire","conventions","Japan Expo","3.0","cours","! Q","dessin","mariage", "réutilisation","sketch","road trip","kot","vélo","Bruxelles","Dieppe"] } + + + configs_sites = { "cipherbliss_blog": { "DOSSIER_SOURCE": "cipherbliss_blog", @@ -183,3 +186,42 @@ configs_sites = { "BANNIERE_ENTETE_ALT": "Bannière du site", }, } + + +# Configuration par défaut +default_config = { + "BLOG_TITLE": "Titre par défaut", + "BLOG_SUBTITLE": "Sous-titre par défaut", + "AUTHOR": "Auteur par défaut", + "LOCALE": "fr_FR", + "DESCRIPTION": "Description par défaut", + "NDD": "https://example.com", + "EMAIL": "contact@example.com", + "SITE_ICON": "https://example.com/icon.png", + "SITE_ICON_TYPE": "image/png", + "NAVIGATION": """ + + """, + "BANNIERE_ENTETE": "https://example.com/banner.jpg", + "BANNIERE_ENTETE_ALT": "Bannière par défaut", +} + +def fill_missing_config(site_config): + """ + Remplit les valeurs manquantes dans la configuration du site avec celles de la configuration par défaut. + + :param site_config: Dictionnaire contenant la configuration du site. + :return: Dictionnaire avec les valeurs manquantes remplies. + """ + for key, value in default_config.items(): + if key not in site_config: + site_config[key] = value + return site_config + +# Exemple d'utilisation avec les configurations des sites +for site_name, site_config in configs_sites.items(): + configs_sites[site_name] = fill_missing_config(site_config) \ No newline at end of file