diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..a787015 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Flask", + "type": "debugpy", + "request": "launch", + "cwd": "${workspaceFolder}/src", + "module": "flask", + "env": { + "FLASK_APP": "app.py", + "FLASK_DEBUG": "1", + + }, + "args": [ + "run", + "--no-debugger", + "--no-reload" + ], + "jinja": true + } + ] +} \ No newline at end of file diff --git a/src/app.py b/src/app.py index 456af98..f97d750 100644 --- a/src/app.py +++ b/src/app.py @@ -2,11 +2,14 @@ import flask from flask_minify import Minify import json from tasks import TaskHandler +import werkzeug.exceptions as HTTPerror proj = json.load(open("./static/json/projects.json", "r")) books = json.load(open("./static/json/books.json", "r")) +skillList = json.load(open("./static/json/skills.json", "r")) timeline = json.load(open("./static/json/timeline.json", "r")) pages = json.load(open("./static/json/pages.json", "r")) +pages['about']['skillList'] = skillList pages['about']['timeline'] = timeline pages['projects']['projects'] = proj pages['home']['books'] = books @@ -20,14 +23,35 @@ tasks = TaskHandler() @app.route('/api/goto/') def goto(location='home'): pagevars = pages[location] - return [pagevars, flask.render_template(pagevars["template"], var=pagevars)] + page = None + try: + page = flask.render_template(pagevars["template"], var=pagevars) + except Exception as e: + e = HTTPerror.InternalServerError(None, e) + page = page404(e) + return [pagevars, page] # I am literally insane # There was no reason for me to do this # it saved some lines of code I guess # infinite flaskless flask here we comes + +def funcGen(pagename, pages): + def dynamicRule(): + try: + return flask.render_template('header.html', var=pages[pagename]) + except Exception: + e = HTTPerror.InternalServerError() + return page404(e) + return dynamicRule + for i in pages: - exec(f"@app.route(pages['{i}']['canonical'])\ndef {i}(): return flask.render_template('header.html', var=pages['{i}'])") + func = funcGen(i, pages) + app.add_url_rule(pages[i]['canonical'], i, func) + + +# for i in pages: +# exec(f"@app.route(pages['{i}']['canonical'])\ndef {i}(): return flask.render_template('header.html', var=pages['{i}'])") @app.route("/resume") @@ -85,4 +109,4 @@ if __name__ == "__main__": # sass.compile(dirname=("static/scss", "static/css"), output_style="compressed") app.run() else: - Minify(app=app, html=True, js=True, cssless=True) \ No newline at end of file + Minify(app=app, html=True, js=True, cssless=True)