Skip to content

Instantly share code, notes, and snippets.

@meskarune
Created July 31, 2016 01:57
Show Gist options
  • Save meskarune/c139a7904ad308fa39bf8a6689a291db to your computer and use it in GitHub Desktop.
Save meskarune/c139a7904ad308fa39bf8a6689a291db to your computer and use it in GitHub Desktop.
@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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment