I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 66dca619 authored by str4d's avatar str4d
Browse files

Moved site_url macro into context processor so could use hasattr(g, 'lang') to fix a bug

parent 487e9ae9
No related branches found
No related tags found
No related merge requests found
...@@ -178,6 +178,16 @@ def restructuredtext(value): ...@@ -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(): ...@@ -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)
......
{%- 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>
......
{%- 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) }}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment