Ajoute la gestion des brouillons
This commit is contained in:
37
blog/blog.py
37
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:
|
||||
|
||||
@@ -13,18 +13,14 @@ class Blog:
|
||||
self.conf = conf
|
||||
self.pages = dict()
|
||||
|
||||
def load_pages(self):
|
||||
"""Charge tous les fichiers .md dans le dossier inbox"""
|
||||
files_list = glob.glob(f"{self.conf.inbox}/*.md")
|
||||
def make(self, draft: bool = False):
|
||||
"""Convertit les pages en un site html"""
|
||||
|
||||
self.pages = dict()
|
||||
for file in files_list:
|
||||
self.pages[Path(file).stem] = Page(Path(file))
|
||||
self._load_pages(self.conf.inbox)
|
||||
|
||||
def make(self):
|
||||
"""Convertit les pages en un site html"""
|
||||
if not self.pages:
|
||||
self.load_pages()
|
||||
if draft:
|
||||
self._load_pages(self.conf.draft)
|
||||
|
||||
env = Environment(loader=FileSystemLoader(self.conf.theme))
|
||||
|
||||
@@ -34,7 +30,12 @@ class Blog:
|
||||
self._copy_css()
|
||||
self._build_all_pages(page_template)
|
||||
self._build_index(index_template)
|
||||
self._build_rss()
|
||||
|
||||
def _load_pages(self, path: Path):
|
||||
"""Charge tous les fichiers .md dans le dossier inbox"""
|
||||
files_list = glob.glob(f"{path}/*.md")
|
||||
for file in files_list:
|
||||
self.pages[Path(file).stem] = Page(Path(file))
|
||||
|
||||
def _build_all_pages(self, template: Template):
|
||||
"""Convertit les pages markdown dans conf.inbox en html dans conf.outbox"""
|
||||
@@ -56,20 +57,8 @@ 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):
|
||||
"""Copie les fichiers CSS du theme vers l'export"""
|
||||
css_path = Path(self.conf.theme) / "css"
|
||||
dest_path = Path(self.conf.outbox) / "css"
|
||||
|
||||
|
Reference in New Issue
Block a user