Browse Source

Now fully functional blog

I made the Home handler generate a list of all blog posts, so it's
effectively a complete blog.

Not too bad for 2 hours of work!
master
Macoy Madson 3 years ago
parent
commit
3f7381b819
  1. 12
      ContentConverter.py
  2. 5
      SimpleBlogServer.py
  3. 4
      templates/BlogPost.html
  4. 11
      templates/Home.html

12
ContentConverter.py

@ -61,6 +61,7 @@ renderedDictionary = {}
def updateRenderedCache():
global renderedCache
global renderedDictionary
renderedCache = []
# Get all rendered files
for root, dirs, files in os.walk(renderedDirectory):
@ -73,6 +74,17 @@ def updateRenderedCache():
print("\t'{}' = '{}'".format(contentPath, renderedFile))
# No use for the value yet, we just want fast key lookups
renderedDictionary[contentPath] = renderedFile
"""
Interface
"""
def getAllPostsList():
allPosts = []
for key, value in renderedDictionary.items():
allPosts.append(key)
return allPosts
def getRenderedBody(contentPath):
body = None

5
SimpleBlogServer.py

@ -18,9 +18,8 @@ import ContentConverter
class HomeHandler(tornado.web.RequestHandler):
def get(self):
self.write('''<html><head><link rel="stylesheet" type="text/css" href="webResources/styles.css"></head>
<body><p>{}</p></body>
</html>'''.format("Hello, world!"))
allPosts = ContentConverter.getAllPostsList()
self.render("templates/Home.html", allPosts=allPosts)
class BlogHandler(tornado.web.RequestHandler):
def get(self, request):

4
templates/BlogPost.html

@ -1,9 +1,9 @@
<html>
<head>
<title>{{ title }}</title>
<link rel="stylesheet" type="text/css" href="webResources/styles.css">
<link rel="stylesheet" type="text/css" href="/webResources/styles.css">
</head>
<body>
{{ postBody }}
{% raw postBody %}
</body>
</html>

11
templates/Home.html

@ -0,0 +1,11 @@
<html>
<head>
<title>Home</title>
<link rel="stylesheet" type="text/css" href="/webResources/styles.css">
</head>
<body>
{% for post in allPosts %}
<a href="blog/{{post}}">{{post}}</a>
{% end %}
</body>
</html>
Loading…
Cancel
Save