[www] renderAlbum
This commit is contained in:
1 parent
280fd105d7
commit
f174d297f2
2 files changed
+38
-27
No files matched your search
@@ -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
@@ -1,36 +1,13 @@
|
|||||||
const React = require('react')
|
const {renderAlbum} = require('../render/albums')
|
||||||
const Article = require('../components/Article')
|
|
||||||
const Album = require('../core/Album')
|
|
||||||
const {render} = require('../lib/render')
|
|
||||||
const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash
|
|
||||||
const {get} = require('koa-route')
|
const {get} = require('koa-route')
|
||||||
|
|
||||||
function getMeta(album) {
|
|
||||||
return {
|
|
||||||
title: album.title,
|
|
||||||
description: album.title,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAlbum() {
|
function getAlbum() {
|
||||||
return get('/album/:id', async (ctx, id) => {
|
return get('/album/:id', async (ctx, id) => {
|
||||||
const path = getPathWithNoTrailingSlash(ctx.path)
|
const body = await renderAlbum(id)
|
||||||
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>
|
|
||||||
)
|
|
||||||
|
|
||||||
|
if (body) {
|
||||||
ctx.type = 'text/html'
|
ctx.type = 'text/html'
|
||||||
ctx.body = await render(path, Component, getMeta(album), {commentsEnabled: true, menuPadding: true})
|
ctx.body = body
|
||||||
} else {
|
} else {
|
||||||
ctx.status = 404
|
ctx.status = 404
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user