Compare commits
5 Commits
694d4b74a4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b849fd94a | |||
| fa24635e40 | |||
| 77666abbca | |||
| 729400e03d | |||
| 2eb8bc99a7 |
18
blog/blog.py
18
blog/blog.py
@@ -7,6 +7,7 @@ from blog.page import Page
|
|||||||
from blog.config import Config
|
from blog.config import Config
|
||||||
from jinja2 import Environment, FileSystemLoader, Template
|
from jinja2 import Environment, FileSystemLoader, Template
|
||||||
|
|
||||||
|
|
||||||
class Blog:
|
class Blog:
|
||||||
|
|
||||||
def __init__(self, conf: Config):
|
def __init__(self, conf: Config):
|
||||||
@@ -69,7 +70,8 @@ class Blog:
|
|||||||
if updated < date:
|
if updated < date:
|
||||||
updated = date
|
updated = date
|
||||||
articles += textwrap.indent(
|
articles += textwrap.indent(
|
||||||
textwrap.dedent(f"""\
|
textwrap.dedent(
|
||||||
|
f"""\
|
||||||
<entry>
|
<entry>
|
||||||
<title>{self.pages[filename].title}</title>
|
<title>{self.pages[filename].title}</title>
|
||||||
<link href="{self.conf.url}/pages/{filename}.html"/>
|
<link href="{self.conf.url}/pages/{filename}.html"/>
|
||||||
@@ -81,10 +83,13 @@ class Blog:
|
|||||||
</div>
|
</div>
|
||||||
</content>
|
</content>
|
||||||
</entry>
|
</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">
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
<title>{self.conf.title}</title>
|
<title>{self.conf.title}</title>
|
||||||
<subtitle>{self.conf.presentation}</subtitle>
|
<subtitle>{self.conf.presentation}</subtitle>
|
||||||
@@ -96,11 +101,12 @@ class Blog:
|
|||||||
<email>{self.conf.author_mail}</email>
|
<email>{self.conf.author_mail}</email>
|
||||||
</author>
|
</author>
|
||||||
<id>urn:uuid:{self.conf.id}</id>
|
<id>urn:uuid:{self.conf.id}</id>
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
footer = "</feed>"
|
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)
|
rss_file.write(header + articles + footer)
|
||||||
|
|
||||||
def _copy_css(self):
|
def _copy_css(self):
|
||||||
|
|||||||
@@ -4,7 +4,13 @@ from pathlib import Path
|
|||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|
||||||
_conf = dict()
|
_conf = {
|
||||||
|
"inbox": "./inbox/",
|
||||||
|
"outbox": "./outbox/",
|
||||||
|
"draft": "./draft/",
|
||||||
|
"theme": "./themes/default/"
|
||||||
|
}
|
||||||
|
|
||||||
_list_valid_parameters = {
|
_list_valid_parameters = {
|
||||||
"inbox",
|
"inbox",
|
||||||
"outbox",
|
"outbox",
|
||||||
@@ -15,7 +21,7 @@ class Config:
|
|||||||
"draft",
|
"draft",
|
||||||
"author_name",
|
"author_name",
|
||||||
"author_mail",
|
"author_mail",
|
||||||
"id"
|
"id",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, config_file: Path):
|
def __init__(self, config_file: Path):
|
||||||
@@ -37,4 +43,5 @@ class Config:
|
|||||||
"""Surcharge les paramètres depuis une liste fournie"""
|
"""Surcharge les paramètres depuis une liste fournie"""
|
||||||
for valid_parameter in self._list_valid_parameters:
|
for valid_parameter in self._list_valid_parameters:
|
||||||
if valid_parameter in parameters:
|
if valid_parameter in parameters:
|
||||||
self._conf[valid_parameter] = parameters[valid_parameter]
|
if parameters[valid_parameter] != None:
|
||||||
|
self._conf[valid_parameter] = parameters[valid_parameter]
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ def new_page(title: str, path: Path) -> Path:
|
|||||||
f"""\
|
f"""\
|
||||||
---
|
---
|
||||||
date: {today}
|
date: {today}
|
||||||
title: {title}
|
title: "{title}"
|
||||||
id: {id}
|
id: {id}
|
||||||
category:
|
category:
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
10
main.py
10
main.py
@@ -25,7 +25,6 @@ def load_args():
|
|||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--inbox",
|
"--inbox",
|
||||||
default="./inbox",
|
|
||||||
help="Chemin vers les fichiers markdown du blog",
|
help="Chemin vers les fichiers markdown du blog",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -35,7 +34,6 @@ def load_args():
|
|||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--draft",
|
"--draft",
|
||||||
default="./draft",
|
|
||||||
help="Chemin vers les brouillons",
|
help="Chemin vers les brouillons",
|
||||||
)
|
)
|
||||||
parser.add_argument("all", nargs=argparse.REMAINDER, help=argparse.SUPPRESS)
|
parser.add_argument("all", nargs=argparse.REMAINDER, help=argparse.SUPPRESS)
|
||||||
@@ -48,12 +46,10 @@ def load_make_args(args: str) -> dict:
|
|||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--theme",
|
"--theme",
|
||||||
default="./themes/default",
|
|
||||||
help="Chemin vers le theme utilisé",
|
help="Chemin vers le theme utilisé",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--output",
|
"--output",
|
||||||
default="./output",
|
|
||||||
help="Nom du dossier où sera exporté le blog en html",
|
help="Nom du dossier où sera exporté le blog en html",
|
||||||
)
|
)
|
||||||
return vars(parser.parse_args(args))
|
return vars(parser.parse_args(args))
|
||||||
@@ -74,9 +70,9 @@ def main():
|
|||||||
case "new":
|
case "new":
|
||||||
page_title = " ".join(args["all"])
|
page_title = " ".join(args["all"])
|
||||||
|
|
||||||
path = conf.inbox
|
print(conf._conf)
|
||||||
if args["d"]:
|
|
||||||
path = conf.draft
|
path = conf.draft
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["nvim", "+normal G$", "+startinsert", new_page(page_title, path)]
|
["nvim", "+normal G$", "+startinsert", new_page(page_title, path)]
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user