Ajoute le flux atom
This commit is contained in:
60
blog/blog.py
60
blog/blog.py
@@ -1,10 +1,11 @@
|
||||
import glob
|
||||
import shutil
|
||||
import datetime
|
||||
import textwrap
|
||||
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:
|
||||
|
||||
@@ -30,7 +31,7 @@ class Blog:
|
||||
self._copy_css()
|
||||
self._build_all_pages(page_template)
|
||||
self._build_index(index_template)
|
||||
self._build_rss()
|
||||
self._build_atom()
|
||||
|
||||
def _load_pages(self, path: Path):
|
||||
"""Charge tous les fichiers .md dans le dossier inbox"""
|
||||
@@ -46,7 +47,7 @@ class Blog:
|
||||
outbox_path.mkdir()
|
||||
|
||||
for filename in self.pages:
|
||||
html_content = self.pages[filename].html(template)
|
||||
html_content = self.pages[filename].html_template(template)
|
||||
with open(f"{self.conf.outbox}/pages/{filename}.html", "w+") as html_file:
|
||||
html_file.write(html_content)
|
||||
|
||||
@@ -58,18 +59,49 @@ class Blog:
|
||||
with open(f"{self.conf.outbox}/index.html", "w+") as html_file:
|
||||
html_file.write(html_content)
|
||||
|
||||
def _build_rss(self):
|
||||
def _build_atom(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')
|
||||
updated = datetime.date(1970, 1, 1)
|
||||
|
||||
articles = ""
|
||||
for filename in self.pages:
|
||||
date = self.pages[filename].date
|
||||
if updated < date:
|
||||
updated = date
|
||||
articles += textwrap.indent(
|
||||
textwrap.dedent(f"""\
|
||||
<entry>
|
||||
<title>{self.pages[filename].title}</title>
|
||||
<link href="{self.conf.url}/pages/{filename}.html"/>
|
||||
<updated>{date}T00:00:00Z</updated>
|
||||
<id>urn:uuid:{self.pages[filename].id}</id>
|
||||
<content type="xhtml">
|
||||
<div xmlns="http://www.w3.org/1999/xhtml">
|
||||
{self.pages[filename].html()}
|
||||
</div>
|
||||
</content>
|
||||
</entry>
|
||||
"""),
|
||||
" ")
|
||||
|
||||
header = textwrap.dedent(f""" <?xml version="1.0" encoding="utf-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>{self.conf.title}</title>
|
||||
<subtitle>{self.conf.presentation}</subtitle>
|
||||
<link href="{self.conf.url}/atom.xml" rel="self"/>
|
||||
<link href="{self.conf.url}/index.html"/>
|
||||
<updated>{updated}T00:00:00Z</updated>
|
||||
<author>
|
||||
<name>{self.conf.author_name}</name>
|
||||
<email>{self.conf.author_mail}</email>
|
||||
</author>
|
||||
<id>urn:uuid:{self.conf.id}</id>
|
||||
""")
|
||||
|
||||
footer = "</feed>"
|
||||
|
||||
with open(Path(self.conf.outbox) / "atom.xml", 'w+') as rss_file:
|
||||
rss_file.write(header + articles + footer)
|
||||
|
||||
def _copy_css(self):
|
||||
"""Copie les fichiers CSS du theme vers l'export"""
|
||||
|
Reference in New Issue
Block a user