2024-11-12 00:55:21 +01:00
|
|
|
#!/bin/python3
|
2024-11-15 23:55:20 +01:00
|
|
|
# import argparse
|
|
|
|
|
|
|
|
from utils import *
|
2024-11-12 00:55:21 +01:00
|
|
|
from website_config import configs_sites
|
|
|
|
|
2024-11-20 00:24:09 +01:00
|
|
|
# trouver les articles précédents et suivants
|
|
|
|
import os
|
|
|
|
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/qzine_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'])
|
|
|
|
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,
|
|
|
|
'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]
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
|
2024-11-15 23:55:20 +01:00
|
|
|
# parser = argparse.ArgumentParser(description="Générer un site Web à partir de fichiers HTML.")
|
|
|
|
# parser.add_argument("blog_name", help="Le chemin vers le dossier contenant les fichiers HTML.")
|
2024-11-12 00:55:21 +01:00
|
|
|
# parser.add_argument("--title", "-t", default="Mon site Web", help="Le titre du site Web.")
|
|
|
|
# parser.add_argument("--style", default="templates/style_general.css", help="Le chemin vers le fichier de style CSS.")
|
2024-11-15 23:55:20 +01:00
|
|
|
# args = parser.parse_args()
|
|
|
|
|
|
|
|
# print(configs_sites[args.blog_name]['DESCRIPTION'])
|
|
|
|
# tester la génération de slug sur un fichier org donné
|
|
|
|
|
2024-11-19 13:49:39 +01:00
|
|
|
# basename_file = '20111126170159_cipherbliss_blog_120_bienvenue-sur-informageek.org'
|
|
|
|
# found_slug = find_slug_in_file_basename(basename_file)
|
|
|
|
# print('slug found:',found_slug)
|
|
|
|
#
|
|
|
|
# basename_file = '20200803124344_blog_cil_gometz_11_ecrire-une-comptine-en-python-bonjour-le-jour.org'
|
|
|
|
# found_slug = find_slug_in_file_basename(basename_file)
|
|
|
|
# print('slug found:',found_slug)
|
|
|
|
#
|
|
|
|
# basename_file = '20241115010205_cipherbliss_blog_suivi-de-rédaction-de-livre-orgmode.org'
|
|
|
|
# found_slug = find_slug_in_file_basename(basename_file)
|
|
|
|
# print('slug found:',found_slug)
|
|
|
|
#
|
|
|
|
# basename_file = '20061125015032_tkblog_864_pourquoi-mee2-est-il-une-flamme.org'
|
|
|
|
# found_slug = find_slug_in_file_basename(basename_file)
|
|
|
|
# print('slug found:',found_slug)
|
2024-11-15 23:55:20 +01:00
|
|
|
|
2024-11-19 13:49:39 +01:00
|
|
|
# trouver le bon slug avec l'année
|
2024-11-12 00:55:21 +01:00
|
|
|
|
2024-11-19 13:49:39 +01:00
|
|
|
# fichier = 'sources/tykayn_blog/lang_fr/20170708T095535_tkblog_918_7-techniques-geniales-pour-maximiser-son-malheur-au-quotidien.org'
|
2024-11-20 00:24:09 +01:00
|
|
|
# fichier = '20170708T095535__techniques-geniales-pour-maximiser-son-malheur-au-quotidien.org'
|
|
|
|
# datestr, slug, path = find_year_and_slug_on_filename(fichier)
|
|
|
|
# print(datestr, slug, path)
|