[www] home page rendering refactoring

This commit is contained in:
Roman Timashev committed 2017-10-14 11:47:49 +03:00
1 parent 5b66c90b60
commit 892e270c99
2 files changed
+30 -24

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
const React = require('react')
const getArticleListComponent = require('../routes/articles').getArticleListComponent
const {render} = require('../lib/render')
function getMeta(article) {
return {
title: article.title,
}
}
async function renderHome(path, page, pageSize) {
const articles = await getArticleListComponent(path, 1, pageSize)
const Component = (
<div className="content content_thin">
<div className="hudozka-title">
<p>МБУДО</p>
<h1>Шлиссельбургская детская художественная&nbsp;школа</h1>
</div>
{articles}
</div>
)
return render(path, Component, getMeta({title: 'Шлиссельбургская ДХШ'}), {showAuthor: true})
}
exports.renderHome = renderHome
+2 -24
View File
@@ -1,33 +1,11 @@
const React = require('react')
const Article = require('../components/Article')
const {get} = require('koa-route')
const getArticleListComponent = require('./articles').getArticleListComponent
const {render} = require('../lib/render')
const {renderHome} = require('../render/home')
const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash
function getMeta(article) {
return {
title: article.title,
}
}
function getHome(pageSize) {
return get('/', async ctx => {
const path = getPathWithNoTrailingSlash(ctx.path)
const articles = await getArticleListComponent(path, 1, pageSize)
const Component = (
<div className="content content_thin">
<div className="hudozka-title">
<p>МБУДО</p>
<h1>Шлиссельбургская детская художественная&nbsp;школа</h1>
</div>
{articles}
</div>
)
ctx.body = await render(path, Component, getMeta({title: 'Шлиссельбургская ДХШ'}), {showAuthor: true})
ctx.body = await renderHome(path, 1, pageSize)
})
}