diff options
author | 2018-05-06 18:21:34 +0100 | |
---|---|---|
committer | 2018-05-06 18:21:34 +0100 | |
commit | efb902f3f293db4aac6e57b9f3a84143d84a90e9 (patch) | |
tree | 69fd91e690f1b8e150b839927c8bb312ebf81abc /gunicorn_config.py | |
parent | I linted that, I swear (diff) |
[Wiki] Misc improvements, plus a beta search feature
Diffstat (limited to 'gunicorn_config.py')
-rw-r--r-- | gunicorn_config.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/gunicorn_config.py b/gunicorn_config.py index 0e374fdd..c09bee6a 100644 --- a/gunicorn_config.py +++ b/gunicorn_config.py @@ -1,3 +1,10 @@ +import html +import re + +STRIP_REGEX = re.compile(r"<[^<]+?>") +WIKI_TABLE = "wiki" + + def when_ready(server=None): """ server hook that only runs when the gunicorn master process loads """ @@ -24,3 +31,11 @@ def when_ready(server=None): if initialized: tables = ", ".join([f"{table} ({count} items)" for table, count in initialized.items()]) output(f"Initialized the following tables: {tables}") + + output("Adding plain-text version of any wiki articles that don't have one...") + + for article in db.pluck(WIKI_TABLE, "html", "text", "slug"): + if "text" not in article: + article["text"] = html.unescape(STRIP_REGEX.sub("", article["html"]).strip()) + + db.insert(WIKI_TABLE, article, conflict="update") |