diff --git a/scripts/template.py b/scripts/template.py index cfcad89..aa4dcb1 100644 --- a/scripts/template.py +++ b/scripts/template.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import re import markdown from datetime import datetime from email import utils +def remove_tags(text): + return re.sub(re.compile('<.*?>'), "", text) + def get_path(path, ext_in, ext_out): path = path[len("pages"):] if path[-len("index"+ext_in):] == "index"+ext_in: @@ -85,6 +89,8 @@ def template(content, path, ext, meta): meta["pub_date"] = utils.format_datetime(datetime.fromtimestamp(int(meta["timestamp"]))) meta["head"] += "\n" meta["content"] = content.format_map(meta) - if "description" not in meta and ext == ".html": - meta["description"] = meta["content"].split("
")[0]+"" # Disgusting! + if "description" not in meta and meta["ext"] == ".html": + meta["auto_description"] = remove_tags(meta["content"].split("")[0]) # Disgusting! + if "description" in meta: + meta["auto_description"] = meta["description"] return t_content.format_map(meta) diff --git a/templates/post_preview.html b/templates/post_preview.html index b97533d..717c79e 100644 --- a/templates/post_preview.html +++ b/templates/post_preview.html @@ -1,5 +1,5 @@ diff --git a/templates/post_preview.xml b/templates/post_preview.xml index 4643cfe..32c3adf 100644 --- a/templates/post_preview.xml +++ b/templates/post_preview.xml @@ -3,7 +3,7 @@ {{base}}{{full_dir}}{full_path}