preview: dont render empty meta fields
ci/woodpecker/pr/woodpecker Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details

Metadata can contain empty fields or broken images. Improved
rendering of meta preview links with missing info, also added a
subtile transparent dark background color to preview images, as
some images contain white text on transparent background and are
invisible in light mode.
pull/39/head
OFF0 2 years ago
parent ff0ba4f6e6
commit 9df0f723f2
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

@ -142,6 +142,7 @@
} }
.preview-image { .preview-image {
background-color: rgba(72, 63, 63, 0.07);
margin-bottom: var(--gap); margin-bottom: var(--gap);
max-height: 30vh; max-height: 30vh;
object-fit: contain; object-fit: contain;

@ -187,14 +187,20 @@ const fetchNext = (href, id, relay) => {
}) })
.then(meta => { .then(meta => {
const container = document.getElementById(previewId); const container = document.getElementById(previewId);
container.append(elem('a', {href, rel: 'noopener noreferrer', target: '_blank'}, [ const content = [];
meta.images[0] && ( if (meta.images[0]) {
elem('img', {className: 'preview-image', loading: 'lazy', src: getNoxyUrl('data', meta.images[0], id, relay).href}) content.push(elem('img', {className: 'preview-image', loading: 'lazy', src: getNoxyUrl('data', meta.images[0], id, relay).href}));
), }
elem('h2', {className: 'preview-title'}, meta.title), if (meta.title) {
elem('p', {className: 'preview-descr'}, meta.descr), content.push(elem('h2', {className: 'preview-title'}, meta.title));
])); }
container.classList.add('preview-loaded'); if (meta.descr) {
content.push(elem('p', {className: 'preview-descr'}, meta.descr))
}
if (content.length) {
container.append(elem('a', {href, rel: 'noopener noreferrer', target: '_blank'}, content));
container.classList.add('preview-loaded');
}
}) })
.finally(() => { .finally(() => {
fetchPending = false; fetchPending = false;

Loading…
Cancel
Save