Browse Source

Add 404 page, change pdf and img get

JoostSijm 6 years ago
parent
commit
ce39943f15
4 changed files with 37 additions and 22 deletions
  1. 15 21
      app/flaskr.py
  2. 15 0
      app/static/404.html
  3. 1 1
      app/static/index.html
  4. 6 0
      app/static/style.css

+ 15 - 21
app/flaskr.py

@@ -19,29 +19,17 @@ def index():
     return send_from_directory('static', 'index.html')
 
 
-@app.route("/tutorial")
-@app.route("/tutorial/book")
-def tutorial_book():
-    """Display book"""
-    return send_from_directory('static', 'tutorial/book.pdf')
+@app.route("/tutorial", defaults={"document": "book"})
+@app.route("/tutorial/<document>.pdf")
+def tutorial_document(document):
+    """Display tutorial document"""
+    return send_from_directory('static', 'tutorial/%s.pdf' % document)
 
 
-@app.route("/tutorial/article")
-def tutorial_article():
-    """Display book"""
-    return send_from_directory('static', 'tutorial/article.pdf')
-
-
-@app.route("/tutorial/dist")
-def tutorial_dist():
-    """Display book"""
-    return send_from_directory('static', 'tutorial/dist.pdf')
-
-
-@app.route("/tutorial.png")
-def tutorial_dist_png():
-    """Display book"""
-    return send_from_directory('static', 'tutorial/dist.png')
+@app.route("/tutorial/<image>.png")
+def tutorial_image(image):
+    """Display tutorial image"""
+    return send_from_directory('static', 'tutorial/%s.png' % image)
 
 
 @app.route('/typeset', methods=['GET', 'POST'])
@@ -64,3 +52,9 @@ def deploy():
     subprocess.check_output(['pipenv', 'sync'])
     subprocess.check_output(['touch', 'flask.wsgi'])
     return jsonify(True)
+
+
+@app.errorhandler(404)
+def page_not_found(e):
+    """Return 404 page"""
+    return send_from_directory('static', '404.html'), 404

+ 15 - 0
app/static/404.html

@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>404 - Rival Regions Tutorial</title>
+    <link href="static/style.css" rel="stylesheet">
+    <link rel="shortcut icon" href="/static/favicon.ico">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+</head>
+<body>
+    <div class="page">
+        <h1><a href="/">Rival Regions Tutorial</a></h1>
+        <p>Pagina niet gevonden, terug naar <a href="/">home</a>.</p>
+    </div>
+</body>
+</html>

+ 1 - 1
app/static/index.html

@@ -8,7 +8,7 @@
 </head>
 <body>
     <div class="page">
-        <h1>Rival Regions Tutorial</h1>
+        <h1><a href="/">Rival Regions Tutorial</a></h1>
         <p>In deze tutorial zijn de belangrijkste aspecten van het spel uitgelegd.</p>
         <h2>Downloads</h2>
         <ul>

+ 6 - 0
app/static/style.css

@@ -32,6 +32,12 @@ h1
     font-size: 34pt;
 }
 
+h1 a
+{
+    text-decoration: none;
+    color: #000;
+}
+
 p,
 ul
 {