mirror of
https://forge.chapril.org/tykayn/orgmode-to-gemini-blog
synced 2025-06-20 09:04:42 +02:00
testing utils, generate better gemini links
This commit is contained in:
parent
6134f677fa
commit
cb2f0d1aa3
6 changed files with 311 additions and 183 deletions
45
utils.py
45
utils.py
|
@ -284,20 +284,37 @@ def remove_hint_html(text):
|
|||
return re.sub(pattern, replacement, text, flags=re.DOTALL)
|
||||
|
||||
|
||||
def slugify_title(title_text):
|
||||
def slugify_title(title):
|
||||
"""
|
||||
Transforme un titre en un slug valide.
|
||||
|
||||
:param title_text: Titre en texte (str).
|
||||
:return: Slug en minuscules avec des tirets (str).
|
||||
Convertit un titre en slug URL-friendly en conservant les accents.
|
||||
- Convertit en minuscules
|
||||
- Conserve les accents francophones
|
||||
- Remplace les caractères spéciaux par des tirets
|
||||
- Supprime les tirets multiples
|
||||
|
||||
Args:
|
||||
title (str): Le titre à convertir
|
||||
|
||||
Returns:
|
||||
str: Le slug généré
|
||||
"""
|
||||
title_text = unicodedata.normalize('NFKD', title_text).encode('ascii', 'ignore').decode('ascii')
|
||||
title_text = title_text.lower()
|
||||
title_text = re.sub(r'[^a-z0-9\s-]', '', title_text)
|
||||
title_text = re.sub(r'\s+', '-', title_text)
|
||||
title_text = re.sub(r'-+', '-', title_text)
|
||||
title_text = title_text.strip('-')
|
||||
return title_text
|
||||
# Conversion en minuscules
|
||||
title = title.lower()
|
||||
|
||||
# Liste des caractères autorisés (inclut les accents francophones)
|
||||
# On garde a-z, 0-9, les accents français, les tirets
|
||||
allowed_chars = r'[^a-zàâäéèêëîïôöùûüçñ0-9-]'
|
||||
|
||||
# Remplacer les caractères non autorisés par des tirets
|
||||
title = re.sub(allowed_chars, '-', title)
|
||||
|
||||
# Supprimer les tirets en début et fin
|
||||
title = title.strip('-')
|
||||
|
||||
# Remplacer les tirets multiples par un seul
|
||||
title = re.sub(r'-+', '-', title)
|
||||
|
||||
return title
|
||||
|
||||
def find_slug_in_file_basename(file_basename) -> str:
|
||||
"""
|
||||
|
@ -522,7 +539,7 @@ def convert_org_to_gemini(org_content):
|
|||
def save_gemini_file(blog, article):
|
||||
|
||||
annee = article['annee']
|
||||
slug = article['slug']
|
||||
slug = slugify_title(article['title'])
|
||||
title = article['title']
|
||||
gemini_content = article['gemini_content']
|
||||
gemini_file_path = article['gemini_file_path']
|
||||
|
@ -539,7 +556,7 @@ def save_gemini_file(blog, article):
|
|||
# Sauvegarde du contenu GMI dans un fichier
|
||||
try:
|
||||
# Créer le dossier parent s'il n'existe pas
|
||||
os.makedirs(os.path.dirname(gemini_file_path), exist_ok=True)
|
||||
# os.makedirs(os.path.dirname(gemini_file_path), exist_ok=True)
|
||||
with open(gemini_file_path, 'w', encoding='utf-8') as f:
|
||||
f.write(
|
||||
f'# {website_title} \n ## {title} \n----------------\n {gemini_content} \n ----------------\n ## Liens\n=> index.gmi')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue