diff options
| author | Yuval Adam <_@yuv.al> | 2017-08-07 09:17:36 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2017-08-07 09:17:36 +0300 |
| commit | dd0cce923a29aee84f7050b7e0c886c8d32a84a7 (patch) | |
| tree | 620c8c963ecfdbce277aa79388d5fd42fca6e518 /app.py | |
| parent | 14958653b9bf92f56316511e8080baeeaf409b97 (diff) | |
Add wiki content
Diffstat (limited to 'app.py')
| -rw-r--r-- | app.py | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -6,6 +6,7 @@ from os import listdir app = Flask(__name__) BLOG_CONTENT_DIR = 'content/blog' +WIKI_CONTENT_DIR = 'content/wiki' @app.route('/') def home(): @@ -33,3 +34,22 @@ def blog_post(y, m, d, title): title = h.split('title:')[0].strip() html = markdown.markdown(body, extensions=['markdown.extensions.extra', 'markdown.extensions.codehilite']) return render_template('post.html', title=title, html=html) + +def parse_page(page): + slug = page[:-3] + title = slug.replace('-', ' ') + return {'url': f'/wiki/{slug}/', 'title': title} + +@app.route('/wiki/') +def wiki(): + pages = sorted(listdir(WIKI_CONTENT_DIR), reverse=True) + pages = map(parse_page, pages) + return render_template('wiki.html', pages=pages) + +@app.route('/wiki/<slug>/') +def wiki_page(slug): + with open(f'{WIKI_CONTENT_DIR}/{slug}.md') as f: + text = f.read() + title = slug.replace('-', ' ') + html = markdown.markdown(text, extensions=['markdown.extensions.extra', 'markdown.extensions.codehilite']) + return render_template('wiki-page.html', title=title, html=html) |
