mirror of
https://forge.chapril.org/tykayn/orgmode-to-gemini-blog
synced 2025-06-20 09:04:42 +02:00
rangement des articles sur l'index gemini en date décroissante
This commit is contained in:
parent
dbbae888f4
commit
6050907dc9
2 changed files with 62 additions and 48 deletions
|
@ -370,39 +370,41 @@ for basename, info in files_dict.items():
|
|||
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)
|
||||
try:
|
||||
# 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)[:global_config['posts_per_page']]
|
||||
# Trier les articles par date
|
||||
sorted_articles = sorted(articles_info.values(), key=lambda x: x['date'], reverse=True)
|
||||
|
||||
# Séparer les articles récents et les autres
|
||||
recent_articles = sorted_articles[:global_config['posts_per_page']]
|
||||
articles_others = sorted_articles[global_config['posts_per_page']:]
|
||||
|
||||
# Configurer Jinja2
|
||||
env = Environment(loader=FileSystemLoader('.'))
|
||||
template = env.get_template(template_file)
|
||||
# Configurer Jinja2
|
||||
env = Environment(loader=FileSystemLoader('.'))
|
||||
template = env.get_template(template_file)
|
||||
template_content = get_blog_template_conf(args.blog)
|
||||
|
||||
articles_others = sorted(articles_info.values(), key=lambda x: x['date'], reverse=True)[10:]
|
||||
# Générer le HTML
|
||||
output_index_html = template.render(
|
||||
template_content=template_content,
|
||||
articles=recent_articles,
|
||||
articles_others=articles_others
|
||||
)
|
||||
|
||||
template_content = get_blog_template_conf(args.blog)
|
||||
# Générer le contenu GMI
|
||||
gmi_list_articles = ''
|
||||
current_year = None
|
||||
for article in sorted_articles:
|
||||
if article['annee'] != current_year:
|
||||
current_year = article['annee']
|
||||
gmi_list_articles += f"\n## {current_year}\n\n"
|
||||
gmi_list_articles += f"=> {article['annee']}/{article['slug']}.gmi {article['title']}\n"
|
||||
|
||||
# Rendre le template avec les données
|
||||
output_index_html = template.render(
|
||||
template_content=template_content,
|
||||
articles=sorted_articles[:global_config['posts_per_page']],
|
||||
articles_others=articles_others
|
||||
)
|
||||
|
||||
gmi_list_articles = ''
|
||||
|
||||
for basename, article in files_dict.items():
|
||||
gmi_list_articles += f"=> {article['annee']}/{article['slug']}.gmi {article['title']}\n"
|
||||
|
||||
output_index_gmi = f"""
|
||||
output_index_gmi = f"""
|
||||
# {template_content['BLOG_TITLE']}
|
||||
===============================================
|
||||
|
||||
|
@ -420,15 +422,13 @@ Dernière mise à jour: {dt.datetime.now().strftime('%Y-%m-%d, %H:%M:%S')}
|
|||
|
||||
{template_content['SITE_ICON']}
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------
|
||||
Index des {len(files_dict.items())} articles:
|
||||
# Index des {len(sorted_articles)} articles:
|
||||
|
||||
{gmi_list_articles}
|
||||
|
||||
-----------------------------------------------
|
||||
Pages:
|
||||
# Pages:
|
||||
=> index.gmi Index
|
||||
=> tags.gmi Tags
|
||||
|
||||
|
@ -437,20 +437,28 @@ Pages:
|
|||
-----------------------------------------------
|
||||
{template_content['WEBSITE_GENERATOR_DESCRIPTION']}
|
||||
{template_content['WEBSITE_GENERATOR']}
|
||||
"""
|
||||
"""
|
||||
|
||||
gmi_index_file=destination_gmi+'index.gmi'
|
||||
|
||||
# Écrire le fichier de sortie en html et en gmi
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
f.write(output_index_html)
|
||||
#print(f"Page d'index générée dans {output_file}")
|
||||
# Écrire les fichiers de sortie
|
||||
gmi_index_file = os.path.join(destination_gmi, 'index.gmi')
|
||||
|
||||
os.makedirs(os.path.dirname(gmi_index_file), exist_ok=True)
|
||||
#print('gmi_index_file', gmi_index_file)
|
||||
with open(gmi_index_file, 'w', encoding='utf-8') as f:
|
||||
f.write(output_index_gmi)
|
||||
#print(f"Page d'index gemini générée dans {gmi_index_file}")
|
||||
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
||||
os.makedirs(os.path.dirname(gmi_index_file), exist_ok=True)
|
||||
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
f.write(output_index_html)
|
||||
|
||||
with open(gmi_index_file, 'w', encoding='utf-8') as f:
|
||||
f.write(output_index_gmi)
|
||||
|
||||
except IOError as e:
|
||||
print(f"Erreur lors de la lecture/écriture des fichiers: {e}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"Erreur inattendue: {e}")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
# Générer la page d'index seulement si des articles ont été convertis
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue