diff options
author | Oxbian <got.dacs@slmail.me> | 2023-04-03 12:01:26 +0200 |
---|---|---|
committer | Oxbian <got.dacs@slmail.me> | 2023-04-03 12:01:26 +0200 |
commit | 47a81050dc892a04bd176e14422daacf9e41e84e (patch) | |
tree | ec5990a214e6217e30462e79aa11655076d16aaa | |
parent | 0d1710412d5949e67a11a50a5f7309a38ef0823e (diff) | |
download | ArKa-Blog-47a81050dc892a04bd176e14422daacf9e41e84e.tar.gz ArKa-Blog-47a81050dc892a04bd176e14422daacf9e41e84e.zip |
Ajout du RSS/Atom & de la génération du fichier index
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | readme.md | 6 | ||||
-rw-r--r-- | tools/atom_post_template.xml | 23 | ||||
-rw-r--r-- | tools/atom_template.xml | 12 | ||||
-rw-r--r-- | tools/index_template.html | 43 | ||||
-rw-r--r-- | tools/page-generator.py | 46 | ||||
-rw-r--r-- | tools/page_template.html | 2 |
7 files changed, 125 insertions, 9 deletions
@@ -1,3 +1,5 @@ .venv archives articles/* +atom.xml +index.html
\ No newline at end of file @@ -8,4 +8,8 @@ Le générateur en python permet de passé de fichier markdown à des fichier ht # TODO - Flux RSS -- Ajout automatique des pages générées dans la page principale
\ No newline at end of file +- 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.
\ No newline at end of file diff --git a/tools/atom_post_template.xml b/tools/atom_post_template.xml new file mode 100644 index 0000000..52703f7 --- /dev/null +++ b/tools/atom_post_template.xml @@ -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>
\ No newline at end of file diff --git a/tools/atom_template.xml b/tools/atom_template.xml new file mode 100644 index 0000000..9fca838 --- /dev/null +++ b/tools/atom_template.xml @@ -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> diff --git a/tools/index_template.html b/tools/index_template.html new file mode 100644 index 0000000..680e43a --- /dev/null +++ b/tools/index_template.html @@ -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>
\ No newline at end of file diff --git a/tools/page-generator.py b/tools/page-generator.py index e5747db..bde61a0 100644 --- a/tools/page-generator.py +++ b/tools/page-generator.py @@ -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' +""" 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']) -""" -def generateRSS(data): +""" 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)
\ No newline at end of file + md2html(file) + print("Génération du fichier RSS / Atom") + generateAtom() + print("Génération de l'index") + updateIndex()
\ No newline at end of file diff --git a/tools/page_template.html b/tools/page_template.html index 3dda284..7c6bf0d 100644 --- a/tools/page_template.html +++ b/tools/page_template.html @@ -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> |