Use the configured pages from config.json
[wiki] / app.py
diff --git a/app.py b/app.py
index b87aa3a..8e1464a 100644 (file)
--- a/app.py
+++ b/app.py
@@ -1,6 +1,12 @@
+import json
+import pathlib
+
 import commonmark
 import flask
 
+with open(pathlib.Path(__file__).parent / 'config.json') as f:
+    CONFIGURATION = json.loads(f.read())
+
 app = flask.Flask(__name__)
 
 @app.route('/')
@@ -10,16 +16,16 @@ def index():
 @app.route('/p/<name>')
 def page(name):
     for ch in name:
-        if not ch in 'abcdefghijklmnopqrstuvwxyz_0123456789':
+        if not ch in 'abcdefghijklmnopqrstuvwxyz-0123456789':
             flask.abort(404)
 
     try:
-        with open('pages/{}.md'.format(name), 'r') as f:
+        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()
+    title = name.replace('-', ' ').title()
 
     return flask.render_template('page.html', content=content, title=title)