From 2459c580ce54e6a11c5cffd7d93e0c3678d57a68 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Wed, 25 Oct 2017 01:57:49 +0300 Subject: [PATCH] [www] Collective & Person meta image --- src/core/Teacher.js | 4 +++ src/render/persons.js | 67 ++++++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/core/Teacher.js b/src/core/Teacher.js index bcc09306..08883ba1 100644 --- a/src/core/Teacher.js +++ b/src/core/Teacher.js @@ -24,6 +24,7 @@ class Teacher { this.file = data.file this.edu = data.edu this.picture = data.picture + this.preview = data.preview this.diploma = data.diploma this.position = data.position this.name = data.name @@ -61,11 +62,14 @@ class Teacher { const processProfile = async profile => { const imageId = profile.picture + const previewId = profile.preview const picture = await Image.findById(imageId) + const preview = await Image.findById(previewId) return new Teacher({ ...profile, picture, + preview, }) } diff --git a/src/render/persons.js b/src/render/persons.js index c4cbdbdf..0a8d8afe 100644 --- a/src/render/persons.js +++ b/src/render/persons.js @@ -12,45 +12,48 @@ const Config = require('../core/Config') const {sortBy} = require('../utils/sort') const {prioritySort} = require('../lib/sort') +const metaImageTypesPriority = [ + ImageArtifactType.FACEBOOK, + ImageArtifactType.MEDIUM, + ImageArtifactType.BIG, + ImageArtifactType.ORIGIN, +] + function getMeta(teacher) { - return { - title: teacher.name, - description: teacher.name, + const meta = { + title: teacher.title, } + + if (teacher.preview) { + 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() { - return { +function getCollectiveMeta(picture) { + const meta = { title: 'Преподаватели', description: 'Преподаватели Шлиссельбургской ДХШ', } -} -// function getMeta(article) { -// 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 -// } + if (picture) { + const artifact = picture.findArtifact(metaImageTypesPriority) + meta.image = artifact.url + meta.imageWidth = artifact.width + meta.imageHeight = artifact.height + } + + return meta +} async function renderPerson(id) { const teacher = await Teacher.findById(id) @@ -106,7 +109,7 @@ async function renderCollective(path, order) { ) - return render(path, Component, getCollectiveMeta(), {menuPadding: true}) + return render(path, Component, getCollectiveMeta(collectiveImage), {menuPadding: true}) } exports.renderPerson = renderPerson