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:
parent
07934e18b2
commit
891d5e3f6d
@ -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)
|
||||
|
@ -1,5 +1,5 @@
|
||||
<div class="block">
|
||||
<a href="{full_path}"><h3>{title}</h3></a>
|
||||
<p>{description}</p>
|
||||
<p>{auto_description}</p>
|
||||
<a href="{full_path}">Read more</a>
|
||||
</div>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<link>{{base}}{{full_dir}}{full_path}</link>
|
||||
<guid isPermaLink="true">{{base}}{{full_dir}}{full_path}</guid>
|
||||
<pubDate>{pub_date}</pubDate>
|
||||
<description>{description}</description>
|
||||
<description><![CDATA[{auto_description}]]></description>
|
||||
<content:encoded><![CDATA[{content}]]></content:encoded>
|
||||
<author>{author}</author>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user