From 367c7754c641a4618218c027a5cdd5207dff8400 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Thu, 20 Feb 2025 15:31:44 +0100 Subject: [PATCH] generate tags pages with jinja template --- gather_tags_in_json.py | 47 +++---- .../index.html | 12 +- html-websites/dragonfeu_blog/index.html | 7 +- linking_articles_prev_next.py | 11 +- .../20250129143536__pouet-pouet-hop.org | 5 +- templates/html/article.html.jinja | 10 +- templates/html/tag.html.jinja | 118 ++++++++++++++++++ utils.py | 10 +- 8 files changed, 178 insertions(+), 42 deletions(-) create mode 100644 templates/html/tag.html.jinja diff --git a/gather_tags_in_json.py b/gather_tags_in_json.py index b812d52a..621e6475 100644 --- a/gather_tags_in_json.py +++ b/gather_tags_in_json.py @@ -2,22 +2,24 @@ import argparse import json from collections import defaultdict +from jinja2 import Environment, FileSystemLoader +import json from utils import * from website_config import * parser = argparse.ArgumentParser(description="Générer un site Web à partir de fichiers HTML.") -parser.add_argument("blog_name", help="Le chemin vers le dossier contenant les fichiers HTML.") +parser.add_argument("blog", help="Le chemin vers le dossier contenant les fichiers HTML.") args = parser.parse_args() # Configuration -blog_folder = args.blog_name +blog_folder = args.blog directory_base = f'sources/{blog_folder}' # Remplacez par le chemin de votre dossier directory_fr = f'{directory_base}/lang_fr' # Remplacez par le chemin de votre dossier output_file = f'sources/{blog_folder}/converted/tags.json' # Fichier de sortie html_output_folder = f'html-websites/{blog_folder}/tag' # Dossier de sortie pour les fichiers HTML html_output_folder_index = f'html-websites/{blog_folder}/tags' # Dossier de sortie pour les fichiers HTML -excluded_tags = {'PROPERTIES', 'CREATED', 'ID', 'END'} +excluded_tags = {'PROPERTIES', 'CREATED', 'ID', 'END', 'CUSTOM_ID'} automatic_tagging_enabled = global_config['automatic_tagging_enabled'] count_not_tagged_files = 0 @@ -100,31 +102,34 @@ def generate_html_pages_for_all_tags(tag_to_files, html_output_folder): def generate_index_page(tag_to_files, html_output_folder): - index_content = f""" - -
-

Index des tags

- - -
- - """ + print(tags_count) + + # Préparer les données pour le template + data = { + 'tags': tags_count, + 'template_content' : template_content, + 'html_output_folder': html_output_folder + } + + # Rendre le template avec les données + output_html = template.render(data) os.makedirs(os.path.dirname(html_output_folder_index), exist_ok=True) index_file_path = os.path.join(html_output_folder_index, "index.html") with open(index_file_path, 'w', encoding='utf-8') as index_file: - index_file.write(index_content) + index_file.write(output_html) print(f"Page d'index générée dans {index_file_path}") @@ -140,4 +145,4 @@ if __name__ == "__main__": print(f"Tags et fichiers associés ont été enregistrés dans {output_file}") print(f"Pages HTML générées dans {html_output_folder}") - # print(f"Pages non tagguées: {count_not_tagged_files}") # TODO + print(f"Pages non tagguées: {count_not_tagged_files}") diff --git a/html-websites/dragonfeu_blog/2024/strategie-mitigation-accident-fusion-coeur-epr2/index.html b/html-websites/dragonfeu_blog/2024/strategie-mitigation-accident-fusion-coeur-epr2/index.html index dc141d77..2dbde845 100644 --- a/html-websites/dragonfeu_blog/2024/strategie-mitigation-accident-fusion-coeur-epr2/index.html +++ b/html-websites/dragonfeu_blog/2024/strategie-mitigation-accident-fusion-coeur-epr2/index.html @@ -576,18 +576,18 @@ href="https://medium.com/tag/fukushima?source=post_page-----f82c1d15ed58-------- - logiciel + art entreprise - AI - - art - bd cours + AI + + logiciel + @@ -603,7 +603,7 @@ href="https://medium.com/tag/fukushima?source=post_page-----f82c1d15ed58-------- diff --git a/html-websites/dragonfeu_blog/index.html b/html-websites/dragonfeu_blog/index.html index 8796bab6..b8a7229c 100644 --- a/html-websites/dragonfeu_blog/index.html +++ b/html-websites/dragonfeu_blog/index.html @@ -83,7 +83,7 @@
- +
@@ -97,10 +97,11 @@ 29 January 2025 à 14:35:36

pouet pouet hop

-

https://placehold.co/600x400/png

coin coin

+

https://placehold.co/600x400/png

+

lorem bla bla

diff --git a/linking_articles_prev_next.py b/linking_articles_prev_next.py index 30a65207..c01347db 100644 --- a/linking_articles_prev_next.py +++ b/linking_articles_prev_next.py @@ -58,10 +58,15 @@ for file_name in os.listdir(directory): if isinstance(tags, set): tags = list(tags) boom = basename.split('__') + # Convertir le contenu Org en HTML title = find_first_level1_title(content) - # Convertir le contenu Org en HTML - html_content = pypandoc.convert_text(content, 'html', format='org') + # Désactiver les warning d'identifiant dupliqué dans la conversion pandoc + content_without_h1 = re.sub(r'^\*.*?$', '', content, count=1, flags=re.MULTILINE) + + html_content = pypandoc.convert_text(content_without_h1, 'html', format='org') + + # html_content = pypandoc.convert_text(content, 'html', format='org') files_dict[f"{annee}/{slug}"] = { 'path': file_path, @@ -186,8 +191,6 @@ def generate_article_pages(json_file, template_file, output_dir): with open(output_file, 'w', encoding='utf-8') as f: f.write(output_html) - # print(f"Page générée pour l'article {article['title']} dans {output_file}") - # Appel de la fonction pour générer les pages des articles generate_article_pages(destination_json + '/articles_info.json', 'templates/html/article.html.jinja', destination_html) diff --git a/sources/dragonfeu_blog/lang_fr/20250129143536__pouet-pouet-hop.org b/sources/dragonfeu_blog/lang_fr/20250129143536__pouet-pouet-hop.org index fd0bd1ba..f29a7a05 100644 --- a/sources/dragonfeu_blog/lang_fr/20250129143536__pouet-pouet-hop.org +++ b/sources/dragonfeu_blog/lang_fr/20250129143536__pouet-pouet-hop.org @@ -17,8 +17,11 @@ * pouet pouet hop #+CAPTION: This is the caption for the next figure #+NAME: fig:placeland -[[https://placehold.co/600x400/png]] coin coin [[https://miro.medium.com/v2/resize:fit:490/0*R7R5WF5O-tznduZZ.jpg]] + +[[https://placehold.co/600x400/png]] + +lorem bla bla \ No newline at end of file diff --git a/templates/html/article.html.jinja b/templates/html/article.html.jinja index 2dbbaed7..f27ae8db 100644 --- a/templates/html/article.html.jinja +++ b/templates/html/article.html.jinja @@ -28,8 +28,8 @@ -
-