Add logic to hide translate button if content is too long
This commit is contained in:
parent
4f0724eaa8
commit
749940abc6
3 changed files with 35 additions and 7 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
; Breadcrumbs
|
; Breadcrumbs
|
||||||
home = Home
|
home = Home
|
||||||
edit_on_github = Edit on GitHub
|
edit_on_github = Edit on GitHub
|
||||||
|
create_on_github = Translate on GitHub
|
||||||
|
|
||||||
; Footer
|
; Footer
|
||||||
sitemap = Sitemap
|
sitemap = Sitemap
|
||||||
|
|
@ -118,6 +119,7 @@ incomplete_space_before_link = false
|
||||||
; Breadcrumbs
|
; Breadcrumbs
|
||||||
home = Inicio
|
home = Inicio
|
||||||
edit_on_github = Editar en GitHub
|
edit_on_github = Editar en GitHub
|
||||||
|
create_on_github = Traducir en GitHub
|
||||||
|
|
||||||
; Footer
|
; Footer
|
||||||
sitemap = Mapa del Sitio
|
sitemap = Mapa del Sitio
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""This is a custom local plugin to ad extra functionality to pybee site."""
|
"""This is a custom local plugin to ad extra functionality to pybee site."""
|
||||||
|
# Standrd library imports
|
||||||
|
import urllib
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
from lektor.pluginsystem import Plugin
|
from lektor.pluginsystem import Plugin
|
||||||
from lektor.db import Record
|
from lektor.db import Record
|
||||||
|
from markupsafe import Markup
|
||||||
|
|
||||||
|
|
||||||
class PyBeePlugin(Plugin):
|
class PyBeePlugin(Plugin):
|
||||||
|
|
@ -28,6 +31,21 @@ class PyBeePlugin(Plugin):
|
||||||
|
|
||||||
return alt_available
|
return alt_available
|
||||||
|
|
||||||
|
def urlencode_limit(string, limit=6000):
|
||||||
|
"""Encodes url for uri but if over limit returns None"""
|
||||||
|
if type(string) == 'Markup':
|
||||||
|
string = string.unescape()
|
||||||
|
|
||||||
|
if len(string) <= limit:
|
||||||
|
string = string.encode('utf8')
|
||||||
|
string = urllib.quote_plus(string)
|
||||||
|
string = Markup(string)
|
||||||
|
else:
|
||||||
|
string = None
|
||||||
|
|
||||||
|
return string
|
||||||
|
|
||||||
self.env.jinja_env.globals.update(
|
self.env.jinja_env.globals.update(
|
||||||
is_alt_content_available=is_alt_content_available
|
is_alt_content_available=is_alt_content_available
|
||||||
)
|
)
|
||||||
|
self.env.jinja_env.globals.update(urlencode_limit=urlencode_limit)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
{% set t_sitemap = transbag('translate', this.alt, 'sitemap') %}
|
{% set t_sitemap = transbag('translate', this.alt, 'sitemap') %}
|
||||||
{% set t_welcome = transbag('translate', this.alt, 'welcome') %}
|
{% set t_welcome = transbag('translate', this.alt, 'welcome') %}
|
||||||
{% set t_edit_on_github = transbag('translate', this.alt, 'edit_on_github') %}
|
{% set t_edit_on_github = transbag('translate', this.alt, 'edit_on_github') %}
|
||||||
|
{% set t_create_on_github = transbag('translate', this.alt, 'create_on_github') %}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
@ -84,21 +85,28 @@ ga('send', 'pageview');
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{# This method is provided by a custom plugin found in /packages/lektor_pybee_plugin/ #}
|
|
||||||
{% if is_alt_content_available(this) %}
|
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
{% set extra_slash = '/' if this.path[-1] != '/' else '' %}
|
{% set extra_slash = '/' if this.path[-1] != '/' else '' %}
|
||||||
{% set alt_path = '+' + this.alt if this.alt and this.alt != 'en' else '' %}
|
{% set alt_path = '%2B' + this.alt if this.alt and this.alt != 'en' else '' %}
|
||||||
<li class="small">
|
<li class="small">
|
||||||
<a href="https://github.com/pybee/pybee.github.io/edit/lektor/content{{ this.path }}{{ extra_slash }}contents{{ alt_path }}.lr">
|
{# This method is provided by a custom plugin found in /packages/lektor_pybee_plugin/ #}
|
||||||
<i class="fa fa-github "></i><small>{{ t_edit_on_github }}</small>
|
{% if is_alt_content_available(this) %}
|
||||||
|
<a href="https://github.com/pybee/pybee.github.io/edit/lektor/content{{ this.path }}{{ extra_slash }}contents{{ alt_path }}.lr" target="_blank">
|
||||||
|
<i class="fa fa-github "></i><small> {{ t_edit_on_github }}</small>
|
||||||
</a>
|
</a>
|
||||||
|
{% else %}
|
||||||
|
{# This method is provided by a custom plugin found in /packages/lektor_pybee_plugin/ #}
|
||||||
|
{% set content_value = urlencode_limit(site.get(this.path).contents.as_text(), limit=5000) %}
|
||||||
|
{% if content_value and '@' not in this.path %}
|
||||||
|
<a href="https://github.com/pybee/pybee.github.io/new/lektor/content{{ this.path }}/contents{{ alt_path }}.lr?filename=contents{{ alt_path }}.lr&value={{ content_value }}" target="_blank">
|
||||||
|
<i class="fa fa-github "></i><small> {{ t_create_on_github }}</small>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{% block preamble %}{% endblock %}
|
{% block preamble %}{% endblock %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue