[www] renderAlbum

This commit is contained in:
Roman Timashev committed 2017-10-28 17:26:18 +03:00
1 parent 280fd105d7
commit f174d297f2
2 files changed
+38 -27

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
const React = require('react')
const Article = require('../components/Article')
const Album = require('../core/Album')
const {render} = require('../lib/render')
const getHtml = require('../lib/component').getHtml
function getMeta(album) {
return {
title: album.title,
description: album.title,
}
}
async function renderAlbum(id) {
const album = await Album.findById(id)
if (!album) return null
const Component = (
<div className="content content_thin">
<Article
title={album.title}
date={album.date}
shareable={true}
>
{getHtml(album.post)}
</Article>
</div>
)
return render(album.url, Component, getMeta(album), {commentsEnabled: true, menuPadding: true})
}
exports.renderAlbum = renderAlbum
+4 -27
View File
@@ -1,36 +1,13 @@
const React = require('react')
const Article = require('../components/Article')
const Album = require('../core/Album')
const {render} = require('../lib/render')
const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash
const {renderAlbum} = require('../render/albums')
const {get} = require('koa-route')
function getMeta(album) {
return {
title: album.title,
description: album.title,
}
}
function getAlbum() {
return get('/album/:id', async (ctx, id) => {
const path = getPathWithNoTrailingSlash(ctx.path)
const album = await Album.findById(id)
if (album) {
const Component = (
<div className="content content_thin">
<Article
title={album.title}
date={album.date}
data={album.post}
shareable={true}
/>
</div>
)
const body = await renderAlbum(id)
if (body) {
ctx.type = 'text/html'
ctx.body = await render(path, Component, getMeta(album), {commentsEnabled: true, menuPadding: true})
ctx.body = body
} else {
ctx.status = 404
}