diff --git a/.blog.template b/.blog.template index ff22bfe..13763fb 100644 --- a/.blog.template +++ b/.blog.template @@ -1,5 +1,6 @@ theme: './theme/default' inbox: './inbox' outbox: './outbox' +url: 'https://blog.example.com' title: 'Blog title' presentation: 'Blog presentation.' diff --git a/blog/blog.py b/blog/blog.py index 77d8cf5..743bf17 100644 --- a/blog/blog.py +++ b/blog/blog.py @@ -4,7 +4,7 @@ from pathlib import Path from blog.page import Page from blog.config import Config from jinja2 import Environment, FileSystemLoader, Template - +from rss import RssFeed class Blog: @@ -34,6 +34,7 @@ class Blog: self._copy_css() self._build_all_pages(page_template) self._build_index(index_template) + self._build_rss() def _build_all_pages(self, template: Template): """Convertit les pages markdown dans conf.inbox en html dans conf.outbox""" @@ -55,6 +56,19 @@ class Blog: with open(f"{self.conf.outbox}/index.html", "w+") as html_file: html_file.write(html_content) + def _build_rss(self): + """ """ + feed = RssFeed(language="fr-fr", title=self.conf.title, link=self.conf.url, description=self.conf.presentation ) + for page in self.pages: + feed.add_item( + title = self.pages[page].meta["title"], + link = Path(self.conf.url) / 'pages' / (page + '.html'), + description = "Ma description a moi !", + pubdate = self.pages[page].meta["date"] + ) + with open(Path(self.conf.outbox) / "flux.rss", 'w+') as rss_file: + feed.write(rss_file, 'utf-8') + def _copy_css(self): css_path = Path(self.conf.theme) / "css" dest_path = Path(self.conf.outbox) / "css" diff --git a/blog/config.py b/blog/config.py index a46ef6c..f9c40bb 100644 --- a/blog/config.py +++ b/blog/config.py @@ -5,7 +5,7 @@ from pathlib import Path class Config: _conf = dict() - _list_valid_parameters = {"inbox", "outbox", "theme", "title", "presentation"} + _list_valid_parameters = {"inbox", "outbox", "theme", "title", "presentation", "url"} def __init__(self, config_file: Path): """Constructeur : charge les paramètres depuis le fichier de configuration"""