mirror of
https://forge.chapril.org/tykayn/orgmode-to-gemini-blog
synced 2025-06-20 09:04:42 +02:00
style sass
This commit is contained in:
parent
f016f842c9
commit
8c45ae05f9
24 changed files with 803 additions and 647 deletions
21
WIP/add_data_in_org_files_from_wp_database.py
Normal file
21
WIP/add_data_in_org_files_from_wp_database.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# script qui se connecte à une base de données wordpress, fait la correspondance entre les billets de blog existants au format org roam et ceux présents en base
|
||||
# puis ajoute des informations de propriété Org Roam manquantes aux fichiers org. Le lien entre les articles et les fichiers se fait en parsant les fichiers Org pour trouver un titre correspondant.
|
||||
# on rajoute le slug dans les billets de blog Orgmode en tant que propriété #+title
|
||||
# si le billet org n'a pas de propriété :ID: en entête, on en crée un à partir d'un uuid.
|
||||
# exemple pour le fichier :
|
||||
# :PROPERTIES:
|
||||
# :ID: 7de1d854-431c-4517-9749-3679aec36b16
|
||||
# :BLOG_ID: 826
|
||||
# :BLOG_NAME: tykayn_blog
|
||||
# :BLOG_PAGE_KIND: article
|
||||
# :BLOG_PAGE_TITLE: Pink elephants and limonade
|
||||
# :BLOG_PAGE_LANG: fr_FR
|
||||
# :BLOG_PAGE_TAGS: truc,bidule,chose
|
||||
# :BLOG_PAGE_CATEGORIES: vie numérique, kotlife
|
||||
# :BLOG_SLUG: pink-elephants-and-limonade
|
||||
# :BLOG_PAGE_URL: https://tykayn.fr/2009/pink-elephants-and-limonade
|
||||
# :BLOG_PUBLISHED_AT: 2018-07-13 15:39:58
|
||||
# :BLOG_MODIFIED_AT: 2018-08-22 12:07:46
|
||||
# :STATUS: publish
|
||||
# :END:
|
||||
# #+title: pink-elephants-and-limonade
|
60
WIP/atom_generate.py
Executable file
60
WIP/atom_generate.py
Executable file
|
@ -0,0 +1,60 @@
|
|||
import os
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
# Chemin du dossier source
|
||||
source_dir = "source"
|
||||
|
||||
# Expression régulière pour extraire la date du contenu de l'article
|
||||
date_regex = re.compile(r"\b(\d{14})\b")
|
||||
|
||||
# Liste des fichiers org-mode trouvés
|
||||
org_files = []
|
||||
|
||||
# Parcourt le dossier source à la recherche de fichiers org-mode
|
||||
for root, dirs, files in os.walk(source_dir):
|
||||
for file in files:
|
||||
if file.endswith(".org"):
|
||||
# Ouvre le fichier et recherche la première date dans le contenu de l'article
|
||||
with open(os.path.join(root, file), "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
match = date_regex.search(content)
|
||||
if match:
|
||||
date = datetime.strptime(match.group(1), "%Y-%m-%d")
|
||||
# Ajoute le fichier à la liste avec sa date correspondante
|
||||
org_files.append((date, os.path.join(root, file)))
|
||||
|
||||
# Tri des fichiers par ordre décroissant de date
|
||||
org_files.sort(reverse=True)
|
||||
|
||||
# Génération du flux Atom
|
||||
atom_feed = {"title": "Flux Atom des articles GMI", "link": "http://www.example.com/atom", "updated": org_files[0][0].strftime("%Y-%m-%dT%H:%M:%SZ"), "entries": []}
|
||||
|
||||
for date, file in org_files:
|
||||
# Parse le fichier org-mode pour extraire le titre, la description et la date de publication
|
||||
with open(file, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
title = re.search(r"\*+ (.+)\n", content).group(1)
|
||||
description = re.search(r"\n+ (.+)\n", content, re.DOTALL).group(1)
|
||||
published = date.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
# Ajoute l'article au flux Atom
|
||||
atom_entry = {"title": title, "link": file, "summary": description, "published": published}
|
||||
atom_feed["entries"].append(atom_entry)
|
||||
if published > atom_feed["updated"]:
|
||||
atom_feed["updated"] = published
|
||||
|
||||
# Enregistrement du flux Atom dans un fichier
|
||||
with open("atom.xml", "w", encoding="utf-8") as f:
|
||||
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||
f.write('<feed xmlns="http://www.w3.org/2005/Atom">\n')
|
||||
f.write(f' <title>{atom_feed["title"]}</title>\n')
|
||||
f.write(f' <link href="{atom_feed["link"]}"/>\n')
|
||||
f.write(f' <updated>{atom_feed["updated"]}</updated>\n')
|
||||
for entry in atom_feed["entries"]:
|
||||
f.write(' <entry>\n')
|
||||
f.write(f' <title>{entry["title"]}</title>\n')
|
||||
f.write(f' <link href="{entry["link"]}"/>\n')
|
||||
f.write(f' <summary>{entry["summary"]}</summary>\n')
|
||||
f.write(f' <published>{entry["published"]}</published>\n')
|
||||
f.write(' </entry>\n')
|
||||
f.write('</feed>')
|
70
WIP/find_info_in_org.py
Normal file
70
WIP/find_info_in_org.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
import os
|
||||
import argparse
|
||||
import re
|
||||
import datetime
|
||||
import shutil
|
||||
|
||||
|
||||
def enlever_premier_tiret_ou_underscore(chaîne):
|
||||
if chaîne.startswith('-') or chaîne.startswith('_'):
|
||||
chaîne = chaîne[1:]
|
||||
return chaîne
|
||||
|
||||
# Expression régulière pour extraire la date et le slug du nom de fichier org
|
||||
regex = r"^(\d{4}(-?\d{2}){2}|\d{8})(-[a-zA-Z0-9_-]+)\.gmi$"
|
||||
regex_orgroam = r"^(\d{14})_([a-zA-Z0-9_-]+)\.gmi$"
|
||||
|
||||
def find_year_and_slug(nom_de_fichier):
|
||||
nom_de_fichier = nom_de_fichier.replace('..','.')
|
||||
annee = ''
|
||||
annee_presumed = nom_de_fichier[:4]
|
||||
print(f"///////////////// /////////////////")
|
||||
print(f"nom_de_fichier: {nom_de_fichier}")
|
||||
if int(annee_presumed) >1970 and len(annee_presumed) == 4:
|
||||
annee = str(annee_presumed)
|
||||
print(f"année: {annee}")
|
||||
match = re.match(regex_orgroam, nom_de_fichier)
|
||||
if match:
|
||||
date_str = match.group(1)
|
||||
# annee = date_str[:4]
|
||||
slug = match.group(2)
|
||||
|
||||
match = re.match(regex, nom_de_fichier)
|
||||
if match:
|
||||
date_str = match.group(1)
|
||||
# Convertir la date en objet datetime
|
||||
if "-" in date_str:
|
||||
date = datetime.datetime.strptime(date_str, "%Y-%m-%d")
|
||||
else:
|
||||
date = datetime.datetime.strptime(date_str, "%Y%m%d%H%M%S")
|
||||
date_string_replaced = str(date).replace(' 00:00:00','')
|
||||
slug = nom_de_fichier.replace('.gmi','')
|
||||
slug = slug.replace(date_string_replaced,'')
|
||||
slug = enlever_premier_tiret_ou_underscore(slug)
|
||||
|
||||
annee = str(date.year).replace(' 00:00:00','')
|
||||
else:
|
||||
print('find_year_and_slug : ERREUR aucun slug trouvé')
|
||||
return [None,annee,None]
|
||||
|
||||
|
||||
print(f"str(date): {str(date)}")
|
||||
print(f"slug: {slug}")
|
||||
print(f"chemin: {annee}/{slug}/")
|
||||
return [date_str, annee,slug]
|
||||
|
||||
def test_find_year_and_slug_short_date():
|
||||
date_string, année, slug = find_year_and_slug("2024-10-12-machin_truc-chose.gmi")
|
||||
assert slug == "machin_truc-chose"
|
||||
assert année == "2024"
|
||||
assert date_string == "2024-10-12"
|
||||
|
||||
def test_find_year_and_slug_orgroam_date():
|
||||
date_string, année, slug = find_year_and_slug("20060925105123_tkblog_879_by-the-wall-intersubkey.gmi")
|
||||
# assert slug == "by-the-wall-intersubkey"
|
||||
assert année == "2006"
|
||||
# assert date_string == "20060925"
|
||||
|
||||
|
||||
test_find_year_and_slug_short_date()
|
||||
test_find_year_and_slug_orgroam_date()
|
35
WIP/move_html_in_org.py
Normal file
35
WIP/move_html_in_org.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import os
|
||||
import shutil
|
||||
# certains fichiers org contenant du html ne sont pas convertis avec pandoc
|
||||
# on les cherche et on les met de côté
|
||||
|
||||
def chercher_fichiers_org(dossier_source, dossier_destination):
|
||||
# Vérifier si le dossier de destination existe, sinon le créer
|
||||
if not os.path.exists(dossier_destination):
|
||||
os.makedirs(dossier_destination)
|
||||
|
||||
# Parcourir tous les fichiers dans le dossier source
|
||||
for racine, dossiers, fichiers in os.walk(dossier_source):
|
||||
for fichier in fichiers:
|
||||
if fichier.endswith(".org"):
|
||||
# Ouvrir le fichier en mode lecture
|
||||
with open(os.path.join(racine, fichier), "r") as f:
|
||||
contenu = f.read()
|
||||
|
||||
# Vérifier si ":html:" est dans le contenu du fichier
|
||||
if ":html:" in contenu:
|
||||
# Déplacer le fichier dans le dossier de destination
|
||||
shutil.move(os.path.join(racine, fichier), os.path.join(dossier_destination, fichier))
|
||||
print(f"Le fichier {fichier} a été déplacé avec succès.")
|
||||
else:
|
||||
print(f"Le fichier {fichier} ne contient pas ':html:', il n'a pas été déplacé.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(os.sys.argv) != 3:
|
||||
print("Usage: python script.py <dossier_source> <dossier_destination>")
|
||||
exit(1)
|
||||
|
||||
dossier_source = os.sys.argv[1]
|
||||
dossier_destination = os.sys.argv[2]
|
||||
|
||||
chercher_fichiers_org(dossier_source, dossier_destination)
|
42
WIP/parse_article.py
Normal file
42
WIP/parse_article.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
import re
|
||||
import os
|
||||
def trouver_nom_article(fichier_org):
|
||||
print('fichier_org, ',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
|
||||
|
||||
|
||||
# Chemin absolu du dossier parent (pour sauver le fichier d'index)
|
||||
dossier_parent = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
nom = trouver_nom_article(dossier_parent+'/sources/cipherbliss_blog/contact.org')
|
||||
print('nom ',nom)
|
||||
|
||||
nom = trouver_nom_article(dossier_parent+'/sources/cipherbliss_blog/lang_fr/20210927092238_cipherbliss_blog_238_des-sauvegardes-qui-durent-mille-ans.org')
|
||||
|
||||
print('nom ',nom)
|
1
WIP/series_posts_build.py
Normal file
1
WIP/series_posts_build.py
Normal file
|
@ -0,0 +1 @@
|
|||
# construit une liste des séries des fichiers orgmode en les reliant aux slugs de ces pages, génère une page pour lister les tags, et chaque page listant les articles liés à un tag.
|
1
WIP/tag_pages_build.py
Normal file
1
WIP/tag_pages_build.py
Normal file
|
@ -0,0 +1 @@
|
|||
# construit une liste des tags présents dans les fichiers orgmode en les reliant aux slugs de ces pages, génère une page pour lister les tags, et chaque page listant les articles liés à un tag.
|
12
WIP/website_config.py
Normal file
12
WIP/website_config.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/python3
|
||||
# configuration pour générer les sites web de plusieurs dossiers
|
||||
configs_sites = {
|
||||
"cipherbliss_blog": {
|
||||
"dossier_source":"cipherbliss_blog",
|
||||
"titre_site":"CipherBliss",
|
||||
"nom_domaine_html": "www.cipherbliss.com",
|
||||
"nom_domaine_gemini": "source.cipherbliss.com",
|
||||
"auteur": "Baptiste Lemoine",
|
||||
"description": "Petite Entreprise de développement web et logiciels libres depuis 2014"
|
||||
},
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue