replace yt links with piped url

This commit is contained in:
Bnyro 2022-09-12 17:50:35 +02:00
parent a82f8dffc6
commit 85b4153393

View file

@ -173,12 +173,17 @@ const mixin = {
}, },
urlify(string) { urlify(string) {
if (!string) return ""; if (!string) return "";
const baseUrl = window.location.origin;
const urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/g; const urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/g;
const emailRegex = /([\w-\\.]+@(?:[\w-]+\.)+[\w-]{2,4})/g; const emailRegex = /([\w-\\.]+@(?:[\w-]+\.)+[\w-]{2,4})/g;
return string return string
.replace(urlRegex, url => { .replace(urlRegex, url => {
if (url.endsWith("</a>")) return url; const targetUrl = url
return `<a href="${url}" target="_blank">${url}</a>`; .replace("https://youtu.be", `${baseUrl}/watch?v=`)
.replace("https://youtube.com", baseUrl)
.replace("https://www.youtube.com", baseUrl);
if (url.endsWith("</a>")) return targetUrl;
return `<a href="${targetUrl}" target="_blank">${url}</a>`;
}) })
.replace(emailRegex, email => { .replace(emailRegex, email => {
return `<a href="mailto:${email}">${email}</a>`; return `<a href="mailto:${email}">${email}</a>`;