mirror of
https://forge.chapril.org/tykayn/orgmode-to-gemini-blog
synced 2025-06-20 09:04:42 +02:00
move on index build and linking previous and next articles
This commit is contained in:
parent
7d221d970a
commit
16b93f380e
1711 changed files with 231792 additions and 838 deletions
73
linking_articles_prev_next.py
Normal file
73
linking_articles_prev_next.py
Normal file
|
@ -0,0 +1,73 @@
|
|||
#!/bin/python3
|
||||
# import argparse
|
||||
|
||||
from utils import *
|
||||
from website_config import configs_sites
|
||||
|
||||
# trouver les articles précédents et suivants
|
||||
import os
|
||||
import json
|
||||
import re
|
||||
|
||||
# Fonction pour extraire le basename d'un fichier
|
||||
def get_basename(file_name):
|
||||
return os.path.splitext(file_name)[0]
|
||||
|
||||
# Chemin du dossier contenant les fichiers orgmode
|
||||
directory = 'sources/tykayn_blog/lang_fr'
|
||||
|
||||
# Dictionnaire pour stocker les informations des fichiers
|
||||
files_dict = {}
|
||||
|
||||
# Parcourir les fichiers du dossier
|
||||
for file_name in os.listdir(directory):
|
||||
if file_name.endswith('.org'):
|
||||
file_path = os.path.join(directory, file_name)
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
basename = get_basename(file_name)
|
||||
date_str, annee, slug = find_year_and_slug_on_filename(basename)
|
||||
tags = extract_tags_from_file(file_path, global_config['excluded_tags'])
|
||||
# Convertir les tags en liste si c'est un set
|
||||
if isinstance(tags, set):
|
||||
tags = list(tags)
|
||||
boom = basename.split('__')
|
||||
title = find_first_level1_title(content)
|
||||
files_dict[f"{annee}/{slug}"] = {
|
||||
'path': file_path,
|
||||
'basename': basename,
|
||||
'slug': slug,
|
||||
'slug_with_year': f"{annee}/{slug}",
|
||||
'date': boom[0],
|
||||
'annee': annee,
|
||||
'tags': tags, # Assurez-vous que c'est une liste
|
||||
'title': title,
|
||||
'next': None,
|
||||
'previous': None
|
||||
}
|
||||
|
||||
# Trier les basenames par ordre décroissant
|
||||
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]
|
||||
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('articles_info.json', 'w', encoding='utf-8') as json_file:
|
||||
files_dict_serialized = json.dumps(files_dict, ensure_ascii=False, indent=4)
|
||||
json_file.write(files_dict_serialized)
|
||||
|
||||
|
||||
# Afficher le dictionnaire pour vérification
|
||||
# for basename, info in files_dict.items():
|
||||
# print(f"Article: {basename}")
|
||||
# print(f" Path: {info['path']}")
|
||||
# print(f" tags: {info['tags']}")
|
||||
# print(f" title: {info['title']}")
|
||||
# print(f" Previous: {info['previous']}")
|
||||
# print(f" Next: {info['next']}")
|
||||
# print("-" * 40)
|
Loading…
Add table
Add a link
Reference in a new issue