X-Git-Url: https://code.kerkeslager.com/?p=wiki;a=blobdiff_plain;f=app.py;h=285c134223b0f780a1f8b0ded2a0debbddc2d88f;hp=8e1464aa683b47631dad94877df68d84d4a65bae;hb=HEAD;hpb=38c78c0b787bc5fe29f6b024d2d88bdabe3c3476 diff --git a/app.py b/app.py index 8e1464a..285c134 100644 --- a/app.py +++ b/app.py @@ -9,9 +9,18 @@ with open(pathlib.Path(__file__).parent / 'config.json') as f: app = flask.Flask(__name__) +def render_markdown_file(name, title): + try: + with open(pathlib.Path(CONFIGURATION['directory']) / '{}.md'.format(name), 'r') as f: + content = commonmark.commonmark(f.read()) + except FileNotFoundError as e: + flask.abort(404) + + return flask.render_template('page.html', content=content, title=title) + @app.route('/') def index(): - return 'Hello, world' + return render_markdown_file('_index', 'Home') @app.route('/p/') def page(name): @@ -19,14 +28,5 @@ def page(name): if not ch in 'abcdefghijklmnopqrstuvwxyz-0123456789': flask.abort(404) - try: - with open(pathlib.Path(CONFIGURATION['directory']) / '{}.md'.format(name), 'r') as f: - content = commonmark.commonmark(f.read()) - except FileNotFoundError as e: - flask.abort(404) - - title = name.replace('-', ' ').title() - - return flask.render_template('page.html', content=content, title=title) - + return render_markdown_file(name, name.replace('-', ' ').title())