mirror of
https://forge.chapril.org/tykayn/orgmode-to-gemini-blog
synced 2025-06-20 09:04:42 +02:00
rework gemini conversion
This commit is contained in:
parent
f40c4c45f9
commit
2908447ddc
1731 changed files with 87067 additions and 16189 deletions
|
@ -24,6 +24,38 @@ source_files_extension="org"
|
|||
regex = r"^(\d{14})(-[a-zA-Z0-9_-]+)\.gmi$"
|
||||
regex_orgroam = r"^(\d{14})_([a-zA-Z0-9_-]+)\.gmi$"
|
||||
|
||||
import re
|
||||
|
||||
def trouver_nom_article(fichier_org):
|
||||
with open(fichier_org, 'r') as file:
|
||||
lignes = file.readlines()
|
||||
|
||||
# Expressions régulières pour trouver les titres de niveau 1 et 2
|
||||
titre_niveau_1 = r'^\*\*\*+ (.+)$'
|
||||
titre_niveau_2 = r'^\*\*+ (.+)$'
|
||||
|
||||
nom_article = None
|
||||
|
||||
# Itérer sur les lignes du fichier
|
||||
for ligne in lignes:
|
||||
# Rechercher un titre de niveau 1
|
||||
titre_niveau_1_match = re.match(titre_niveau_1, ligne)
|
||||
if titre_niveau_1_match:
|
||||
titre_niveau_1_texte = titre_niveau_1_match.group(1)
|
||||
if titre_niveau_1_texte.lower() != "article":
|
||||
nom_article = titre_niveau_1_texte
|
||||
break
|
||||
else:
|
||||
# Si le premier titre de niveau 1 est "Article", rechercher le premier titre de niveau 2
|
||||
titre_niveau_2_match = re.match(titre_niveau_2, ligne)
|
||||
if titre_niveau_2_match:
|
||||
nom_article = titre_niveau_2_match.group(1)
|
||||
break
|
||||
print(f"Nom de l'article : {nom_article}")
|
||||
|
||||
return nom_article
|
||||
|
||||
|
||||
def find_year_and_slug(fichier):
|
||||
fichier = fichier.replace('..','.')
|
||||
# print(f" ------------ build_indexes: find in {fichier} -------------")
|
||||
|
@ -110,6 +142,8 @@ def empty_folder_content(path):
|
|||
os.remove(file_path)
|
||||
else:
|
||||
shutil.rmtree(file_path)
|
||||
|
||||
use_article_file_for_name=False
|
||||
|
||||
def generer_index(dossier_source, fichier_index, titre_index):
|
||||
# Chemin absolu du dossier parent (pour sauver le fichier d'index)
|
||||
|
@ -139,13 +173,22 @@ def generer_index(dossier_source, fichier_index, titre_index):
|
|||
for fichier in files_static:
|
||||
contenu_index_gmi += f"=> {fichier}\n"
|
||||
link_html = fichier.replace('..gmi','.html')
|
||||
contenu_index_html += f"<br><a href=/{link_html}>{link_html}</a>"
|
||||
|
||||
if use_article_file_for_name:
|
||||
article_name = link_html
|
||||
else:
|
||||
file_path_org = os.path.join(dossier_parent,fichier)
|
||||
print('--------------',file_path_org)
|
||||
article_name=trouver_nom_article( file_path_org)
|
||||
|
||||
contenu_index_html += f"<br><a href=/{link_html}>{article_name}</a>"
|
||||
|
||||
# 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"
|
||||
contenu_index_html += "<h1>Articles en Français</h1>"
|
||||
lang_folder="lang_fr/"
|
||||
|
||||
for fichier in files_fr:
|
||||
date_string, année, slug = find_year_and_slug(fichier)
|
||||
new_folder=f"{année}/{slug}"
|
||||
|
@ -158,12 +201,7 @@ def generer_index(dossier_source, fichier_index, titre_index):
|
|||
# contenu_index_html += f"<br><a href=/{lang_folder}/{link_html}>{link_html}</a>"
|
||||
contenu_index_html += f"<br><a href=/{année}/{slug}>{année} {slug.replace('-', ' ')}</a>"
|
||||
|
||||
# déplacer l'article html généré dans son dossier de slug
|
||||
# print(f" ------------ build_indexes: on créée le dossier : {new_folder_path_this_article}, et on y copie le fichier {chemin_fichier_this_article} en le renommant index.html")
|
||||
# 'html-websites/'+args.source+'/'+new_folder
|
||||
# print(f" ------------ build_indexes: mkdir {new_folder_path_this_article} -p")
|
||||
# print(f" ------------ build_indexes: mv {chemin_fichier_this_article} {new_folder_path_this_article}")
|
||||
|
||||
|
||||
os.makedirs(os.path.dirname(new_folder_path_this_article), exist_ok=True)
|
||||
# déplacer le fichier html dans le dossier slug, et le renommer en index.html ensuite pour ne pas modifier l'index du blog
|
||||
shutil.copy(chemin_fichier_this_article, new_folder_path_this_article+'index.html')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue