From e12cf1463848faa973d7c2ec174892655d131c22 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Thu, 18 Jan 2018 13:43:19 +0800 Subject: + fix --- rss.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'rss.py') diff --git a/rss.py b/rss.py index 928bf34..af9f0ca 100644 --- a/rss.py +++ b/rss.py @@ -1,7 +1,7 @@ +import glob import os -import jinja2 -import glob +import jinja2 from bs4 import BeautifulSoup @@ -31,16 +31,18 @@ def main(): filenames = glob.glob("./_build/html/_posts/*/*/*.html") posts = [] - for p in filenames: - soup = BeautifulSoup(open(p), "html5lib") + for file in filenames: + soup = BeautifulSoup(open(file), "html5lib") body = soup.find_all("div", class_="body")[0].text posts.append({ "title": soup.title.string, "body": body, "date_rss": body[body.find("Publish Date:")+13:body.find("Publish Date:")+23], - "permalink": "/".join(p.split("/")[3:]) + "permalink": "/".join(file.split("/")[3:]) }) + with open(file, "w") as file: + file.write(str(BeautifulSoup(str(soup).replace("\n", "").replace("\r", ""), "html5lib").prettify())) context = { "site": { -- cgit v1.2.3