Make the emoji template configurable

This commit is contained in:
Thomas Sileo 2019-05-12 13:05:27 +02:00
parent 31d356ea49
commit 0f6fa36fbd
3 changed files with 11 additions and 6 deletions

7
app.py
View file

@ -69,6 +69,7 @@ from config import BASE_URL
from config import DB from config import DB
from config import DEBUG_MODE from config import DEBUG_MODE
from config import DOMAIN from config import DOMAIN
from config import EMOJI_TPL
from config import EMOJIS from config import EMOJIS
from config import HEADERS from config import HEADERS
from config import ICON_URL from config import ICON_URL
@ -88,8 +89,6 @@ from utils.key import get_secret_key
from utils.lookup import lookup from utils.lookup import lookup
from utils.media import Kind from utils.media import Kind
EMOJI = '<img src="https://cdn.jsdelivr.net/npm/twemoji@12.0.0/2/svg/{filename}.svg" alt="{raw}" class="emoji">'
p = PousseTaches( p = PousseTaches(
os.getenv("MICROBLOGPUB_POUSSETACHES_HOST", "http://localhost:7991"), os.getenv("MICROBLOGPUB_POUSSETACHES_HOST", "http://localhost:7991"),
os.getenv("MICROBLOGPUB_INTERNAL_HOST", "http://localhost:5000"), os.getenv("MICROBLOGPUB_INTERNAL_HOST", "http://localhost:5000"),
@ -243,7 +242,7 @@ def _get_file_url(url, size, kind):
@app.template_filter() @app.template_filter()
def emojify(text): def emojify(text):
return emoji_unicode.replace( return emoji_unicode.replace(
text, lambda e: EMOJI.format(filename=e.code_points, raw=e.unicode) text, lambda e: EMOJI_TPL.format(filename=e.code_points, raw=e.unicode)
) )
@ -314,7 +313,7 @@ def is_from_outbox(t):
def clean(html): def clean(html):
out = clean_html(html) out = clean_html(html)
return emoji_unicode.replace( return emoji_unicode.replace(
out, lambda e: EMOJI.format(filename=e.code_points, raw=e.unicode) out, lambda e: EMOJI_TPL.format(filename=e.code_points, raw=e.unicode)
) )

View file

@ -219,5 +219,11 @@ ME = {
"publicKey": KEY.to_dict(), "publicKey": KEY.to_dict(),
} }
# TODO(tsileo): read the config from the YAML if set
EMOJIS = "😺 😸 😹 😻 😼 😽 🙀 😿 😾" EMOJIS = "😺 😸 😹 😻 😼 😽 🙀 😿 😾"
if conf.get("emojis"):
EMOJIS = conf["emojis"]
# Emoji template for the FE
EMOJI_TPL = '<img src="https://cdn.jsdelivr.net/npm/twemoji@12.0.0/2/svg/{filename}.svg" alt="{raw}" class="emoji">'
if conf.get("emoji_tpl"):
EMOJI_TPL = conf["emoji_tpl"]

View file

@ -25,7 +25,7 @@
<p> <p>
{% for emoji in emojis %} {% for emoji in emojis %}
<span class="ji">{{ emoji }}</span> <span class="ji">{{ emoji | emojify | safe }}</span>
{% endfor %} {% endfor %}
</p> </p>