From 891d5e3f6d72ca4c3c8a245ec3111193f352fc2f Mon Sep 17 00:00:00 2001
From: Ryan Fox
Date: Mon, 13 Jul 2020 06:04:40 +0000
Subject: [PATCH] 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.
---
scripts/template.py | 10 ++++++++--
templates/post_preview.html | 2 +-
templates/post_preview.xml | 2 +-
3 files changed, 10 insertions(+), 4 deletions(-)
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}
{{base}}{{full_dir}}{full_path}
{pub_date}
- {description}
+
{author}