generate articles with template
This commit is contained in:
parent
7c88fb7314
commit
ac9659b08d
@ -53,6 +53,8 @@ for file_name in os.listdir(directory):
|
||||
'slug': slug,
|
||||
'slug_with_year': f"{annee}/{slug}",
|
||||
'date': boom[0],
|
||||
'date_formattee': datetime.strptime(date_str, '%Y%m%d%H%M%S').strftime('%d %B %Y à %H:%M:%S') if len(date_str) == 14 else datetime.strptime(date_str, '%Y%m%dT%H%M%S').strftime('%d %B %Y à %H:%M:%S'),
|
||||
# 'date_formattee': datetime.strptime(date_str, '%Y%m%d%H%M%S').strftime('%d %B %Y à %H:%M:%S'),
|
||||
'annee': annee,
|
||||
'tags': tags, # Assurez-vous que c'est une liste
|
||||
'title': title,
|
||||
@ -68,9 +70,11 @@ sorted_basenames = sorted(files_dict.keys(), reverse=True)
|
||||
# Ajouter les noms des articles suivant et précédent
|
||||
for i in range(len(sorted_basenames)):
|
||||
basename = sorted_basenames[i]
|
||||
print('basename', basename)
|
||||
if i > 0:
|
||||
files_dict[basename]['previous'] = sorted_basenames[i - 1]
|
||||
if i < len(sorted_basenames) - 1:
|
||||
|
||||
files_dict[basename]['next'] = sorted_basenames[i + 1]
|
||||
|
||||
with open(destination_json+'/articles_info.json', 'w', encoding='utf-8') as json_file:
|
||||
@ -115,7 +119,6 @@ def generate_blog_index(json_file, template_file, output_file):
|
||||
template_content=configs_sites[args.blog],
|
||||
articles=sorted_articles[:global_config['posts_per_page']],
|
||||
articles_others=sorted_articles[10:]
|
||||
|
||||
)
|
||||
|
||||
# Écrire le fichier de sortie
|
||||
@ -125,4 +128,48 @@ def generate_blog_index(json_file, template_file, output_file):
|
||||
print(f"Page d'index générée dans {output_file}")
|
||||
|
||||
# Appel de la fonction pour générer la page d'index
|
||||
generate_blog_index(destination_json + '/articles_info.json', 'templates/html/index_template.html.jinja', destination_html + '/index.html')
|
||||
generate_blog_index(destination_json + '/articles_info.json', 'templates/html/index.html.jinja', destination_html + '/index.html')
|
||||
|
||||
|
||||
def generate_article_pages(json_file, template_file, output_dir):
|
||||
"""
|
||||
Génère les pages HTML pour chaque article à partir des informations JSON et d'un template Jinja2.
|
||||
|
||||
:param json_file: Chemin du fichier JSON contenant les informations des articles.
|
||||
:param template_file: Chemin du fichier template Jinja2.
|
||||
:param output_dir: Répertoire de sortie pour les fichiers HTML.
|
||||
"""
|
||||
# Charger les données JSON
|
||||
with open(json_file, 'r', encoding='utf-8') as f:
|
||||
articles_info = json.load(f)
|
||||
|
||||
# Configurer Jinja2
|
||||
env = Environment(loader=FileSystemLoader('.'))
|
||||
template = env.get_template(template_file)
|
||||
|
||||
# Générer les pages pour chaque article
|
||||
for article in articles_info.values():
|
||||
output_html = template.render(
|
||||
template_content=configs_sites[args.blog],
|
||||
article=article
|
||||
)
|
||||
|
||||
# Construire le chemin de sortie en fonction du slug avec l'année
|
||||
output_subdir = os.path.join(output_dir, article['slug_with_year'])
|
||||
os.makedirs(output_subdir, exist_ok=True)
|
||||
output_file = os.path.join(output_subdir ,"index.html")
|
||||
|
||||
|
||||
|
||||
# print(output_file)
|
||||
# Écrire le fichier de sortie
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
f.write(output_html)
|
||||
|
||||
# print(f"Page générée pour l'article {article['title']} dans {output_file}")
|
||||
|
||||
# Appel de la fonction pour générer les pages des articles
|
||||
generate_article_pages(destination_json + '/articles_info.json', 'templates/html/article.html.jinja', destination_html)
|
||||
|
||||
|
||||
|
||||
|
120
templates/html/article.html.jinja
Normal file
120
templates/html/article.html.jinja
Normal file
@ -0,0 +1,120 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<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:locale" content="{{template_content['LOCALE']}}">
|
||||
<meta property="og:description" content="{{template_content['BLOG_SUBTITLE']}}">
|
||||
<meta property="og:url" content="{{template_content['NDD']}}">
|
||||
<meta property="og:site_name" content="{{template_content['TITLE']}}">
|
||||
<link rel="alternate" type="application/atom+xml" title="Cipher Bliss » Flux"
|
||||
href="{{template_content['NDD']}}/feed/">
|
||||
<link href="/style.css" rel="stylesheet">
|
||||
<script src="main_script.js"></script>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{{template_content['TITLE']}}</title>
|
||||
<meta name="author" content="{{template_content['AUTHOR']}}">
|
||||
<link rel="alternate" type="application/rss+xml" title="{{template_content['BLOG_TITLE']}} » Flux"
|
||||
href="{{template_content['NDD']}}/feed/">
|
||||
<meta property="og:title" content="{{template_content['PAGE_TITLE']}}">
|
||||
<meta property="og:locale" content="{{template_content['LOCALE']}}">
|
||||
<!-- Description de la page -->
|
||||
<meta name="description" content="{{template_content['PAGE_TITLE']}}">
|
||||
<meta name="reply-to" content="{{template_content['EMAIL']}}">
|
||||
<link rel="icon" type="{{template_content['SITE_ICON_TYPE']}}" href="{{template_content['SITE_ICON']}}">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="page" class="page__{{template_content[" PAGE_SLUG"]}}">
|
||||
<header id="masthead" class="site-header">
|
||||
<div class="header-image" style="background-image: url('{{template_content[" BANNIERE_ENTETE"]}}');
|
||||
background-repeat: no-repeat; background-size: cover;">
|
||||
<a href="/">
|
||||
<img src="{{template_content['SITE_ICON']}}" class="site-icon img">
|
||||
</a>
|
||||
<h1 class="blog-title">{{template_content['BLOG_TITLE']}}</h1>
|
||||
<p class="blog-subtitle">{{template_content['BLOG_SUBTITLE']}}</p>
|
||||
<div class="template-header">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<nav class="navbar is-fixed-top is-dark" role="navigation" aria-label="main navigation">
|
||||
<div class="navbar-brand">
|
||||
<a class="navbar-item" href="{{template_content['NDD']}}">
|
||||
{{template_content['NDD']}}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div id="navbarBasicExample" class="navbar-menu">
|
||||
<div class="navbar-start">
|
||||
<a class="logo" href="{{template_content['NDD']}}">
|
||||
<img src="{{template_content['SITE_ICON']}}" class="img-fluid">
|
||||
</a>
|
||||
{{template_content['NAVIGATION']}}
|
||||
</div>
|
||||
<div class="navbar-end">
|
||||
<div class="navbar-item">
|
||||
<form role="search" method="get" class="search-form" action="/" id="recherche">
|
||||
<label>
|
||||
<input class="search-field" placeholder="Recherche" value="" name="s" type="search">
|
||||
</label>
|
||||
<input class="is-hidden search-submit" value="Rechercher" type="submit">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<main class="body-wrap boxed-container">
|
||||
|
||||
<article class="content">
|
||||
<div class="article-title">
|
||||
|
||||
<a href="{{ article.slug_with_year }}">{{ article.title }}</a>
|
||||
</div>
|
||||
<div class="article-date">
|
||||
{{article.date_formattee}}
|
||||
</div>
|
||||
<div>{{ article.html_content | safe }}</div>
|
||||
<div class="article-tags">
|
||||
{% if articles_others %}
|
||||
Tags:
|
||||
{% for tag in article.tags %}
|
||||
<a href="/tags/{{ tag }}">{{ tag }}</a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<hr />
|
||||
<div class="article-navigation">
|
||||
{% if article.previous %}
|
||||
<a href="{{ article.previous.slug_with_year }}" class="previous-article">Article précédent</a>
|
||||
{% endif %}
|
||||
{% if article.next %}
|
||||
<a href="{{ article.next.slug_with_year }}" class="next-article">Article suivant</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</main>
|
||||
<footer class="site-footer has-top-divider">
|
||||
<div class="container">
|
||||
<div class="site-footer-inner">
|
||||
<div class="site-foot">
|
||||
</div>
|
||||
<nav class="footer-nav">
|
||||
{{template_content['NAVIGATION']}}
|
||||
<a href="/tags/">Tags</a>
|
||||
<a href="{{template_content['NDD']}}/feed/">Flux Atom</a>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
</body>
|
||||
<!-- généré avec orgmode-to-gemini-blog par Tykayn -->
|
||||
|
||||
</html>
|
@ -76,7 +76,7 @@
|
||||
<a href="{{ article.slug_with_year }}">{{ article.title }}</a>
|
||||
</div>
|
||||
<div class="article-date">
|
||||
{{article.date}}
|
||||
{{article.date_formattee}}
|
||||
</div>
|
||||
<div>{{ article.html_content | safe }}</div>
|
||||
<div class="article-tags">
|
20
templates/html/site_head.html.jinja
Normal file
20
templates/html/site_head.html.jinja
Normal file
@ -0,0 +1,20 @@
|
||||
<!-- site_head.html.jinja -->
|
||||
<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:locale" content="{{ template_content['LOCALE'] }}">
|
||||
<meta property="og:description" content="{{ template_content['BLOG_SUBTITLE'] }}">
|
||||
<meta property="og:url" content="{{ template_content['NDD'] }}">
|
||||
<meta property="og:site_name" content="{{ template_content['TITLE'] }}">
|
||||
<link rel="alternate" type="application/atom+xml" title="{{ template_content['BLOG_TITLE'] }} » Flux" href="{{ template_content['NDD'] }}/feed/">
|
||||
<link href="/style.css" rel="stylesheet">
|
||||
<script src="main_script.js"></script>
|
||||
<title>{{ template_content['TITLE'] }}</title>
|
||||
<meta name="author" content="{{ template_content['AUTHOR'] }}">
|
||||
<link rel="alternate" type="application/rss+xml" title="{{ template_content['BLOG_TITLE'] }} » Flux" href="{{ template_content['NDD'] }}/feed/">
|
||||
<meta property="og:title" content="{{ template_content['PAGE_TITLE'] }}">
|
||||
<meta name="description" content="{{ template_content['PAGE_TITLE'] }}">
|
||||
<meta name="reply-to" content="{{ template_content['EMAIL'] }}">
|
||||
<link rel="icon" type="{{ template_content['SITE_ICON_TYPE'] }}" href="{{ template_content['SITE_ICON'] }}">
|
||||
</head>
|
@ -208,6 +208,7 @@ default_config = {
|
||||
""",
|
||||
"BANNIERE_ENTETE": "https://example.com/banner.jpg",
|
||||
"BANNIERE_ENTETE_ALT": "Bannière par défaut",
|
||||
"SOUTIEN": "Si vous aimez ce que nous faisons, soutenez nous et partagez nos écrits. Vous pouvez nous faire un don sur <a href='https://liberapay.com/cipherbliss'>liberapay.com/cipherbliss</a>."
|
||||
}
|
||||
|
||||
def fill_missing_config(site_config):
|
||||
|
Loading…
x
Reference in New Issue
Block a user