blog.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/blog/<int:year>/<int:month>/<int:day>') | |
def daypage(year, month, day): | |
y, m, d = str(year), str(month), str(day) | |
postlist = "content/posts" | |
results = {} | |
for post in os.listdir(postlist): | |
if fnmatch.fnmatch(file, '{0}-{1}-{2}:*.md'.format(y, m, d)): | |
year, month, day, slug = re.split("^([0-9]{4})-([0-9]{2})-([0-9]{2}):([a-z]*).md", post, flags=re.IGNORECASE)[1:5] | |
results[file].append("/blog/{0}/{1}/{2}/{3}".format(year, month, day, slug)) | |
if results: | |
return render_template('posts.html', links=results, title='blog - {0} {1}, {2}'.format(m, d, y)) | |
else: | |
abort(404) | |
@app.route('/blog/<int:year>/<int:month>/<int:day>/<slug>') | |
def postpage(year, month, day, slug): | |
page = "content/posts/{0}-{1}-{2}:{3}.md".format(year, month, day, slug) | |
if os.path.isfile(page): | |
with codecs.open(page, encoding='utf-8', mode='r+') as f: | |
content = f.read() | |
return render_template('post.html', page_html=content, title="blog - " + slug) | |
else: | |
abort(404) |