Commit e0e669e1 authored by Marien Fressinaud's avatar Marien Fressinaud

Add more information to article and site

parent 39c7a809
...@@ -134,6 +134,21 @@ For now, you can use any valid Python expression between `{{ }}`, you have ...@@ -134,6 +134,21 @@ For now, you can use any valid Python expression between `{{ }}`, you have
access to the variables defined in the meta header, the Python builtin access to the variables defined in the meta header, the Python builtin
functions and the `datetime` module. functions and the `datetime` module.
The following meta variables have specific significance, especially in the Atom
feed:
- `slug` (defines the final URL of the article)
- `title`
- `author`
- `date` (the date of publication)
- `update` (the date of the last update)
It is highly recommended to always specify `title` and `date` (or default
values will be generated). The default value of `slug` is the name of the file
without its extension. A default value for `author` can be set in the
`configuration.yml` file. `date` and `update` must follow this format:
`YYYY-MM-DD HH:MM`.
The `./theme` folder can contain a `static` folder as well. Its content will be The `./theme` folder can contain a `static` folder as well. Its content will be
copied under the `./site` folder: copied under the `./site` folder:
......
...@@ -6,8 +6,11 @@ import shutil ...@@ -6,8 +6,11 @@ import shutil
import distutils.dir_util import distutils.dir_util
import locale import locale
import yaml import yaml
import datetime
import uuid
import markdown import markdown
import pytz
import boopsy import boopsy
...@@ -63,9 +66,46 @@ class Article: ...@@ -63,9 +66,46 @@ class Article:
def title(self): def title(self):
return self.meta.get("ARTICLE_TITLE", "An article") return self.meta.get("ARTICLE_TITLE", "An article")
def author(self):
if "ARTICLE_AUTHOR" in self.meta:
return self.meta["ARTICLE_AUTHOR"]
elif "SITE_AUTHOR" in self.meta:
return self.meta["SITE_AUTHOR"]
else:
return None
def url(self):
site_url = self.meta.get("SITE_URL", "")
return f"{site_url}{self.slug()}.html"
def uuid(self):
return str(uuid.uuid5(uuid.NAMESPACE_URL, self.url()))
def content(self): def content(self):
return self.meta["ARTICLE_CONTENT"] return self.meta["ARTICLE_CONTENT"]
def timezone(self):
site_timezone = self.meta.get("SITE_TIMEZONE", "UTC")
return pytz.timezone(site_timezone)
def date(self):
if "ARTICLE_DATE" not in self.meta:
return datetime.datetime.now(tz=self.timezone())
article_date = datetime.datetime.strptime(
self.meta["ARTICLE_DATE"], "%Y-%m-%d %H:%M"
)
return article_date.astimezone(tz=self.timezone())
def update(self):
if "ARTICLE_UPDATE" not in self.meta:
return None
article_update = datetime.datetime.strptime(
self.meta["ARTICLE_UPDATE"], "%Y-%m-%d %H:%M"
)
return article_update.astimezone(tz=self.timezone())
def dir_tree(path): def dir_tree(path):
"""List all the tree directory under the given path. """List all the tree directory under the given path.
...@@ -124,6 +164,9 @@ def main(): ...@@ -124,6 +164,9 @@ def main():
site_key = f"SITE_{key.upper()}" site_key = f"SITE_{key.upper()}"
configuration[site_key] = value configuration[site_key] = value
configuration["SITE_UUID"] = str(
uuid.uuid5(uuid.NAMESPACE_URL, configuration["SITE_URL"])
)
if "SITE_AUTHOR" not in configuration: if "SITE_AUTHOR" not in configuration:
configuration["SITE_AUTHOR"] = f"{configuration['SITE_TITLE']}'s author" configuration["SITE_AUTHOR"] = f"{configuration['SITE_TITLE']}'s author"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment