[www] Collective/Person pages updated
This commit is contained in:
1 parent
b2191200da
commit
39ce95746f
14 files changed
+200
-123
No files matched your search
+7
-73
@@ -1,69 +1,15 @@
|
||||
const React = require('react')
|
||||
const Article = require('../components/Article')
|
||||
const TeacherProfile = require('../components/TeacherProfile')
|
||||
const Teacher = require('../core/Teacher')
|
||||
const ImageArtifactType = require('../core/ImageArtifactType')
|
||||
const {render} = require('../lib/render')
|
||||
const {prioritySort} = require('../lib/sort')
|
||||
const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash
|
||||
|
||||
const {renderPerson, renderCollective} = require('../render/persons')
|
||||
const {get} = require('koa-route')
|
||||
|
||||
function getCollectiveMeta() {
|
||||
return {
|
||||
title: 'Преподаватели',
|
||||
description: 'Преподаватели Шлиссельбургской ДХШ',
|
||||
}
|
||||
}
|
||||
|
||||
function getMeta(teacher) {
|
||||
return {
|
||||
title: teacher.name,
|
||||
description: teacher.name,
|
||||
}
|
||||
}
|
||||
|
||||
const pictureTypes = [
|
||||
ImageArtifactType.BIG,
|
||||
ImageArtifactType.MEDIUM,
|
||||
ImageArtifactType.ORIGIN,
|
||||
]
|
||||
|
||||
const profilePicture = profile => profile.picture.findArtifact(pictureTypes)
|
||||
|
||||
function getCollective(order) {
|
||||
const teachersSorted = prioritySort.bind(null, order, t => t.id)
|
||||
|
||||
return get('/collective', async ctx => {
|
||||
const path = getPathWithNoTrailingSlash(ctx.path)
|
||||
let teachers = await Teacher.find({})
|
||||
|
||||
if (teachers) {
|
||||
teachers = teachersSorted(teachers)
|
||||
|
||||
const Component = (
|
||||
<div className="page-collective content content_full">
|
||||
<img className="page-collective__collective-image"
|
||||
width="100%"
|
||||
src="https://static.shlisselburg.org/art/graphics/collective.jpg"
|
||||
/>
|
||||
|
||||
<div className="content content_semi-wide">
|
||||
{teachers.map((teacher, index) => (
|
||||
<TeacherProfile key={index}
|
||||
profile={teacher}
|
||||
picture={profilePicture(teacher)}
|
||||
url={teacher.url}
|
||||
biography={teacher.biography}
|
||||
name={teacher.splitName()}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
const body = await renderCollective(path, order)
|
||||
|
||||
if (body) {
|
||||
ctx.type = 'text/html'
|
||||
ctx.body = await render(path, Component, getCollectiveMeta(), {menuPadding: false})
|
||||
ctx.body = body
|
||||
} else {
|
||||
ctx.status = 404
|
||||
}
|
||||
@@ -72,23 +18,11 @@ function getCollective(order) {
|
||||
|
||||
function getTeacher() {
|
||||
return get('/teacher/:id', async (ctx, id) => {
|
||||
const path = getPathWithNoTrailingSlash(ctx.path)
|
||||
const teacher = await Teacher.findById(id)
|
||||
|
||||
if (teacher) {
|
||||
const Component = (
|
||||
<div className="content content_semi-wide">
|
||||
<TeacherProfile profile={teacher}
|
||||
picture={profilePicture(teacher)}
|
||||
biography={teacher.biography}
|
||||
name={teacher.splitName()}
|
||||
shareable={true}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
const body = await renderPerson(id)
|
||||
|
||||
if (body) {
|
||||
ctx.type = 'text/html'
|
||||
ctx.body = await render(path, Component, getMeta(teacher), {commentsEnabled: true})
|
||||
ctx.body = body
|
||||
} else {
|
||||
ctx.status = 404
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user