move back files

This commit is contained in:
Tykayn 2025-02-20 17:14:53 +01:00 committed by tykayn
parent b1c8937fc9
commit d885085861
967 changed files with 152 additions and 56 deletions

View file

@ -15,6 +15,10 @@ import time # Importer le module time
# Démarrer le chronomètre # Démarrer le chronomètre
start_time = time.time() start_time = time.time()
# pour tester
generate_linkings_json = True
generate_articles = True
run_pandoc = True # le plus long quand on a beaucoup d'articles
# Configurer argparse pour prendre le blog en argument # Configurer argparse pour prendre le blog en argument
parser = argparse.ArgumentParser(description='Générer une liste des derniers articles de blog.') parser = argparse.ArgumentParser(description='Générer une liste des derniers articles de blog.')
@ -41,9 +45,10 @@ def get_first_picture_url(content):
else: else:
return None return None
if generate_linkings_json :
# Parcourir les fichiers du dossier # Parcourir les fichiers du dossier
for file_name in os.listdir(directory): for file_name in os.listdir(directory):
if file_name.endswith('.org'): if file_name.endswith('.org'):
file_path = os.path.join(directory, file_name) file_path = os.path.join(directory, file_name)
with open(file_path, "r", encoding="utf-8") as f: with open(file_path, "r", encoding="utf-8") as f:
@ -64,7 +69,11 @@ for file_name in os.listdir(directory):
# Désactiver les warning d'identifiant dupliqué dans la conversion pandoc # Désactiver les warning d'identifiant dupliqué dans la conversion pandoc
content_without_h1 = re.sub(r'^\*.*?$', '', content, count=1, flags=re.MULTILINE) content_without_h1 = re.sub(r'^\*.*?$', '', content, count=1, flags=re.MULTILINE)
if run_pandoc:
html_content = pypandoc.convert_text(content_without_h1, 'html', format='org') html_content = pypandoc.convert_text(content_without_h1, 'html', format='org')
else:
html_content = content_without_h1
# html_content = pypandoc.convert_text(content, 'html', format='org') # html_content = pypandoc.convert_text(content, 'html', format='org')
@ -78,7 +87,7 @@ for file_name in os.listdir(directory):
'first_picture_url' : get_first_picture_url(content), 'first_picture_url' : get_first_picture_url(content),
'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') if len(date_str) == 15 else datetime.strptime(date_str, '%Y-%m-%d').strftime('%d %B %Y'), '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') if len(date_str) == 15 else datetime.strptime(date_str, '%Y-%m-%d').strftime('%d %B %Y'),
'annee': annee, 'annee': annee,
'tags': tags, # Assurez-vous que c'est une liste 'tags': tags,
'title': title, 'title': title,
'next': None, 'next': None,
'previous': None, 'previous': None,
@ -132,17 +141,18 @@ def generate_blog_index(json_file, template_file, output_file):
articles_info = json.load(f) articles_info = json.load(f)
# Trier les articles par date (ou par slug) et prendre les 10 derniers # 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] sorted_articles = sorted(articles_info.values(), key=lambda x: x['date'], reverse=True)[:global_config['posts_per_page']]
# Configurer Jinja2 # Configurer Jinja2
env = Environment(loader=FileSystemLoader('.')) env = Environment(loader=FileSystemLoader('.'))
template = env.get_template(template_file) template = env.get_template(template_file)
articles_others = sorted(articles_info.values(), key=lambda x: x['date'], reverse=True)[10:]
# Rendre le template avec les données # Rendre le template avec les données
output_html = template.render( output_html = template.render(
template_content=configs_sites[args.blog], template_content=configs_sites[args.blog],
articles=sorted_articles[:global_config['posts_per_page']], articles=sorted_articles[:global_config['posts_per_page']],
articles_others=sorted_articles articles_others=articles_others
) )
# Écrire le fichier de sortie # Écrire le fichier de sortie
@ -163,6 +173,8 @@ def generate_article_pages(json_file, template_file, output_dir):
:param template_file: Chemin du fichier template Jinja2. :param template_file: Chemin du fichier template Jinja2.
:param output_dir: Répertoire de sortie pour les fichiers HTML. :param output_dir: Répertoire de sortie pour les fichiers HTML.
""" """
print('generate_article_pages: ouverture du json')
# Charger les données JSON # Charger les données JSON
with open(json_file, 'r', encoding='utf-8') as f: with open(json_file, 'r', encoding='utf-8') as f:
articles_info = json.load(f) articles_info = json.load(f)
@ -182,7 +194,7 @@ def generate_article_pages(json_file, template_file, output_dir):
# Construire le chemin de sortie en fonction du slug avec l'année # Construire le chemin de sortie en fonction du slug avec l'année
output_subdir = os.path.join(output_dir, article['slug_with_year']) output_subdir = os.path.join(output_dir, article['slug_with_year'])
print('make subdir: ',output_subdir) # print('make subdir: ',output_subdir)
@ -195,9 +207,11 @@ def generate_article_pages(json_file, template_file, output_dir):
# Écrire le fichier de sortie # Écrire le fichier de sortie
with open(output_file, 'w', encoding='utf-8') as f: with open(output_file, 'w', encoding='utf-8') as f:
f.write(output_html) f.write(output_html)
print('generate_article_pages: fin de génération de l index')
if generate_articles:
# Appel de la fonction pour générer les pages des articles # 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) generate_article_pages(destination_json + '/articles_info.json', 'templates/html/article.html.jinja', destination_html)
# À la fin du script, calculer et afficher le temps d'exécution # À la fin du script, calculer et afficher le temps d'exécution
execution_time = time.time() - start_time execution_time = time.time() - start_time

Some files were not shown because too many files have changed in this diff Show more