mirror of
https://forge.chapril.org/tykayn/orgmode-to-gemini-blog
synced 2025-06-20 09:04:42 +02:00
ajout redirection pour tout un blog caddy server
This commit is contained in:
parent
248c4b1b37
commit
b4e7dd453e
1 changed files with 68 additions and 0 deletions
68
WIP/make_caddy_redirect.py
Normal file
68
WIP/make_caddy_redirect.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
import sys
|
||||
import os
|
||||
|
||||
# Ajoute le dossier parent du script au PYTHONPATH
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import json
|
||||
import argparse
|
||||
from utils.utils import get_blog_template_conf
|
||||
|
||||
# Configuration des arguments de la ligne de commande
|
||||
parser = argparse.ArgumentParser(description="Générer un fichier de redirection Caddy pour les articles de blog.")
|
||||
parser.add_argument("blog", help="Le nom du dossier de blog.")
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.blog:
|
||||
print("Erreur: Veuillez spécifier le nom du blog")
|
||||
parser.print_help()
|
||||
exit(1)
|
||||
|
||||
# Chemin vers le fichier d'infos
|
||||
blog_name = args.blog
|
||||
articles_info_path = f'../sources/{blog_name}/build/articles_info.json'
|
||||
|
||||
template_content = get_blog_template_conf(args.blog)
|
||||
website_ndd = template_content['NDD']
|
||||
|
||||
# Charger les données du fichier articles_info.json
|
||||
json_file = f'../sources/{blog_name}/build/articles_info.json'
|
||||
with open(json_file, 'r', encoding='utf-8') as f:
|
||||
articles_info = json.load(f)
|
||||
|
||||
# Trier les articles par date décroissante
|
||||
sorted_articles = sorted(articles_info.values(), key=lambda x: x['date'], reverse=True)
|
||||
|
||||
# Créer le fichier de configuration Caddy
|
||||
caddy_config_path = f'{args.blog}.conf.caddy'
|
||||
|
||||
with open(caddy_config_path, 'w', encoding='utf-8') as f:
|
||||
# f.write(f"""
|
||||
# {website_ndd} {
|
||||
# redir {website_ndd}{uri}
|
||||
# }
|
||||
|
||||
# {website_ndd} {
|
||||
# import generic_headers
|
||||
# root * /poule/encrypted/www/{website_ndd}
|
||||
# encode zstd gzip
|
||||
# file_server browse
|
||||
|
||||
# }
|
||||
|
||||
# """)
|
||||
# Pour chaque article, écrire la règle de redirection
|
||||
for article in sorted_articles:
|
||||
# Récupérer l'ancien slug (sans année) et le nouveau (avec année)
|
||||
old_slug = article['slug']
|
||||
new_slug = article['slug_with_year']
|
||||
|
||||
# Écrire la règle de redirection
|
||||
f.write(f'redir /{old_slug} /{new_slug} permanent\n')
|
||||
|
||||
print(f"Fichier de configuration Caddy généré : {caddy_config_path}")
|
||||
|
||||
|
||||
# pour cipherbliss, ajouter :
|
||||
# redir /contribuer-a-panoramax-avec-open-camera /2024/contribuer-a-panoramax-avec-open-camera
|
||||
# redir /contact https://portfolio.cipherbliss.com/#contact
|
Loading…
Add table
Add a link
Reference in a new issue