Added lazy-loading to release tile posters.

This commit is contained in:
ThePendulum 2020-05-07 02:10:28 +02:00
parent af9d8f7858
commit c410294022
6 changed files with 37 additions and 11 deletions

View File

@ -5,7 +5,10 @@
class="heading" class="heading"
><span class="range">{{ range }}</span> releases for '{{ context }}'</h3> ><span class="range">{{ range }}</span> releases for '{{ context }}'</h3>
<ul class="nolist tiles"> <ul
v-lazy-container="{ selector: '.thumbnail' }"
class="nolist tiles"
>
<li <li
v-for="(release, index) in releases" v-for="(release, index) in releases"
:key="`release-${release.id}`" :key="`release-${release.id}`"

View File

@ -69,7 +69,8 @@
> >
<img <img
v-if="release.poster" v-if="release.poster"
:src="sfw ? `/img/${release.poster.sfw.thumbnail}` : `/media/${release.poster.thumbnail}`" :data-src="sfw ? `/img/${release.poster.sfw.thumbnail}` : `/media/${release.poster.thumbnail}`"
:data-loading="sfw ? `/img/${release.poster.sfw.lazy}` : `/media/${release.poster.lazy}`"
:alt="release.title" :alt="release.title"
class="thumbnail" class="thumbnail"
> >
@ -81,7 +82,8 @@
<img <img
v-for="cover in release.covers" v-for="cover in release.covers"
:key="cover.id" :key="cover.id"
:src="`/${release.batch === 'dummy' ? 'img' : 'media'}/${cover.thumbnail}`" :data-src="`/media/${cover.thumbnail}`"
:data-loading="`/media/${cover.lazy}`"
:alt="release.title" :alt="release.title"
class="thumbnail cover" class="thumbnail cover"
> >

View File

@ -79,6 +79,7 @@ const releasePosterFragment = `
index index
path path
thumbnail thumbnail
lazy
comment comment
sfw: sfwMedia { sfw: sfwMedia {
id id
@ -96,6 +97,7 @@ const releaseCoversFragment = `
index index
path path
thumbnail thumbnail
lazy
comment comment
sfw: sfwMedia { sfw: sfwMedia {
id id

View File

@ -72,12 +72,14 @@ function initReleasesActions(store, _router) {
media { media {
id id
thumbnail thumbnail
lazy
} }
} }
covers: releasesCovers { covers: releasesCovers {
media { media {
id id
thumbnail thumbnail
lazy
} }
} }
} }

View File

@ -168,6 +168,8 @@ module.exports = {
path: './media', path: './media',
thumbnailSize: 320, // width for 16:9 will be exactly 576px thumbnailSize: 320, // width for 16:9 will be exactly 576px
thumbnailQuality: 100, thumbnailQuality: 100,
lazySize: 90,
lazyQuality: 90,
videoQuality: [480, 360, 320, 540, 720, 1080, 2160, 270, 240, 180], videoQuality: [480, 360, 320, 540, 720, 1080, 2160, 270, 240, 180],
limit: 25, // max number of photos per release limit: 25, // max number of photos per release
}, },

View File

@ -267,6 +267,9 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil
const thumbdir = path.join(media.role, 'thumbs', hashDir, hashSubDir); const thumbdir = path.join(media.role, 'thumbs', hashDir, hashSubDir);
const thumbpath = path.join(thumbdir, filename); const thumbpath = path.join(thumbdir, filename);
const lazydir = path.join(media.role, 'lazy', hashDir, hashSubDir);
const lazypath = path.join(lazydir, filename);
const image = sharp(media.file.path); const image = sharp(media.file.path);
const [info, stat] = await Promise.all([ const [info, stat] = await Promise.all([
@ -277,16 +280,26 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil
await Promise.all([ await Promise.all([
fsPromises.mkdir(path.join(config.media.path, filedir), { recursive: true }), fsPromises.mkdir(path.join(config.media.path, filedir), { recursive: true }),
fsPromises.mkdir(path.join(config.media.path, thumbdir), { recursive: true }), fsPromises.mkdir(path.join(config.media.path, thumbdir), { recursive: true }),
fsPromises.mkdir(path.join(config.media.path, lazydir), { recursive: true }),
]); ]);
// generate thumbnail // generate thumbnail and lazy
await sharp(media.file.path) await Promise.all([
.resize({ image
height: config.media.thumbnailSize, .resize({
withoutEnlargement: true, height: config.media.thumbnailSize,
}) withoutEnlargement: true,
.jpeg({ quality: config.media.thumbnailQuality }) })
.toFile(path.join(config.media.path, thumbpath)); .jpeg({ quality: config.media.thumbnailQuality })
.toFile(path.join(config.media.path, thumbpath)),
image
.resize({
height: config.media.lazySize,
withoutEnlargement: true,
})
.jpeg({ quality: config.media.lazyQuality })
.toFile(path.join(config.media.path, lazypath)),
]);
if (media.meta.subtype === 'jpeg') { if (media.meta.subtype === 'jpeg') {
// move temp file to permanent location // move temp file to permanent location
@ -310,6 +323,7 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil
file: { file: {
path: filepath, path: filepath,
thumbnail: thumbpath, thumbnail: thumbpath,
lazy: lazypath,
}, },
meta: { meta: {
...media.meta, ...media.meta,
@ -492,6 +506,7 @@ function curateMediaEntry(media, index) {
id: media.id, id: media.id,
path: media.file.path, path: media.file.path,
thumbnail: media.file.thumbnail, thumbnail: media.file.thumbnail,
lazy: media.file.lazy,
index, index,
mime: media.meta.mimetype, mime: media.meta.mimetype,
hash: media.meta.hash, hash: media.meta.hash,