diff options
-rwxr-xr-x | app.py | 6 | ||||
-rwxr-xr-x | database.py | 2 | ||||
-rwxr-xr-x | parser.py | 8 |
3 files changed, 11 insertions, 5 deletions
@@ -113,11 +113,15 @@ def get_thought(): thought_id = flask.request.args.get("id", type=int) with database.Database() as db: try: - category_name, title, dt, parsed, headers = parser.get_thought_from_id(db, thought_id) + category_name, title, dt, parsed, headers, redirect = parser.get_thought_from_id(db, thought_id) # print(headers) except TypeError: flask.abort(404) return + + if redirect is not None: + return flask.redirect(redirect, code = 301) + return flask.render_template( "thought.html.j2", **get_template_items(title, db), diff --git a/database.py b/database.py index 1a02cea..1877ab7 100755 --- a/database.py +++ b/database.py @@ -94,7 +94,7 @@ class Database: def get_thought(self, id_): with self.__connection.cursor() as cursor: cursor.execute(""" - SELECT categories.category_name, thoughts.title, thoughts.dt, thoughts.markdown_text + SELECT categories.category_name, thoughts.title, thoughts.dt, thoughts.markdown_text, thoughts.redirect FROM thoughts INNER JOIN categories ON thoughts.category_id = categories.category_id WHERE thought_id = %s;""", (id_, )) @@ -51,9 +51,9 @@ class EdawebRenderer(mistune.HTMLRenderer): ) def get_thought_from_id(db, id_): - category_name, title, dt, markdown = db.get_thought(id_) + category_name, title, dt, markdown, redirect = db.get_thought(id_) html, headers = parse_text(markdown) - return category_name, title, dt, html, headers + return category_name, title, dt, html, headers, redirect def parse_file(path): with open(path, "r") as f: @@ -67,6 +67,8 @@ def parse_text(unformatted): plugins = ["strikethrough", "table", "url", "task_lists", "def_list"] ) html = md(unformatted) + if html == "": + return "", "" return html, get_headers(html) @@ -180,7 +182,7 @@ def main(): elif verb == "export": with open(args["out"], "w") as f: - f.writelines(db.get_thought(args["id"])[-1]) + f.writelines(db.get_thought(args["id"])[-2]) print("Written to %s" % args["out"]) elif verb == "update": |