Browse Source

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
master
Macoy Madson 1 year ago
parent
commit
65ff0d6895
3 changed files with 25 additions and 9 deletions
  1. +8
    -7
      SimpleBlogServer.py
  2. +3
    -0
      templates/BlogPost.html
  3. +14
    -2
      webResources/styles.css

+ 8
- 7
SimpleBlogServer.py View File

@ -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'<h1.*>(.*)</h1>', htmlBody)
return match[1]
def getBlogHtmlBody(requestedContent):
renderedBody = ContentConverter.getRenderedBody(requestedContent)
if not renderedBody:
renderedBody = "<p>The post under '{}' does not exist.</p>".format(requestedContent)
return renderedBody
def getPrettyHtmlTime(time):
return time.strftime("%B&nbsp;%d,&nbsp;%Y")
class HomeHandler(tornado.web.RequestHandler):
def get(self):
allPosts = ContentConverter.getAllPostsList()
@ -55,7 +53,7 @@ class HomeHandler(tornado.web.RequestHandler):
contentListHtml += ('<div class="blogPostLinkContainer"><a class="blogPostLink" href="blog/{contentPath}">{title}</a><time class="publishedDate">— {published}</time>{tagsHtml}</div>\n'
.format(contentPath = metadata.contentPath,
title = metadata.properties["TITLE"],
published = metadata.properties["PUBLISHED"].strftime("%B&nbsp;%d,&nbsp;%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


+ 3
- 0
templates/BlogPost.html View File

@ -13,7 +13,10 @@
{% raw postBody %}
</article>
<p class="timeLabel">Published on <time>{% raw published %}</time></p>
<br />
<nav>
<a href="/">Back to Home</a>
</nav>


+ 14
- 2
webResources/styles.css View File

@ -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;
}


Loading…
Cancel
Save