forked from I2P_Developers/i2p.www
Moved site_url macro into context processor so could use hasattr(g, 'lang') to fix a bug
This commit is contained in:
@@ -178,6 +178,16 @@ def restructuredtext(value):
|
|||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def utility_processor():
|
def utility_processor():
|
||||||
|
# Shorthand for getting a site url
|
||||||
|
def get_site_url(path=None):
|
||||||
|
lang = 'en'
|
||||||
|
if hasattr(g, 'lang') and g.lang:
|
||||||
|
lang = g.lang
|
||||||
|
if path:
|
||||||
|
return url_for('site_show', lang=lang, page=path)
|
||||||
|
else:
|
||||||
|
return url_for('site_show', lang=lang)
|
||||||
|
|
||||||
# Provide the canonical link to the current page
|
# Provide the canonical link to the current page
|
||||||
def get_canonical_link():
|
def get_canonical_link():
|
||||||
protocol = request.url.split('//')[0]
|
protocol = request.url.split('//')[0]
|
||||||
@@ -220,6 +230,7 @@ def utility_processor():
|
|||||||
return dict(i2pconv=convert_url_to_clearnet,
|
return dict(i2pconv=convert_url_to_clearnet,
|
||||||
url_for_other_page=url_for_other_page,
|
url_for_other_page=url_for_other_page,
|
||||||
change_theme=change_theme,
|
change_theme=change_theme,
|
||||||
|
site_url=get_site_url,
|
||||||
canonical=get_canonical_link)
|
canonical=get_canonical_link)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
{%- from "global/macros" import site_url, change_lang, ver with context -%}
|
{%- from "global/macros" import change_lang, ver with context -%}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
{%- macro site_url(path=None) -%}
|
|
||||||
{%- if path -%}{{ url_for('site_show', lang=g.lang, page=path) }}
|
|
||||||
{%- else -%}{{ url_for('site_show', lang=g.lang) }}
|
|
||||||
{%- endif -%}
|
|
||||||
{%- endmacro -%}
|
|
||||||
|
|
||||||
{%- macro change_lang(lang) -%}
|
{%- macro change_lang(lang) -%}
|
||||||
{%- if request.endpoint == 'site_show' -%}{{ url_for('site_show', lang=lang, page=page) }}
|
{%- if request.endpoint == 'site_show' -%}{{ url_for('site_show', lang=lang, page=page) }}
|
||||||
{%- elif request.endpoint == 'blog_entry' -%}{{ url_for('blog_entry', lang=lang, slug=slug) }}
|
{%- elif request.endpoint == 'blog_entry' -%}{{ url_for('blog_entry', lang=lang, slug=slug) }}
|
||||||
|
Reference in New Issue
Block a user