Ajout du RSS/Atom & de la génération du fichier index
This commit is contained in:
parent
0d1710412d
commit
47a81050dc
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
.venv
|
||||
archives
|
||||
articles/*
|
||||
atom.xml
|
||||
index.html
|
@ -9,3 +9,7 @@ Le générateur en python permet de passé de fichier markdown à des fichier ht
|
||||
|
||||
- Flux RSS
|
||||
- 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.
|
23
tools/atom_post_template.xml
Normal file
23
tools/atom_post_template.xml
Normal 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">
|
||||
<h1>$TITLE</h1>
|
||||
$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
12
tools/atom_template.xml
Normal 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
43
tools/index_template.html
Normal 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>
|
@ -2,10 +2,12 @@ import os
|
||||
|
||||
articles_path = 'articles/'
|
||||
generate_path = 'archives/'
|
||||
atom_content = ""
|
||||
index_content = "<h2>Articles</h2><ul>"
|
||||
|
||||
"""Parse le fichier markdown et retourne le contenu à mettre dans notre page html"""
|
||||
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
|
||||
for line in open('../' + articles_path + filename, "r"):
|
||||
line = line.strip()
|
||||
@ -89,22 +91,52 @@ def parsemd(filename):
|
||||
def md2html(filename):
|
||||
content = parsemd(filename) # Contenu parsé de notre fichier markdown
|
||||
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.write(template.replace("$CONTENT", content['content']).replace("$TITLE", content['title']).
|
||||
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'
|
||||
|
||||
"""
|
||||
def generateRSS(data):
|
||||
""" Génère le post Atom"""
|
||||
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 not os.path.exists('../' + generate_path):
|
||||
os.mkdir('../' + generate_path)
|
||||
else:
|
||||
else: # Régénation du blog
|
||||
for file in os.listdir('../' + generate_path):
|
||||
os.remove('../' + generate_path + file)
|
||||
os.remove('../atom.xml')
|
||||
os.remove('../index.html')
|
||||
|
||||
for file in os.listdir('../' + articles_path):
|
||||
print("Génération en cours du fichier: " + file)
|
||||
md2html(file)
|
||||
print("Génération du fichier RSS / Atom")
|
||||
generateAtom()
|
||||
print("Génération de l'index")
|
||||
updateIndex()
|
@ -10,7 +10,7 @@
|
||||
<meta property="og:article:published_time" content="$DATE" >
|
||||
<meta property="og:image" content="$IMAGE_PREVIEW" >
|
||||
<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="shortcut icon" href="../assets/favicon/favicon.ico" type="image/x-icon">
|
||||
</head>
|
||||
|
Loading…
x
Reference in New Issue
Block a user