ajout d'image og dans les articles si existant

This commit is contained in:
Tykayn 2025-02-23 19:46:10 +01:00 committed by tykayn
parent ce6eb680b7
commit e1f8bf93e0
3 changed files with 25 additions and 7 deletions

View file

@ -87,7 +87,7 @@ Navigation:
try:
with open(destination_gmi+'/'+output_filename_slug+'.gmi', 'w', encoding='utf-8') as f:
f.write(output)
# print(f"Fichier GMI sauvegardé avec succès : {output_filename_slug}")
print(f"Fichier GMI sauvegardé avec succès : {output_filename_slug}")
except OSError as e:
print(f"Erreur lors de la sauvegarde du fichier : {e}")
return output
@ -188,7 +188,7 @@ if generate_linkings_json :
'last_gemini_build': last_gemini_build,
'org_content': content, # Contenu Org original
'html_content_without_h1': re.sub(r'<h1>.*?</h1>', '', html_content), # Contenu HTML converti sans le titre de premier niveau
'html_content': html_content # Contenu HTML converti
'html_content': html_content # Contenu first_picture_urlHTML converti
}
# Trier les basenames par ordre décroissant
@ -336,11 +336,18 @@ def generate_article_pages(json_file, template_file, output_dir):
# Configurer Jinja2
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template(template_file)
template_content = get_blog_template_conf(args.blog)
# Générer les pages pour chaque article
for article in articles_info.values():
if article['first_picture_url']:
template_content['OG_IMAGE'] = article['first_picture_url']
else:
template_content['OG_IMAGE'] = template_content['SITE_ICON']
output_html = template.render(
template_content=get_blog_template_conf(args.blog),
template_content=template_content,
article=article,
all_articles=articles_info
)

View file

@ -11,11 +11,13 @@ parser = argparse.ArgumentParser(description="Générer un nouvel article en mod
parser.add_argument("--title", nargs="?", help="Le titre de l'article.")
parser.add_argument("--lang", nargs="?", default="fr", help="La langue de l'article (par défaut : fr pour Français ou en pour English).")
parser.add_argument("--blog_dir", nargs="?", default=None, help="Le nom du dossier de blog (sous source/). Si non spécifié, une liste de dossiers disponibles sera proposée.")
parser.add_argument("--year_prefix_in_slug", nargs="?", default=True, help="Ajouter l'année au début du slug.")
args = parser.parse_args()
# Définition du dossier de base pour les blogs
base_blog_dir = "sources/"
year_prefix_in_slug = args.year_prefix_in_slug
# Si aucun dossier de blog n'est spécifié, proposer une sélection
if args.blog_dir is None:
@ -67,6 +69,12 @@ if args.title:
slug = args.title.lower().replace(" ", "-")
slug = slug.replace("--", "-")
slug = slug.replace("--", "-")
if year_prefix_in_slug:
schema_slug = f"{now.year}/{slug}"
else:
schema_slug = slug
file_abs_path = os.path.abspath(os.path.dirname(__file__))
if args.lang == 'fr' or args.lang == 'en':
@ -91,13 +99,16 @@ with open(filename, "w") as f:
#+title: {args.title}
#+post_ID:
#+post_slug: organisation-de-taches-orgmode
#+post_url: https://www.ciperbliss.com/{now.year}/{slug}
#+post_slug: {slug}
#+post_url: https://www.ciperbliss.com/{schema_slug}
#+post_title: {args.title}
#+post_tags:
#+post_series:
#+post_type: post
#+post_status: publish
#+post_picture:
#+post_date_published: <{date_string_full}>
#+post_date_modified: <{date_string_full}>
#+post_index_page_roam_id: {uuid}

View file

@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:image" content="{{template_content['SITE_ICON']}}">
<meta property="og:image" content="{{template_content['OG_IMAGE']}}">
<meta property="og:locale" content="{{template_content['LOCALE']}}">
<meta property="og:description" content="{{template_content['BLOG_SUBTITLE']}}">
<meta property="og:url" content="{{template_content['NDD']}}">