From a60590f482c176d7dd4eba83505be73663326924 Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: May 20 2019 20:14:36 +0000 Subject: Generate index.html.lang_code files when freezing, to go back to the old way of doing things Signed-off-by: Rick Elrod --- diff --git a/sites/getfedora.org/main.py b/sites/getfedora.org/main.py index 40c0494..cdf47d4 100644 --- a/sites/getfedora.org/main.py +++ b/sites/getfedora.org/main.py @@ -82,6 +82,12 @@ FEDORA_LANGUAGE_DEFAULT = 'en' # Only include translations which actually have a translations file FEDORA_LANGUAGES = {k: v for k, v in FEDORA_LANGUAGES_FULL.items() if k in os.listdir('translations') or k == FEDORA_LANGUAGE_DEFAULT} +# Set this early so we can base routing logic on it. +if __name__ == '__main__': + freezing = True +else: + freezing = False + app = Flask(__name__, static_folder='../static/', static_url_path='/static') app.config['TEMPLATES_AUTO_RELOAD'] = True @@ -161,35 +167,39 @@ def get_locale(): return g.get('current_lang', app.config['BABEL_DEFAULT_LOCALE']) # This is a more manual attempt at still having some automation. +freeze_indexes = set() def export_route(name, path, template=None): + global freeze_indexes + freeze_indexes.add(name) def r(): - return render_template(template or path.strip('/').replace('', '') + '/index.html') + return render_template(template or path.strip('/') + '/index.html') r.__name__ = name - app.route(path)(r) + if freezing: + app.route(path + 'index.html.')(r) + else: + app.route('/' + path)(r) return r -# This will freeze, sadly, but we probably shouldn't use it in production. -# We want Apache or whatever in production to just always redirect to -# // for us. But for now it makes it easier to test things using the -# flask reload server. -@app.route('/') -def index_redirect(): - return redirect('/' + app.config['BABEL_DEFAULT_LOCALE'] + '/', code=302) - -export_route('index', '//') - -export_route('workstation', '//workstation/') -export_route('workstation_download', '//workstation/download/') -export_route('server', '//server/') -export_route('server_download', '//server/download/') -export_route('coreos', '//coreos/') -export_route('coreos_download', '//coreos/download/') -export_route('silverblue', '//silverblue/') -export_route('silverblue_download', '//silverblue/download/') -export_route('iot', '//iot/') -export_route('iot_download', '//iot/download/') -export_route('security', '//security/') -export_route('sponsors', '//sponsors/') +if not freezing: + @app.route('/') + def index_redirect(): + return redirect('/' + app.config['BABEL_DEFAULT_LOCALE'] + '/', code=302) + +export_route('index', '/') + +# export_route(identifier +export_route('workstation', '/workstation/') +export_route('workstation_download', '/workstation/download/') +export_route('server', '/server/') +export_route('server_download', '/server/download/') +export_route('coreos', '/coreos/') +export_route('coreos_download', '/coreos/download/') +export_route('silverblue', '/silverblue/') +export_route('silverblue_download', '/silverblue/download/') +export_route('iot', '/iot/') +export_route('iot_download', '/iot/download/') +export_route('security', '/security/') +export_route('sponsors', '/sponsors/') # This is manually updated for now by calling: # python scripts/releases-json.py > static/releases.json @@ -217,6 +227,8 @@ def index_html_var_for_apache(): def index(): for lang in FEDORA_LANGUAGES: yield {'lang_code': lang} + for name in freeze_indexes: + yield name, {'lang_code': lang} if __name__ == '__main__': # Minification is good for production, but not for debugging.