forked from I2P_Developers/i2p.www
Get I2P/clearnet url conversion working
For reference: a context processor was used to add the function in because this needs to be evaluated on every request, but the output from a template filter of a hard-coded string gets cached.
This commit is contained in:
@@ -106,14 +106,19 @@ def restructuredtext(value):
|
|||||||
parts = publish_parts(source=value, writer_name="html")
|
parts = publish_parts(source=value, writer_name="html")
|
||||||
return parts['html_body']
|
return parts['html_body']
|
||||||
|
|
||||||
# Convert an I2P url to an equivalent clearnet one
|
|
||||||
i2ptoclear = {
|
####################
|
||||||
|
# Context processors
|
||||||
|
|
||||||
|
@app.context_processor
|
||||||
|
def utility_processor():
|
||||||
|
# Convert an I2P url to an equivalent clearnet one
|
||||||
|
i2ptoclear = {
|
||||||
'www.i2p2.i2p': 'www.i2p2.de',
|
'www.i2p2.i2p': 'www.i2p2.de',
|
||||||
'forum.i2p': 'forum.i2p2.de',
|
'forum.i2p': 'forum.i2p2.de',
|
||||||
'trac.i2p2.i2p': 'trac.i2p2.de',
|
'trac.i2p2.i2p': 'trac.i2p2.de',
|
||||||
}
|
}
|
||||||
@app.template_filter('i2pconv')
|
def convert_url_to_clearnet(value):
|
||||||
def convert_url_to_clearnet(value):
|
|
||||||
if not value.endswith('.i2p'):
|
if not value.endswith('.i2p'):
|
||||||
# The url being passed in isn't an I2P url, so just return it
|
# The url being passed in isn't an I2P url, so just return it
|
||||||
return value
|
return value
|
||||||
@@ -127,6 +132,7 @@ def convert_url_to_clearnet(value):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
# The I2P site has no known clearnet address, so use an inproxy
|
# The I2P site has no known clearnet address, so use an inproxy
|
||||||
return value + '.to'
|
return value + '.to'
|
||||||
|
return dict(i2pconv=convert_url_to_clearnet)
|
||||||
|
|
||||||
|
|
||||||
################
|
################
|
||||||
|
@@ -60,8 +60,8 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li><a href="{{ site_url('support/faq') }}"><span>{{ _('FAQ') }}</span></a></li>
|
<li><a href="{{ site_url('support/faq') }}"><span>{{ _('FAQ') }}</span></a></li>
|
||||||
<li><a href="{{ site_url('support/contact') }}"><span>{{ _('Contact us') }}</span></a></li>
|
<li><a href="{{ site_url('support/contact') }}"><span>{{ _('Contact us') }}</span></a></li>
|
||||||
<li><a href="http://forum.i2p2.de/"><span>{{ _('Forums') }}</span></a></li>
|
<li><a href="http://{{ i2pconv('forum.i2p') }}/"><span>{{ _('Forums') }}</span></a></li>
|
||||||
<li><a href="http://trac.i2p2.i2p/"><span>Trac</span></a></li>
|
<li><a href="http://{{ i2pconv('trac.i2p2.i2p') }}/"><span>Trac</span></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li class="has-sub"><a href="#"><span>{{ _('Develop') }}</span></a>
|
<li class="has-sub"><a href="#"><span>{{ _('Develop') }}</span></a>
|
||||||
|
Reference in New Issue
Block a user