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,36 +370,38 @@ for basename, info in files_dict.items():
|
||||||
def generate_blog_index(json_file, template_file, output_file):
|
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.
|
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.
|
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
# 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)
|
||||||
|
|
||||||
# Trier les articles par date (ou par slug) et prendre les 10 derniers
|
# Trier les articles par date
|
||||||
sorted_articles = sorted(articles_info.values(), key=lambda x: x['date'], reverse=True)[:global_config['posts_per_page']]
|
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
|
# 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:]
|
|
||||||
|
|
||||||
template_content = get_blog_template_conf(args.blog)
|
template_content = get_blog_template_conf(args.blog)
|
||||||
|
|
||||||
# Rendre le template avec les données
|
# Générer le HTML
|
||||||
output_index_html = template.render(
|
output_index_html = template.render(
|
||||||
template_content=template_content,
|
template_content=template_content,
|
||||||
articles=sorted_articles[:global_config['posts_per_page']],
|
articles=recent_articles,
|
||||||
articles_others=articles_others
|
articles_others=articles_others
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Générer le contenu GMI
|
||||||
gmi_list_articles = ''
|
gmi_list_articles = ''
|
||||||
|
current_year = None
|
||||||
for basename, article in files_dict.items():
|
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"
|
gmi_list_articles += f"=> {article['annee']}/{article['slug']}.gmi {article['title']}\n"
|
||||||
|
|
||||||
output_index_gmi = f"""
|
output_index_gmi = f"""
|
||||||
|
@ -420,15 +422,13 @@ Dernière mise à jour: {dt.datetime.now().strftime('%Y-%m-%d, %H:%M:%S')}
|
||||||
|
|
||||||
{template_content['SITE_ICON']}
|
{template_content['SITE_ICON']}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
Index des {len(files_dict.items())} articles:
|
# Index des {len(sorted_articles)} articles:
|
||||||
|
|
||||||
{gmi_list_articles}
|
{gmi_list_articles}
|
||||||
|
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
Pages:
|
# Pages:
|
||||||
=> index.gmi Index
|
=> index.gmi Index
|
||||||
=> tags.gmi Tags
|
=> tags.gmi Tags
|
||||||
|
|
||||||
|
@ -439,18 +439,26 @@ Pages:
|
||||||
{template_content['WEBSITE_GENERATOR']}
|
{template_content['WEBSITE_GENERATOR']}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
gmi_index_file=destination_gmi+'index.gmi'
|
# Écrire les fichiers de sortie
|
||||||
|
gmi_index_file = os.path.join(destination_gmi, 'index.gmi')
|
||||||
|
|
||||||
|
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
||||||
|
os.makedirs(os.path.dirname(gmi_index_file), exist_ok=True)
|
||||||
|
|
||||||
# Écrire le fichier de sortie en html et en gmi
|
|
||||||
with open(output_file, 'w', encoding='utf-8') as f:
|
with open(output_file, 'w', encoding='utf-8') as f:
|
||||||
f.write(output_index_html)
|
f.write(output_index_html)
|
||||||
#print(f"Page d'index générée dans {output_file}")
|
|
||||||
|
|
||||||
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:
|
with open(gmi_index_file, 'w', encoding='utf-8') as f:
|
||||||
f.write(output_index_gmi)
|
f.write(output_index_gmi)
|
||||||
#print(f"Page d'index gemini générée dans {gmi_index_file}")
|
|
||||||
|
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
|
# Générer la page d'index seulement si des articles ont été convertis
|
||||||
|
|
|
@ -115,10 +115,14 @@
|
||||||
|
|
||||||
{% if articles_others %}
|
{% if articles_others %}
|
||||||
<div class="more-articles">
|
<div class="more-articles">
|
||||||
<p>Y'en a un peu plus, je vous le mets...</p>
|
<h2>Y'en a un peu plus, je vous le mets...</h2>
|
||||||
|
|
||||||
|
{% for article in articles_others %}
|
||||||
|
{% if loop.first or article.annee != articles_others[loop.index0 - 1].annee %}
|
||||||
|
<div class="more-articles">
|
||||||
|
<h3>{{article.annee}}</h3>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for article in articles_others %}
|
|
||||||
<article class="more-content">
|
<article class="more-content">
|
||||||
<div class="article-title">
|
<div class="article-title">
|
||||||
|
|
||||||
|
@ -135,9 +139,10 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<a href="/{{ article.slug_with_year }}">
|
<a href="/{{ article.slug_with_year }}">
|
||||||
<span class="article-date-inline">
|
<!-- <span class="article-date-inline">
|
||||||
{{article.annee}}
|
{{article.annee}}
|
||||||
</span> {{ article.title }}
|
</span> -->
|
||||||
|
{{ article.title }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -145,7 +150,8 @@
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</main>
|
</main>
|
||||||
<footer class="site-footer has-top-divider">
|
<footer class="site-footer has-top-divider">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue