diff --git a/ContentConverter.py b/ContentConverter.py index e448af1..9fb0d20 100644 --- a/ContentConverter.py +++ b/ContentConverter.py @@ -87,6 +87,10 @@ Interface def getAllPostsList(): allPosts = [] for key, value in renderedDictionary.items(): + # Hide folders and files with '_hidden' (they can still be retrieved though) + if '_hidden' in key: + continue + allPosts.append(key) return allPosts diff --git a/SimpleBlogServer.py b/SimpleBlogServer.py index 1310478..00466ea 100755 --- a/SimpleBlogServer.py +++ b/SimpleBlogServer.py @@ -1,14 +1,16 @@ #!/usr/bin/env python3 +import tornado.gen +import tornado.httpclient +import tornado.httpserver import tornado.ioloop import tornado.web import tornado.websocket -import tornado.httpclient -import tornado.httpserver -import tornado.gen import os from datetime import datetime +import random +import re import ContentConverter @@ -16,25 +18,39 @@ 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 + class HomeHandler(tornado.web.RequestHandler): def get(self): allPosts = ContentConverter.getAllPostsList() - self.render("templates/Home.html", allPosts=allPosts) + renderedHomeBody = getBlogHtmlBody('Home_hidden') + self.render("templates/Home.html", allPosts=allPosts, homeBody=renderedHomeBody) class BlogHandler(tornado.web.RequestHandler): def get(self, request): - contentTitle = "Blog: " + request - renderedBody = ContentConverter.getRenderedBody(request) - if not renderedBody: - renderedBody = "

The post under '{}' does not exist.

".format(request) + renderedBody = getBlogHtmlBody(request) - self.render("templates/BlogPost.html", title=contentTitle, postBody=renderedBody) + self.render("templates/BlogPost.html", + title=getTitleFromBody(renderedBody), postBody=renderedBody) # # Startup # def make_app(): + # Makes sure we don't have predictable cookies to combat spoofed requests + randomGenerator = random.SystemRandom() + cookieSecret = str(randomGenerator.getrandbits(128)) + return tornado.web.Application([ # Home page (r'/', HomeHandler), @@ -51,11 +67,10 @@ def make_app(): # (r'/output/(.*)', tornado.web.StaticFileHandler, {'path' : 'output'}), # Static files. Keep this at the bottom because it handles everything else - # TODO put these in a subdir so everything isn't accessible (r'/webResources/(.*)', tornado.web.StaticFileHandler, {'path' : 'webResources'}), ], xsrf_cookies=True, - cookie_secret='this is my org blog') + cookie_secret=cookieSecret) if __name__ == '__main__': diff --git a/content/Home_hidden.org b/content/Home_hidden.org new file mode 100644 index 0000000..89d0a41 --- /dev/null +++ b/content/Home_hidden.org @@ -0,0 +1,2 @@ +* Simple Org Blog +The owner has not set up their ~Home_hidden.org~ file. diff --git a/templates/BlogPost.html b/templates/BlogPost.html index 8fd008a..481092c 100644 --- a/templates/BlogPost.html +++ b/templates/BlogPost.html @@ -1,9 +1,17 @@ - - {{ title }} - - - - {% raw postBody %} - - + + {{ title }} + + + +
+ {% raw postBody %} +
+ +
+ +
+ + diff --git a/templates/Home.html b/templates/Home.html index 0a230b8..c9fedc8 100644 --- a/templates/Home.html +++ b/templates/Home.html @@ -4,10 +4,12 @@ -

Simple Blog

-

The owner hasn't set up their templates/Home.html template yet.

- {% for post in allPosts %} - {{post}}
- {% end %} + {% raw homeBody %} + + diff --git a/webResources/styles.css b/webResources/styles.css index ff8b8b4..25201b9 100644 --- a/webResources/styles.css +++ b/webResources/styles.css @@ -1,18 +1,35 @@ +html { + margin: 15 15 15 15; + background-color: #333333; +} + body { + /* Center body */ margin: 0 auto; - width: 80%; - height: 100%; - background-color: #333333; - max-width: 800px; + /* Make sure lines don't get too long */ + max-width: 700px; } p, +blockquote, h1, h2, h3, a, -li { +li, +tr, +td, +th { color: #cccccc; + font-family: Arial; +} + +/* Font sizes for consistently sized text */ +p, +blockquote, +a, +li { + font-size: medium; } label { @@ -20,14 +37,6 @@ label { color: #cccccc; } -li { - margin-top: 0px; - margin-bottom: 0px; - margin-left: 20px; - font-size: small; - color: #aaaaaa; -} - img { width: 100%; height: auto;