[www] home page rendering refactoring
This commit is contained in:
1 parent
5b66c90b60
commit
892e270c99
2 files changed
+30
-24
No files matched your search
@@ -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>Шлиссельбургская детская художественная школа</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{articles}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
return render(path, Component, getMeta({title: 'Шлиссельбургская ДХШ'}), {showAuthor: true})
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.renderHome = renderHome
|
||||||
+2
-24
@@ -1,33 +1,11 @@
|
|||||||
const React = require('react')
|
|
||||||
const Article = require('../components/Article')
|
|
||||||
const {get} = require('koa-route')
|
const {get} = require('koa-route')
|
||||||
const getArticleListComponent = require('./articles').getArticleListComponent
|
const {renderHome} = require('../render/home')
|
||||||
const {render} = require('../lib/render')
|
|
||||||
const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash
|
const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash
|
||||||
|
|
||||||
function getMeta(article) {
|
|
||||||
return {
|
|
||||||
title: article.title,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getHome(pageSize) {
|
function getHome(pageSize) {
|
||||||
return get('/', async ctx => {
|
return get('/', async ctx => {
|
||||||
const path = getPathWithNoTrailingSlash(ctx.path)
|
const path = getPathWithNoTrailingSlash(ctx.path)
|
||||||
const articles = await getArticleListComponent(path, 1, pageSize)
|
ctx.body = await renderHome(path, 1, pageSize)
|
||||||
|
|
||||||
const Component = (
|
|
||||||
<div className="content content_thin">
|
|
||||||
<div className="hudozka-title">
|
|
||||||
<p>МБУДО</p>
|
|
||||||
<h1>Шлиссельбургская детская художественная школа</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{articles}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
|
|
||||||
ctx.body = await render(path, Component, getMeta({title: 'Шлиссельбургская ДХШ'}), {showAuthor: true})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user