Ajout du RSS/Atom & de la génération du fichier index

This commit is contained in:
Oxbian 2023-04-03 12:01:26 +02:00
parent 0d1710412d
commit 47a81050dc
7 changed files with 125 additions and 9 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
.venv .venv
archives archives
articles/* articles/*
atom.xml
index.html

View File

@ -9,3 +9,7 @@ Le générateur en python permet de passé de fichier markdown à des fichier ht
- Flux RSS - Flux RSS
- Ajout automatique des pages générées dans la page principale - Ajout automatique des pages générées dans la page principale
# Crédits
Ce projet m'a été inspiré par le [générateur de blog](https://git.sr.ht/~lioploum/ploum.net) de [Ploum](https://ploum.net), merci à lui pour son travail remarquable.

View File

@ -0,0 +1,23 @@
<entry xml:lang="fr">
<author><name>Oxbian</name><uri>https://blog.arka.rocks</uri></author>
<title type="html">$TITLE</title>
<link rel="alternate" type="text/html" href="$URL"/>
<id>$URL</id>
<published>$DATE</published>
<updated>$DATE</updated>
<content type="html">
&lt;h1&gt;$TITLE&lt;/h1&gt;
$CONTENT
</content>
</entry>
<h2>Articles sur les bonnes pratiques</h2>
<ul>
<li><a href="articles/">Vie privée</a></li>
<li><a href="articles/">Vie privée</a></li>
</ul>
<h2>Autres articles</h2>
<ul>
<li><a href="articles/">KKOOOYYAAA</a></li>
</ul>

12
tools/atom_template.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0"
xml:lang="fr">
<title type="text">blog.arka.rocks</title>
<subtitle type="text">Blog d'Oxbian</subtitle>
<updated>$DATE</updated>
<link rel="alternate" type="text/html" href="https://blog.arka.rocks"/>
<id>https://blog.arka.rocks</id>
<link rel="self" type="application/atom+xml" href="https://blog.arka.rocks/atom.xml"/>
$CONTENT
</feed>

43
tools/index_template.html Normal file
View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Blog d'Oxbian">
<meta property="og:title" content="Blog d'Oxbian">
<meta property="og:url" content="https://blog.arka.rocks">
<meta property="og:type" content="article">
<meta property="og:article:author" content="Oxbian">
<title>Blog d'Oxbian</title>
<link rel="alternate" href="../atom.xml" type="application/atom+xml" title="RSS">
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="shortcut icon" href="../assets/favicon/favicon.ico" type="image/x-icon">
</head>
<body>
<header>
<div class="navbar">
<a href="index.html">Accueil</a>
<a href="pages/howtoread.html">Comment lire ce blog ?</a>
<a href="pages/about.html">À Propos</a>
</div>
</header>
<main>
<article>
<h1>Bienvenue sur mon blog</h1>
<p>Sur ce blog vous retrouverez des articles liées à l'informatique, la programmation, le réseau, la sécurité, le libre, etc.
De plus j'y partage aussi des articles sur les bonnes pratiques dans divers domaines, comme la vie privée, le sport..</p>
$CONTENT
</article>
</main>
<hr>
<footer>
<p>Contactez-moi pour toute question ou discussion, je répond assez vite en général.</p>
<div>
<a class="matrix" href="https://matrix.to/#/@oxbian:matrix.org">Matrix</a>
<a class="mastodon" href="https://social.linux.pizza/@Oxbian">Mastodon</a>
<a class="mail" href="mailto:oxbian.noch@simplelogin.com">Mail</a>
</div>
</footer>
</body>
</html>

View File

@ -2,10 +2,12 @@ import os
articles_path = 'articles/' articles_path = 'articles/'
generate_path = 'archives/' generate_path = 'archives/'
atom_content = ""
index_content = "<h2>Articles</h2><ul>"
"""Parse le fichier markdown et retourne le contenu à mettre dans notre page html""" """Parse le fichier markdown et retourne le contenu à mettre dans notre page html"""
def parsemd(filename): def parsemd(filename):
content = {'content': '', 'title': '', 'date': '', 'description': ''} content = {'content': '', 'title': '', 'date': '', 'description': '', 'filename': generate_path + filename.split('.')[0] + '.html'}
inquote, inpre, inul = False, False, False inquote, inpre, inul = False, False, False
for line in open('../' + articles_path + filename, "r"): for line in open('../' + articles_path + filename, "r"):
line = line.strip() line = line.strip()
@ -89,22 +91,52 @@ def parsemd(filename):
def md2html(filename): def md2html(filename):
content = parsemd(filename) # Contenu parsé de notre fichier markdown content = parsemd(filename) # Contenu parsé de notre fichier markdown
template = open('page_template.html', 'r').read() template = open('page_template.html', 'r').read()
# Création du fichier html & ajout du contenu
output = open('../' + generate_path + filename.split('.')[0] + '.html', 'w') output = open('../' + generate_path + filename.split('.')[0] + '.html', 'w')
output.write(template.replace("$CONTENT", content['content']).replace("$TITLE", content['title']). output.write(template.replace("$CONTENT", content['content']).replace("$TITLE", content['title']).
replace("$DATE", content['date']).replace("$DESC", content['description'])) replace("$DATE", content['date']).replace("$DESC", content['description']))
output.close()
# Génération du post Atom et de l'index
generatePageXML(content)
global index_content
index_content += '<li><a href="' + content['filename'] + '">' + content['title'] + '</a></li>\n'
""" """ Génère le post Atom"""
def generateRSS(data): def generatePageXML(data):
global atom_content
template = open('atom_post_template.xml', 'r').read()
atom_content += template.replace("$TITLE", data['title']).replace("$DATE", data['date']).replace("$CONTENT",
data['content']).replace("$URL", "https://blog.arka.rocks/" + data['filename'])
""" Génère le fichier Atom"""
def generateAtom():
template = open('atom_template.xml', 'r').read()
output = open('../atom.xml', 'w')
output.write(template.replace("$CONTENT", atom_content))
output.close()
""" Génère l'index"""
def updateIndex():
template = open('index_template.html', 'r').read()
output = open('../index.html', 'w')
output.write(template.replace("$CONTENT", index_content + '</ul>'))
output.close()
def updateIndex(data):
"""
if __name__=="__main__": if __name__=="__main__":
if not os.path.exists('../' + generate_path): if not os.path.exists('../' + generate_path):
os.mkdir('../' + generate_path) os.mkdir('../' + generate_path)
else: else: # Régénation du blog
for file in os.listdir('../' + generate_path): for file in os.listdir('../' + generate_path):
os.remove('../' + generate_path + file) os.remove('../' + generate_path + file)
os.remove('../atom.xml')
os.remove('../index.html')
for file in os.listdir('../' + articles_path): for file in os.listdir('../' + articles_path):
print("Génération en cours du fichier: " + file) print("Génération en cours du fichier: " + file)
md2html(file) md2html(file)
print("Génération du fichier RSS / Atom")
generateAtom()
print("Génération de l'index")
updateIndex()

View File

@ -10,7 +10,7 @@
<meta property="og:article:published_time" content="$DATE" > <meta property="og:article:published_time" content="$DATE" >
<meta property="og:image" content="$IMAGE_PREVIEW" > <meta property="og:image" content="$IMAGE_PREVIEW" >
<title>$TITLE</title> <title>$TITLE</title>
<link rel="alternate" href="../rss.xml" type="application/rss+xml" title="RSS"> <link rel="alternate" href="../atom.xml" type="application/atom+xml" title="RSS">
<link rel="stylesheet" href="../assets/css/style.css"> <link rel="stylesheet" href="../assets/css/style.css">
<link rel="shortcut icon" href="../assets/favicon/favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="../assets/favicon/favicon.ico" type="image/x-icon">
</head> </head>