Compare commits
4 Commits
rss
...
77666abbca
| Author | SHA1 | Date | |
|---|---|---|---|
| 77666abbca | |||
| 729400e03d | |||
| 2eb8bc99a7 | |||
| 694d4b74a4 |
3
Makefile
3
Makefile
@@ -17,6 +17,9 @@ install-dep:
|
||||
clean:
|
||||
@rm -r ./dist ./build
|
||||
|
||||
publish:
|
||||
@cd ./outbox && python3 -m http.server
|
||||
|
||||
install:
|
||||
ifeq ($(USER), root)
|
||||
@cp ./dist/main /usr/local/bin/blog
|
||||
|
||||
18
blog/blog.py
18
blog/blog.py
@@ -7,6 +7,7 @@ from blog.page import Page
|
||||
from blog.config import Config
|
||||
from jinja2 import Environment, FileSystemLoader, Template
|
||||
|
||||
|
||||
class Blog:
|
||||
|
||||
def __init__(self, conf: Config):
|
||||
@@ -69,7 +70,8 @@ class Blog:
|
||||
if updated < date:
|
||||
updated = date
|
||||
articles += textwrap.indent(
|
||||
textwrap.dedent(f"""\
|
||||
textwrap.dedent(
|
||||
f"""\
|
||||
<entry>
|
||||
<title>{self.pages[filename].title}</title>
|
||||
<link href="{self.conf.url}/pages/{filename}.html"/>
|
||||
@@ -81,10 +83,13 @@ class Blog:
|
||||
</div>
|
||||
</content>
|
||||
</entry>
|
||||
"""),
|
||||
" ")
|
||||
"""
|
||||
),
|
||||
" ",
|
||||
)
|
||||
|
||||
header = textwrap.dedent(f""" <?xml version="1.0" encoding="utf-8"?>
|
||||
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>
|
||||
@@ -96,11 +101,12 @@ class Blog:
|
||||
<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:
|
||||
with open(Path(self.conf.outbox) / "atom.xml", "w+") as rss_file:
|
||||
rss_file.write(header + articles + footer)
|
||||
|
||||
def _copy_css(self):
|
||||
|
||||
@@ -15,7 +15,7 @@ class Config:
|
||||
"draft",
|
||||
"author_name",
|
||||
"author_mail",
|
||||
"id"
|
||||
"id",
|
||||
}
|
||||
|
||||
def __init__(self, config_file: Path):
|
||||
|
||||
10
blog/page.py
10
blog/page.py
@@ -14,13 +14,13 @@ def new_page(title: str, path: Path) -> Path:
|
||||
|
||||
today = date.today().strftime("%Y-%m-%d")
|
||||
|
||||
filename = path + '/' + re.sub("[^a-zA-Z0-9-]", "_", title) + ".md"
|
||||
filename = path + "/" + re.sub("[^a-zA-Z0-9-]", "_", title) + ".md"
|
||||
id = uuid.uuid4()
|
||||
content = textwrap.dedent(
|
||||
f"""\
|
||||
---
|
||||
date: {today}
|
||||
title: {title}
|
||||
title: "{title}"
|
||||
id: {id}
|
||||
category:
|
||||
tags:
|
||||
@@ -43,6 +43,8 @@ class Page:
|
||||
md_content = ""
|
||||
filename = ""
|
||||
|
||||
_cache = ""
|
||||
|
||||
def __init__(self, filename: Path):
|
||||
"""Constructeur : nouvelle page"""
|
||||
self.filename = filename
|
||||
@@ -84,10 +86,12 @@ class Page:
|
||||
|
||||
def html(self) -> str:
|
||||
"""Convertit le markdown en html"""
|
||||
return markdown.markdown(
|
||||
if not self._cache:
|
||||
self._cache = markdown.markdown(
|
||||
self.md_content, extensions=["codehilite", "fenced_code"]
|
||||
)
|
||||
|
||||
return self._cache
|
||||
|
||||
def html_template(self, template: jinja2.Template) -> str:
|
||||
"""Convertit la page en html a partir d'un template jinja2"""
|
||||
|
||||
Reference in New Issue
Block a user