From 65ff0d6895f9dc587ca96fd7bd64bd7dd6fe8b41 Mon Sep 17 00:00:00 2001 From: Macoy Madson Date: Tue, 16 Jul 2019 21:39:27 -0700 Subject: [PATCH] Added date to blog post, styles adjustments * Blog post template now has published dates * Line height is increased according to web readability guidelines * Tables now have more padding * Titles come from metadata instead of parsed HTML --- SimpleBlogServer.py | 15 ++++++++------- templates/BlogPost.html | 3 +++ webResources/styles.css | 16 ++++++++++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/SimpleBlogServer.py b/SimpleBlogServer.py index bcfd981..40d3773 100755 --- a/SimpleBlogServer.py +++ b/SimpleBlogServer.py @@ -18,17 +18,15 @@ import ContentConverter # Tornado handlers # -def getTitleFromBody(htmlBody): - # The cardinal sin: do not use regex to parse HTML! :D - match = re.match(r'(.*)', htmlBody) - return match[1] - def getBlogHtmlBody(requestedContent): renderedBody = ContentConverter.getRenderedBody(requestedContent) if not renderedBody: renderedBody = "

The post under '{}' does not exist.

".format(requestedContent) return renderedBody +def getPrettyHtmlTime(time): + return time.strftime("%B %d, %Y") + class HomeHandler(tornado.web.RequestHandler): def get(self): allPosts = ContentConverter.getAllPostsList() @@ -55,7 +53,7 @@ class HomeHandler(tornado.web.RequestHandler): contentListHtml += ('\n' .format(contentPath = metadata.contentPath, title = metadata.properties["TITLE"], - published = metadata.properties["PUBLISHED"].strftime("%B %d, %Y"), + published = getPrettyHtmlTime(metadata.properties["PUBLISHED"]), tagsHtml = tagsHtml)) # Home is also just a rendered content file, just with a special name @@ -66,9 +64,12 @@ class HomeHandler(tornado.web.RequestHandler): class BlogHandler(tornado.web.RequestHandler): def get(self, request): renderedBody = getBlogHtmlBody(request) + metadata = ContentConverter.getRenderedContentDictionary()[request] self.render("templates/BlogPost.html", - title=getTitleFromBody(renderedBody), postBody=renderedBody) + title=metadata.properties["TITLE"], + postBody=renderedBody, + published=getPrettyHtmlTime(metadata.properties["PUBLISHED"])) # # Startup diff --git a/templates/BlogPost.html b/templates/BlogPost.html index de4bf31..c456103 100644 --- a/templates/BlogPost.html +++ b/templates/BlogPost.html @@ -13,7 +13,10 @@ {% raw postBody %} +

Published on

+
+ diff --git a/webResources/styles.css b/webResources/styles.css index 22b92dd..dea792c 100644 --- a/webResources/styles.css +++ b/webResources/styles.css @@ -6,6 +6,7 @@ html { body { /* Center body */ margin: 0 auto; + padding: 30px; /* Make sure lines don't get too long */ max-width: 700px; } @@ -23,6 +24,16 @@ th, time { color: #c7ae95; font-family: Arial; + line-height: 1.65; +} + +table { + border-collapse: separate; + border-spacing: 20px 0; +} + +th { + text-align: left; } .blogPostLinkContainer { @@ -66,14 +77,15 @@ td { color: #95aec7; } -time { +time, +.timeLabel { /* color: #95aec7; */ color: #7c91a5; font-style: italic; - font-size: smaller; } .publishedDate { + font-size: smaller; margin-left: 20px; }