Do not display preview if there is nothing to preview

This commit is contained in:
Pavel Djundik 2017-06-26 09:27:51 +03:00
parent cfd71cab02
commit 77667e7a3f

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);
} }