up detection of slug

This commit is contained in:
Tykayn 2024-11-15 16:24:31 +01:00 committed by tykayn
parent 618c029c62
commit a0bb742d4c
46 changed files with 737 additions and 4848 deletions

View file

@ -1,10 +1,7 @@
import argparse
import datetime
import os
import shutil
from utils import *
from enrich_html import enrich_one_file
from utils import *
from website_config import configs_sites, global_config
# from enrich_html import static_page_path
@ -22,12 +19,10 @@ source_files_extension = "org"
config_title = configs_sites[args.source]['BLOG_TITLE']
use_article_file_for_name = (not global_config["slug_with_year"])
website_name = args.source
# transformer le nom du fichier orgmode en une création de dossier de l'année, et un sous dossier du nom du slug dans le nom de fichier, contenant un seul fichier d'index afin de faire de l'url rewrite en dur.
# le nom de fichier org commence par une date YYYY-MM-DD ou bien YYYYMMDDHHmmss, est suivie d'un slug, et finit par l'extension .org
@ -53,7 +48,6 @@ def generer_index(dossier_source, fichier_index):
contenu_index_gmi += "\n# Navigation\n-------------------------\n"
# ne préciser la langue français que si on a des articles en Anglais
if len(files_en):
contenu_index_gmi += "\n# Articles en Français\n-------------------------\n"
@ -70,19 +64,21 @@ def generer_index(dossier_source, fichier_index):
link_org = fichier.replace('.gmi', '.org')
file_path_org = os.path.join(dossier_parent, "sources", website_name, lang_folder, link_org)
article_name = trouver_nom_article(file_path_org,args.source, 'org')
article_name = trouver_nom_article(file_path_org, args.source, 'org')
basename_file = os.path.basename(file_path_org)
article_relative_url = detect_slug_in_file_basename(basename_file)
if not article_name:
article_name = slug.replace('-', ' ')
if global_config["slug_with_year"]:
new_folder = f"{année}/{slug}"
new_folder_path_this_article = os.path.join(dossier_parent,
'html-websites/' + args.source + '/' + new_folder + '/')
new_folder = article_relative_url
new_folder_path_this_article = os.path.join(dossier_parent, f"html-websites{args.source}/{new_folder}/")
# déplacer le fichier html dans le dossier slug,
# et le renommer en index.html ensuite pour ne pas modifier l'index du blog
contenu_index_html += f"<br/><a href=/{année}/{slug}>{année} {article_name}</a>"
contenu_index_html += f"<br/><a href={article_relative_url}>{année} {article_name}</a>"
os.makedirs(os.path.dirname(new_folder_path_this_article), exist_ok=True)
shutil.copy(chemin_fichier_this_article_html, new_folder_path_this_article + 'index.html')
else:
@ -95,7 +91,7 @@ def generer_index(dossier_source, fichier_index):
link_html = fichier.replace('.gmi', '.html')
link_org = fichier.replace('.gmi', '.org')
file_path_org = os.path.join(dossier_parent, "sources", website_name, link_org)
article_name = trouver_nom_article(file_path_org,args.source, 'org')
article_name = trouver_nom_article(file_path_org, args.source, 'org')
if article_name:
contenu_index_gmi += f"=> {fichier} {article_name}\n"
@ -107,7 +103,7 @@ def generer_index(dossier_source, fichier_index):
if use_article_file_for_name:
article_name = link_html
else:
article_name = trouver_nom_article(file_path_org,args.source, 'org')
article_name = trouver_nom_article(file_path_org, args.source, 'org')
if not article_name:
article_name = link_html