Prefix youtube URLs in video descriptions and channel about page

Closes #75

Signed-off-by: Jesús <heckyel@hyperbola.info>
This commit is contained in:
James Taylor
2021-08-08 20:29:42 -07:00
committed by Jesús
parent 2039972ab3
commit 6c6c469fbd
3 changed files with 26 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ from youtube import util
from .get_app_version import app_version
import flask
from flask import request
import jinja2
import settings
import traceback
import re
@@ -135,3 +136,17 @@ def get_css():
),
mimetype='text/css',
)
# This is okay because the flask urlize function puts the href as the first
# property
YOUTUBE_LINK_RE = re.compile(r'<a href="(' + util.YOUTUBE_URL_RE_STR + ')"')
old_urlize = jinja2.filters.urlize
def prefix_urlize(*args, **kwargs):
result = old_urlize(*args, **kwargs)
return YOUTUBE_LINK_RE.sub(r'<a href="/\1"', result)
jinja2.filters.urlize = prefix_urlize