[www] Gallery page updated
This commit is contained in:
1 parent
6fa8564cc8
commit
597e87896e
6 files changed
+75
-38
No files matched your search
+18
-5
@@ -4,6 +4,7 @@ const ImageArtifactType = require('./ImageArtifactType')
|
|||||||
const {find, findOne} = require('../lib/store')
|
const {find, findOne} = require('../lib/store')
|
||||||
|
|
||||||
const previewTypes = [
|
const previewTypes = [
|
||||||
|
ImageArtifactType.SMALL,
|
||||||
ImageArtifactType.MEDIUM,
|
ImageArtifactType.MEDIUM,
|
||||||
ImageArtifactType.BIG,
|
ImageArtifactType.BIG,
|
||||||
ImageArtifactType.ORIGIN,
|
ImageArtifactType.ORIGIN,
|
||||||
@@ -31,14 +32,26 @@ const previewFromImage = (imgs = []) => imgs.length
|
|||||||
: null
|
: null
|
||||||
|
|
||||||
const processAlbum = async album => {
|
const processAlbum = async album => {
|
||||||
|
let preview = {}
|
||||||
|
// {
|
||||||
|
// data: [
|
||||||
|
// {
|
||||||
|
// url: null,
|
||||||
|
// width: 0,
|
||||||
|
// height: 0,
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
|
||||||
const previewImageId = album.preview ? album.preview : previewFromImage(album.images)
|
const previewImageId = album.preview ? album.preview : previewFromImage(album.images)
|
||||||
let preview
|
|
||||||
if (previewImageId) {
|
if (previewImageId) {
|
||||||
const image = await Image.findById(previewImageId)
|
const image = await Image.findById(previewImageId)
|
||||||
preview = image.findArtifact(previewTypes)
|
if (image) {
|
||||||
} else {
|
// const imageArtifacts = image.findArtifact(previewTypes)
|
||||||
preview = {
|
// if (imageArtifacts) {
|
||||||
url: null,
|
// preview = imageArtifacts
|
||||||
|
// }
|
||||||
|
preview = image.getPicture(ImageArtifactType.SMALL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const Data = require('./Data')
|
const Data = require('./Data')
|
||||||
|
const ImageArtifactType = require('./ImageArtifactType')
|
||||||
const {findOne} = require('../lib/store')
|
const {findOne} = require('../lib/store')
|
||||||
const {mapOf} = require('../lib/common')
|
const {mapOf} = require('../lib/common')
|
||||||
|
|
||||||
@@ -32,6 +33,26 @@ class Image {
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPicture(size) {
|
||||||
|
const retinaSize = ImageArtifactType.retina(size)
|
||||||
|
|
||||||
|
const a = this.getArtifact(size)
|
||||||
|
const a2 = this.getArtifact(retinaSize)
|
||||||
|
const pic = {
|
||||||
|
src: a.url,
|
||||||
|
width: a.width,
|
||||||
|
height: a.height,
|
||||||
|
set: [
|
||||||
|
{
|
||||||
|
url: a2.url,
|
||||||
|
density: ImageArtifactType.RETINA_DENSITY,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
console.log(pic)
|
||||||
|
return pic
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ImageArtifact {
|
class ImageArtifact {
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
class ImageArtifact {
|
class ImageArtifactType {
|
||||||
constructor() {
|
constructor() {
|
||||||
throw new Error('Cannot create instance of ImageArtifact')
|
throw new Error('Cannot create instance of ImageArtifactType')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageArtifact.MEDIUM = 'medium'
|
ImageArtifactType.SMALL = 'small'
|
||||||
ImageArtifact.BIG = 'big'
|
ImageArtifactType.MEDIUM = 'medium'
|
||||||
ImageArtifact.ORIGIN = 'origin'
|
ImageArtifactType.BIG = 'big'
|
||||||
|
ImageArtifactType.ORIGIN = 'origin'
|
||||||
|
|
||||||
module.exports = ImageArtifact
|
ImageArtifactType.RETINA_DENSITY = 2
|
||||||
|
ImageArtifactType.retina = type => `${type}@${ImageArtifactType.RETINA_DENSITY}`
|
||||||
|
|
||||||
|
module.exports = ImageArtifactType
|
||||||
+22
-7
@@ -6,10 +6,6 @@ const {splitBy} = require('../lib/array')
|
|||||||
const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash
|
const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash
|
||||||
const {get} = require('koa-route')
|
const {get} = require('koa-route')
|
||||||
|
|
||||||
const previewUrl = preview => preview
|
|
||||||
? preview.url
|
|
||||||
: null
|
|
||||||
|
|
||||||
function getMeta() {
|
function getMeta() {
|
||||||
return {
|
return {
|
||||||
title: 'Галерея',
|
title: 'Галерея',
|
||||||
@@ -17,11 +13,30 @@ function getMeta() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// {data.set.map((s, i) => (
|
||||||
|
// <source
|
||||||
|
// key={i}
|
||||||
|
// src={i}
|
||||||
|
// />
|
||||||
|
// ))}
|
||||||
|
// const m = 0.5
|
||||||
|
const m = 1
|
||||||
|
const AlbumImage = ({data, alt}) => (
|
||||||
|
<picture>
|
||||||
|
<img
|
||||||
|
alt={alt}
|
||||||
|
src={data.src}
|
||||||
|
width={data.width * m}
|
||||||
|
height={data.height * m}
|
||||||
|
srcSet={data.set.map(({url, density}) => `${url} ${density}x`)}
|
||||||
|
/>
|
||||||
|
</picture>
|
||||||
|
)
|
||||||
|
|
||||||
const GItem = ({album}) => (
|
const GItem = ({album}) => (
|
||||||
<div className="gallery-item">
|
<div className="gallery-item">
|
||||||
<a href={album.url}>
|
<a className="invisible" href={album.url}>
|
||||||
<h2>{album.title}</h2>
|
<AlbumImage data={album.preview} alt={album.title}/>
|
||||||
<img src={previewUrl(album.preview)} alt={album.title}/>
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
position: relative;
|
position: relative;
|
||||||
justify-content: center;
|
justify-content: flex-start;
|
||||||
align-items:flex-start;
|
align-items:center;
|
||||||
|
|
||||||
margin: 0 0 $double-margin;
|
margin: 0 0 $double-margin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,27 +8,11 @@ $percentage: 25%;
|
|||||||
box-sizing: padding-box;
|
box-sizing: padding-box;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
width: 13em;
|
|
||||||
height: 15em;
|
|
||||||
margin: 0 $single-margin $double-margin;
|
margin: 0 $single-margin $double-margin;
|
||||||
overflow: hidden;
|
|
||||||
|
|
||||||
h3 {
|
a.invisible {
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: $dark-color;
|
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
|
text-decoration: none;
|
||||||
&:hover {
|
|
||||||
border-bottom: none;
|
|
||||||
color: $blue-color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
|
||||||
width: 100%;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user