diff --git a/src/render/albums.js b/src/render/albums.js new file mode 100644 index 00000000..4f48cd04 --- /dev/null +++ b/src/render/albums.js @@ -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 = ( +
+
+ {getHtml(album.post)} +
+
+ ) + + return render(album.url, Component, getMeta(album), {commentsEnabled: true, menuPadding: true}) +} + +exports.renderAlbum = renderAlbum diff --git a/src/routes/albums.js b/src/routes/albums.js index bac44308..5f343912 100644 --- a/src/routes/albums.js +++ b/src/routes/albums.js @@ -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 = ( -
-
-
- ) + 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 }