[www] Collective & Person meta image

This commit is contained in:
Roman Timashev committed 2017-10-25 01:57:49 +03:00
1 parent 66ca7719fa
commit 2459c580ce
2 files changed
+39 -32

No files matched your search

+4
View File
@@ -24,6 +24,7 @@ class Teacher {
this.file = data.file this.file = data.file
this.edu = data.edu this.edu = data.edu
this.picture = data.picture this.picture = data.picture
this.preview = data.preview
this.diploma = data.diploma this.diploma = data.diploma
this.position = data.position this.position = data.position
this.name = data.name this.name = data.name
@@ -61,11 +62,14 @@ class Teacher {
const processProfile = async profile => { const processProfile = async profile => {
const imageId = profile.picture const imageId = profile.picture
const previewId = profile.preview
const picture = await Image.findById(imageId) const picture = await Image.findById(imageId)
const preview = await Image.findById(previewId)
return new Teacher({ return new Teacher({
...profile, ...profile,
picture, picture,
preview,
}) })
} }
+35 -32
View File
@@ -12,45 +12,48 @@ const Config = require('../core/Config')
const {sortBy} = require('../utils/sort') const {sortBy} = require('../utils/sort')
const {prioritySort} = require('../lib/sort') const {prioritySort} = require('../lib/sort')
const metaImageTypesPriority = [
ImageArtifactType.FACEBOOK,
ImageArtifactType.MEDIUM,
ImageArtifactType.BIG,
ImageArtifactType.ORIGIN,
]
function getMeta(teacher) { function getMeta(teacher) {
return { const meta = {
title: teacher.name, title: teacher.title,
description: teacher.name,
}
} }
function getCollectiveMeta() { if (teacher.preview) {
return { try {
const artifact = teacher.preview.findArtifact(metaImageTypesPriority)
meta.image = artifact.url
meta.imageWidth = artifact.width
meta.imageHeight = artifact.height
} catch (error) {
meta.image = 'https://art.shlisselburg.org/entrance.jpg'
meta.imageWidth = 1200
meta.imageHeight = 630
}
}
return meta
}
function getCollectiveMeta(picture) {
const meta = {
title: 'Преподаватели', title: 'Преподаватели',
description: 'Преподаватели Шлиссельбургской ДХШ', description: 'Преподаватели Шлиссельбургской ДХШ',
} }
if (picture) {
const artifact = picture.findArtifact(metaImageTypesPriority)
meta.image = artifact.url
meta.imageWidth = artifact.width
meta.imageHeight = artifact.height
} }
// function getMeta(article) { return meta
// const types = [ }
// ImageArtifactType.FACEBOOK,
// ImageArtifactType.MEDIUM,
// ImageArtifactType.BIG,
// ImageArtifactType.ORIGIN,
// ]
// const meta = {
// title: article.title,
// }
//
// if (article.preview) {
// try {
// const artifact = article.preview.findArtifact(types)
// meta.image = artifact.url
// meta.imageWidth = artifact.width
// meta.imageHeight = artifact.height
// } catch (error) {
// meta.image = 'https://art.shlisselburg.org/entrance.jpg'
// meta.imageWidth = 1200
// meta.imageHeight = 630
// }
// }
// return meta
// }
async function renderPerson(id) { async function renderPerson(id) {
const teacher = await Teacher.findById(id) const teacher = await Teacher.findById(id)
@@ -106,7 +109,7 @@ async function renderCollective(path, order) {
</div> </div>
) )
return render(path, Component, getCollectiveMeta(), {menuPadding: true}) return render(path, Component, getCollectiveMeta(collectiveImage), {menuPadding: true})
} }
exports.renderPerson = renderPerson exports.renderPerson = renderPerson