mirror of
https://forge.chapril.org/tykayn/orgmode-to-gemini-blog
synced 2025-06-20 09:04:42 +02:00
page de tags avec échelle de taille selon la fréquence
This commit is contained in:
parent
341292aa12
commit
a473479b83
7 changed files with 112 additions and 58 deletions
|
@ -105,14 +105,20 @@ def generate_html_pages_for_all_tags(tag_to_files, html_output_folder):
|
|||
if not os.path.exists(html_output_folder):
|
||||
os.makedirs(html_output_folder)
|
||||
|
||||
|
||||
# Charger le template Jinja2
|
||||
env = Environment(loader=FileSystemLoader('.'))
|
||||
template = env.get_template('templates/html/tag.html.j2')
|
||||
sorted_tags = sorted(tag_to_files.items())
|
||||
|
||||
for tag, files in tag_to_files.items():
|
||||
|
||||
for tag, files in sorted_tags:
|
||||
print('------------ tag', tag, len(files))
|
||||
print('Files pour ce tag:', files)
|
||||
print('Clés disponibles dans articles_info:', list(articles_info.keys())[:5], '...')
|
||||
|
||||
# Afficher un exemple détaillé de non-correspondance
|
||||
for f in files:
|
||||
if f not in articles_info:
|
||||
print(f"Fichier non trouvé dans articles_info: {f}")
|
||||
|
||||
# Préparer les données pour le template
|
||||
data = {
|
||||
|
@ -135,23 +141,39 @@ def generate_html_pages_for_all_tags(tag_to_files, html_output_folder):
|
|||
print(f"Pages HTML générées dans {html_output_folder}")
|
||||
|
||||
|
||||
def calculate_tag_size_class(count, max_count, num_classes=10):
|
||||
"""Calcule la classe de taille pour un tag basé sur sa fréquence."""
|
||||
if max_count == 0:
|
||||
return 1
|
||||
# Utilise une échelle logarithmique pour mieux répartir les tailles
|
||||
ratio = count / max_count
|
||||
# Convertit le ratio en classe de 1 à num_classes
|
||||
size_class = int(ratio * num_classes) + 1
|
||||
# Assure que la classe est entre 1 et num_classes
|
||||
return max(1, min(size_class, num_classes))
|
||||
|
||||
def generate_index_page(tag_to_files, html_output_folder):
|
||||
|
||||
|
||||
|
||||
# Charger le template Jinja2
|
||||
env = Environment(loader=FileSystemLoader('.'))
|
||||
template = env.get_template('templates/html/tag.html.j2')
|
||||
sorted_tags = sorted(tag_to_files.items())
|
||||
|
||||
tags_count = {tag: len(files) for tag, files in sorted_tags}
|
||||
# Calculer le nombre maximum d'articles pour un tag
|
||||
max_count = max(len(files) for _, files in sorted_tags) if sorted_tags else 0
|
||||
|
||||
# print(tags_count)
|
||||
# Créer un dictionnaire avec les tags et leurs informations
|
||||
tags_info = {
|
||||
tag: {
|
||||
'count': len(files),
|
||||
'size_class': calculate_tag_size_class(len(files), max_count)
|
||||
}
|
||||
for tag, files in sorted_tags
|
||||
}
|
||||
|
||||
# Préparer les données pour le template
|
||||
data = {
|
||||
'tags': tags_count,
|
||||
'template_content' : get_blog_template_conf(args.blog),
|
||||
'tags': tags_info,
|
||||
'template_content': get_blog_template_conf(args.blog),
|
||||
'html_output_folder': html_output_folder
|
||||
}
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ if generate_linkings_json :
|
|||
if f.endswith(('.org', '.md', '.gmi'))]
|
||||
|
||||
for file_index, file_name in enumerate(files):
|
||||
print(f"Traitement du fichier {file_name}, {file_index+1}/{len(files)}")
|
||||
# print(f"Traitement du fichier {file_index+1}/{len(files)}, {file_name}")
|
||||
# Vérifier si le fichier se termine par une extension supportée
|
||||
if not (file_name.endswith('.org') or file_name.endswith('.md') or file_name.endswith('.gmi')):
|
||||
print(f"Fichier {file_name} non supporté")
|
||||
|
@ -139,7 +139,7 @@ if generate_linkings_json :
|
|||
# pour déterminer les informations qu'il contient
|
||||
# afin de les stocker dans un json pour la génération des pages html et gemini
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
print(f"----- Traitement de l'article {counter}: {file_name}")
|
||||
# print(f"----- Traitement de l'article {counter}: {file_name}")
|
||||
content = f.read()
|
||||
# Convertir le contenu Org en HTML
|
||||
title = find_first_level1_title(content)
|
||||
|
@ -169,13 +169,13 @@ if generate_linkings_json :
|
|||
html_content_without_h1 = ''
|
||||
# Vérifier l'existence du fichier HTML pour déterminer last_html_build
|
||||
html_path = f"html-websites/{args.blog}/{annee}/{slug}/index.html"
|
||||
print(f"html_path existe il? : {html_path}")
|
||||
# print(f"html_path existe il? : {html_path}")
|
||||
last_html_build_time = None
|
||||
if os.path.exists(html_path):
|
||||
# Obtenir la date de création du fichier HTML
|
||||
last_html_build_time = os.path.getctime(html_path)
|
||||
|
||||
print(f"----- last_html_build EXISTE: {last_html_build_time} : {html_path}")
|
||||
# print(f"----- last_html_build EXISTE: {last_html_build_time} : {html_path}")
|
||||
else:
|
||||
print(f"html_path n'existe pas: on va le créer")
|
||||
# Vérifier l'existence du fichier Gemini pour déterminer last_gemini_build
|
||||
|
@ -202,15 +202,15 @@ if generate_linkings_json :
|
|||
|
||||
if last_html_build_time:
|
||||
file_modified_time = os.path.getmtime(file_path)
|
||||
print(f"--------- file_modified_time: {file_path} : {file_modified_time}")
|
||||
print(f"--------- last_html_build_time: {last_html_build_time}")
|
||||
# print(f"--------- file_modified_time: {file_path} : {file_modified_time}")
|
||||
# print(f"--------- last_html_build_time: {last_html_build_time}")
|
||||
# Obtenir l'heure de dernière modification du fichier HTML
|
||||
|
||||
rebuild_this_article_html = file_modified_time > last_html_build_time
|
||||
if rebuild_this_article_html:
|
||||
print(f"\033[91m--------- article modifié après le build de son rendu html: {file_path}, {rebuild_this_article_html}\033[0m")
|
||||
else:
|
||||
# print(f"\033[91m--------- article non modifié après le build de son rendu html: {file_path}, {rebuild_this_article_html}, on ne recrée pas\033[0m")
|
||||
# else:
|
||||
# print(f"\033[91m--------- article non modifié après le build de son rendu html: {file_path}, {rebuild_this_article_html}, on ne recrée pas\033[0m")
|
||||
|
||||
else:
|
||||
# si il n'y a pas de fichier html, on le construit pour la première fois
|
||||
|
@ -221,7 +221,7 @@ if generate_linkings_json :
|
|||
rebuild_counter += 1
|
||||
|
||||
|
||||
print(f"slug_with_year: {slug_with_year}")
|
||||
# print(f"slug_with_year: {slug_with_year}")
|
||||
# Afficher les clés de files_dict pour débogage
|
||||
# print("\nClés disponibles dans files_dict:")
|
||||
# for key in files_dict.keys():
|
||||
|
@ -229,16 +229,16 @@ if generate_linkings_json :
|
|||
# print("\n")
|
||||
# Garder le contenu HTML existant si déjà présent
|
||||
if not rebuild_this_article_html and slug_with_year in files_dict and 'html_content' in files_dict[slug_with_year]:
|
||||
print('========= on reprend le contenu html existant')
|
||||
# print('========= on reprend le contenu html existant')
|
||||
len_html = len(files_dict[slug_with_year]['html_content'])
|
||||
print(f"len_html: {len_html}")
|
||||
# print(f"len_html: {len_html}")
|
||||
if len_html > 0 :
|
||||
html_content = files_dict[slug_with_year]['html_content']
|
||||
html_content_without_h1 = re.sub(r'<h1>.*?</h1>', '', html_content)
|
||||
if len(files_dict[slug_with_year]['html_content_without_h1']) > 0 :
|
||||
html_content_without_h1 = files_dict[slug_with_year]['html_content_without_h1']
|
||||
else:
|
||||
print('========= pas de contenu html existant')
|
||||
print('========= pas de contenu html existant: ', title)
|
||||
print(f"\033[91m {time.strftime('%H:%M:%S')} BRRRRRRRRRRRRR pandoc html_content : {title} en html\033[0m")
|
||||
pandoc_runs_counter += 1
|
||||
html_content = pypandoc.convert_text(content_without_h1, 'html', format='org')
|
||||
|
@ -297,9 +297,9 @@ if generate_linkings_json :
|
|||
except OSError as e:
|
||||
print(f"Erreur lors de la lecture du dossier {directory}: {e}")
|
||||
continue
|
||||
|
||||
print(f"======= Nombre d'articles reconstruits: {rebuild_counter}")
|
||||
print(f"======= Nombre de runs de pandoc: {pandoc_runs_counter}")
|
||||
if rebuild_counter > 0:
|
||||
print(f"======= Nombre d'articles reconstruits: {rebuild_counter}")
|
||||
# print(f"======= Nombre de runs de pandoc: {pandoc_runs_counter}")
|
||||
|
||||
else:
|
||||
print(f"Pas de génération des liens entre articles")
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#+post_slug: organisation-de-taches-orgmode
|
||||
#+post_url: https://www.ciperbliss.com/2024/julie-de-la-fabrique-des-mobilités-elles-font-le-libre
|
||||
#+post_title: Julie de la fabrique des mobilités - Elles font le libre
|
||||
#+post_tags:
|
||||
#+post_tags: openstreetmap, transport, sotm
|
||||
#+post_type: post
|
||||
#+post_mime_types:
|
||||
#+post_guid:
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#+post_slug: organisation-de-taches-orgmode
|
||||
#+post_url: https://www.ciperbliss.com/2024/dépasser-la-spécialisation
|
||||
#+post_title: dépasser la spécialisation
|
||||
#+post_tags:
|
||||
#+post_tags: information, médias, internet, médias sociaux, mastodon
|
||||
#+post_type: post
|
||||
#+post_mime_types:
|
||||
#+post_guid:
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#+post_lang: fr
|
||||
#+post_url: https://www.cipherbliss.com2025/faire-une-analyse-avec-osmose-backend
|
||||
#+post_title: Faire une analyse avec Osmose-Backend
|
||||
#+post_tags:
|
||||
#+post_tags: osmose, openstreetmap, osm, python, opendata
|
||||
#+post_series:
|
||||
#+post_type: post
|
||||
#+post_status: publish
|
||||
|
|
|
@ -25,6 +25,31 @@
|
|||
<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']}}">
|
||||
<style>
|
||||
.tag-cloud {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
padding: 2rem;
|
||||
}
|
||||
.tag-link {
|
||||
text-decoration: none;
|
||||
color: #333;
|
||||
transition: all 0.3s ease;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
.tag-link:hover {
|
||||
color: #007bff;
|
||||
transform: scale(1.1);
|
||||
}
|
||||
{% for i in range(1, 11) %}
|
||||
.tag-size-{{i}} {
|
||||
font-size: {{ 0.8 + (i * 0.2) }}rem;
|
||||
opacity: {{ 0.5 + (i * 0.05) }};
|
||||
}
|
||||
{% endfor %}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -84,46 +109,51 @@
|
|||
</h1>
|
||||
{% if files %}
|
||||
|
||||
fichiers: {{files|length}}
|
||||
|
||||
<div class="article-main-content">
|
||||
<ul>
|
||||
|
||||
{% set sorted_files = files|sort(reverse=true) %}
|
||||
{% set files = sorted_files %}
|
||||
|
||||
{% for file in files %}
|
||||
{% if articles_info[file] %}
|
||||
<li>
|
||||
<a href='/{{articles_info[file].slug_with_year}}'>
|
||||
<h2>
|
||||
{{articles_info[file].annee}}
|
||||
{{articles_info[file].title}}
|
||||
</h2>
|
||||
</a>
|
||||
<div class="tags">
|
||||
{% for t in articles_info[file].tags %}
|
||||
<a href="/tag/{{t}}">
|
||||
{{t}}
|
||||
{% if articles_info[file] %}
|
||||
<li>
|
||||
<a class="article-link article-from-tag-list" href='/{{articles_info[file].slug_with_year}}'>
|
||||
<h2>
|
||||
{{articles_info[file].annee}}
|
||||
{{articles_info[file].title}}
|
||||
</h2>
|
||||
</a>
|
||||
<div class="tags">
|
||||
{% for t in articles_info[file].tags %}
|
||||
<a href="/tag/{{t}}">
|
||||
{{t}}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<li>
|
||||
<a class="article-link article-from-tag-slug" href='/{{file}}'>
|
||||
{{file}}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if tags %}
|
||||
|
||||
<div class="article-tags">
|
||||
<ul>
|
||||
{% for tag_key, file_count in tags.items() %}
|
||||
|
||||
{% if tag_key %}
|
||||
<li><a href='/tag/{{tag_key}}.html'>{{tag_key}}</a> ({{file_count}})</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="tag-cloud">
|
||||
{% for tag_key, info in tags.items() %}
|
||||
{% if tag_key %}
|
||||
<a href='/tag/{{tag_key}}' class="tag-link tag-size-{{info.size_class}}">
|
||||
{{tag_key}} ({{info.count}})
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</article>
|
||||
|
|
|
@ -232,6 +232,8 @@ def save_untagged_files(output_file="sources/site_web/build/articles_without_tag
|
|||
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
||||
|
||||
print('save_untagged_files', len(untagged_files))
|
||||
for f in untagged_files:
|
||||
print('- ', f)
|
||||
# Sauvegarder la liste dans le fichier JSON
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(untagged_files, f, ensure_ascii=False, indent=4)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue