Improve handling of descriptions

I created a separate variable for automatically generated descriptions,
since I would like to add meta tags for the manual ones in the future.
This commit is contained in:
2020-07-13 07:47:14 +00:00
parent 07934e18b2
commit 891d5e3f6d
3 changed files with 10 additions and 4 deletions
+8 -2
View File
@@ -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<link rel=\"canonical\" href=\""+meta["base"]+meta["full_path"]+"\"/>"
meta["content"] = content.format_map(meta)
if "description" not in meta and ext == ".html":
meta["description"] = meta["content"].split("</p>")[0]+"</p>" # Disgusting!
if "description" not in meta and meta["ext"] == ".html":
meta["auto_description"] = remove_tags(meta["content"].split("</p>")[0]) # Disgusting!
if "description" in meta:
meta["auto_description"] = meta["description"]
return t_content.format_map(meta)