Merge pull request #1273 from thelounge/xpaw/no-preview

Do not display preview if there is nothing to preview
This commit is contained in:
Jérémie Astori 2017-06-26 02:36:46 -04:00 committed by GitHub
commit f516d21f7b

View File

@ -56,11 +56,11 @@ function parse(msg, url, res, client) {
toggle.head = toggle.head =
$("meta[property=\"og:title\"]").attr("content") $("meta[property=\"og:title\"]").attr("content")
|| $("title").text() || $("title").text()
|| "No title found."; || "";
toggle.body = toggle.body =
$("meta[property=\"og:description\"]").attr("content") $("meta[property=\"og:description\"]").attr("content")
|| $("meta[name=\"description\"]").attr("content") || $("meta[name=\"description\"]").attr("content")
|| "No description found."; || "";
toggle.thumb = toggle.thumb =
$("meta[property=\"og:image\"]").attr("content") $("meta[property=\"og:image\"]").attr("content")
|| $("meta[name=\"twitter:image:src\"]").attr("content") || $("meta[name=\"twitter:image:src\"]").attr("content")
@ -74,11 +74,13 @@ function parse(msg, url, res, client) {
// Verify that thumbnail pic exists and is under allowed size // Verify that thumbnail pic exists and is under allowed size
if (toggle.thumb.length) { if (toggle.thumb.length) {
fetch(escapeHeader(toggle.thumb), (resThumb) => { fetch(escapeHeader(toggle.thumb), (resThumb) => {
if (!(/^image\/.+/.test(resThumb.type)) || resThumb.size > (Helper.config.prefetchMaxImageSize * 1024)) { if (resThumb === null
|| !(/^image\/.+/.test(resThumb.type))
|| resThumb.size > (Helper.config.prefetchMaxImageSize * 1024)) {
toggle.thumb = ""; toggle.thumb = "";
} }
client.emit("toggle", toggle); emitToggle(client, toggle);
}); });
return; return;
@ -101,6 +103,20 @@ function parse(msg, url, res, client) {
return; return;
} }
emitToggle(client, toggle);
}
function emitToggle(client, toggle) {
// If there is no title but there is preview or description, set title
// otherwise bail out and show no preview
if (!toggle.head.length) {
if (toggle.thumb.length || toggle.body.length) {
toggle.head = "Untitled page";
} else {
return;
}
}
client.emit("toggle", toggle); client.emit("toggle", toggle);
} }