diff options
author | Alexandre Flament <alex@al-f.net> | 2022-03-13 22:15:27 +0100 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2022-03-13 22:22:02 +0100 |
commit | 1157462ff9fc08504297e259356ccbefb339965f (patch) | |
tree | b87c6f75cc657e1929fe32afa2b8fbc9f905c65d /searxng_extra/docs_prebuild | |
parent | 59100e852573cbc01b602b1637b0d4a02a863a9d (diff) | |
download | searxng-1157462ff9fc08504297e259356ccbefb339965f.tar.gz searxng-1157462ff9fc08504297e259356ccbefb339965f.zip |
Various change on PR 930
Diffstat (limited to 'searxng_extra/docs_prebuild')
-rwxr-xr-x | searxng_extra/docs_prebuild | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/searxng_extra/docs_prebuild b/searxng_extra/docs_prebuild index 73c9c99b1..879007f64 100755 --- a/searxng_extra/docs_prebuild +++ b/searxng_extra/docs_prebuild @@ -8,24 +8,26 @@ import sys import os.path import time +from contextlib import contextmanager from searx import settings, get_setting from searx.infopage import InfoPageSet, InfoPage + _doc_user = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'docs', 'user')) -def main(): - DOC = None +def main(): base_url = get_setting('server.base_url', None) - if base_url: - DOC = _render_all_with_flask_ctx(base_url) + infopageset_ctx = _instance_infosetset_ctx(base_url) else: - DOC = _render_all() - for pagename, page in DOC.all_pages('en'): - fname = os.path.join(_doc_user, os.path.basename(page.fname)) - with open(fname, 'w') as f: - f.write(page.content) + infopageset_ctx = _offline_infosetset_ctx() + + with infopageset_ctx as infopageset: + for _, page in infopageset.all_pages('en'): + fname = os.path.join(_doc_user, os.path.basename(page.fname)) + with open(fname, 'w') as f: + f.write(page.content) class OfflinePage(InfoPage): @@ -41,21 +43,17 @@ class OfflinePage(InfoPage): return ctx -def _render_all(): - DOC = InfoPageSet(OfflinePage) - for pagename, page in DOC.all_pages('en'): - page.render() - return DOC - - -def _render_all_with_flask_ctx(base_url): +@contextmanager +def _offline_infosetset_ctx(): + yield InfoPageSet(OfflinePage) - DOC = InfoPageSet(InfoPage, base_url) +@contextmanager +def _instance_infosetset_ctx(base_url): # The url_for functions in the jinja templates need all routes to be # registered in the Flask app. - settings['server']['secret_key'] = "x" + settings['server']['secret_key'] = '' from searx.webapp import app # Specify base_url so that url_for() works for base_urls. If base_url is @@ -63,8 +61,7 @@ def _render_all_with_flask_ctx(base_url): # generics (see flaskfix.py). with app.test_request_context(base_url=base_url): - for pagename, page in DOC.all_pages('en'): - page.render() + yield InfoPageSet() # The searx.webapp import from above fires some HTTP requests, thats # why we get a RuntimeError:: |