diff --git a/linking_articles_prev_next.py b/linking_articles_prev_next.py index e4efc720..daa7d05a 100644 --- a/linking_articles_prev_next.py +++ b/linking_articles_prev_next.py @@ -53,6 +53,8 @@ for file_name in os.listdir(directory): 'slug': slug, 'slug_with_year': f"{annee}/{slug}", 'date': boom[0], + 'date_formattee': datetime.strptime(date_str, '%Y%m%d%H%M%S').strftime('%d %B %Y à %H:%M:%S') if len(date_str) == 14 else datetime.strptime(date_str, '%Y%m%dT%H%M%S').strftime('%d %B %Y à %H:%M:%S'), + # 'date_formattee': datetime.strptime(date_str, '%Y%m%d%H%M%S').strftime('%d %B %Y à %H:%M:%S'), 'annee': annee, 'tags': tags, # Assurez-vous que c'est une liste 'title': title, @@ -68,9 +70,11 @@ sorted_basenames = sorted(files_dict.keys(), reverse=True) # Ajouter les noms des articles suivant et précédent for i in range(len(sorted_basenames)): basename = sorted_basenames[i] + print('basename', basename) if i > 0: files_dict[basename]['previous'] = sorted_basenames[i - 1] if i < len(sorted_basenames) - 1: + files_dict[basename]['next'] = sorted_basenames[i + 1] with open(destination_json+'/articles_info.json', 'w', encoding='utf-8') as json_file: @@ -115,7 +119,6 @@ def generate_blog_index(json_file, template_file, output_file): template_content=configs_sites[args.blog], articles=sorted_articles[:global_config['posts_per_page']], articles_others=sorted_articles[10:] - ) # Écrire le fichier de sortie @@ -125,4 +128,48 @@ def generate_blog_index(json_file, template_file, output_file): 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') +generate_blog_index(destination_json + '/articles_info.json', 'templates/html/index.html.jinja', destination_html + '/index.html') + + +def generate_article_pages(json_file, template_file, output_dir): + """ + Génère les pages HTML pour chaque article à 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_dir: Répertoire de sortie pour les fichiers HTML. + """ + # Charger les données JSON + with open(json_file, 'r', encoding='utf-8') as f: + articles_info = json.load(f) + + # Configurer Jinja2 + env = Environment(loader=FileSystemLoader('.')) + template = env.get_template(template_file) + + # Générer les pages pour chaque article + for article in articles_info.values(): + output_html = template.render( + template_content=configs_sites[args.blog], + article=article + ) + + # Construire le chemin de sortie en fonction du slug avec l'année + output_subdir = os.path.join(output_dir, article['slug_with_year']) + os.makedirs(output_subdir, exist_ok=True) + output_file = os.path.join(output_subdir ,"index.html") + + + + # print(output_file) + # Écrire le fichier de sortie + 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/templates/html/article.html.jinja b/templates/html/article.html.jinja new file mode 100644 index 00000000..36005f53 --- /dev/null +++ b/templates/html/article.html.jinja @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + {{template_content['TITLE']}} + + + + + + + + + + + +
+ +
+ +
+
+ + {{ article.title }} +
+ +
{{ article.html_content | safe }}
+ +
+ +
+
+ {% if article.previous %} + + {% endif %} + {% if article.next %} + + {% endif %} +
+ +
+ +
+ + + + \ No newline at end of file diff --git a/templates/html/index_template.html.jinja b/templates/html/index.html.jinja similarity index 99% rename from templates/html/index_template.html.jinja rename to templates/html/index.html.jinja index 9421a8b2..9210b9f8 100644 --- a/templates/html/index_template.html.jinja +++ b/templates/html/index.html.jinja @@ -76,7 +76,7 @@ {{ article.title }}
- {{article.date}} + {{article.date_formattee}}
{{ article.html_content | safe }}
diff --git a/templates/html/site_head.html.jinja b/templates/html/site_head.html.jinja new file mode 100644 index 00000000..143a3b6d --- /dev/null +++ b/templates/html/site_head.html.jinja @@ -0,0 +1,20 @@ + + + + + + + + + + + + + {{ template_content['TITLE'] }} + + + + + + + \ No newline at end of file diff --git a/website_config.py b/website_config.py index 82557d33..6d7b5a4b 100644 --- a/website_config.py +++ b/website_config.py @@ -208,6 +208,7 @@ default_config = { """, "BANNIERE_ENTETE": "https://example.com/banner.jpg", "BANNIERE_ENTETE_ALT": "Bannière par défaut", + "SOUTIEN": "Si vous aimez ce que nous faisons, soutenez nous et partagez nos écrits. Vous pouvez nous faire un don sur liberapay.com/cipherbliss." } def fill_missing_config(site_config):