[www] Articles & Article pages refactoring. Displaying as ArticleCard
This commit is contained in:
1 parent
610266db80
commit
625a557e2a
2 files changed
+66
-142
No files matched your search
@@ -1,6 +1,8 @@
|
||||
const React = require('react')
|
||||
const Article = require('../core/Article')
|
||||
const ArticleComponent = require('../components/Article')
|
||||
const ArticleCardList = require('../components/ArticleCardList')
|
||||
const {render} = require('../lib/render')
|
||||
const timestamp = require('../lib/date').timestamp
|
||||
const ImageArtifactType = require('../core/ImageArtifactType')
|
||||
const {sortBy} = require('../utils/sort')
|
||||
@@ -9,6 +11,32 @@ const sortArticleByDate = sortBy(
|
||||
x => timestamp(new Date(x.date))
|
||||
)
|
||||
|
||||
function getMeta(article) {
|
||||
const types = [
|
||||
ImageArtifactType.FACEBOOK,
|
||||
ImageArtifactType.MEDIUM,
|
||||
ImageArtifactType.BIG,
|
||||
ImageArtifactType.ORIGIN,
|
||||
]
|
||||
const meta = {
|
||||
title: article.title,
|
||||
}
|
||||
|
||||
if (article.preview) {
|
||||
try {
|
||||
const artifact = article.preview.findArtifact(types)
|
||||
meta.image = artifact.url
|
||||
meta.imageWidth = artifact.width
|
||||
meta.imageHeight = artifact.height
|
||||
} catch (error) {
|
||||
meta.image = 'https://art.shlisselburg.org/entrance.jpg'
|
||||
meta.imageWidth = 1200
|
||||
meta.imageHeight = 630
|
||||
}
|
||||
}
|
||||
return meta
|
||||
}
|
||||
|
||||
async function findArticlesNin(nin, skip, limit, sort) {
|
||||
const query = {
|
||||
_id: {$nin: nin}
|
||||
@@ -65,4 +93,36 @@ async function createArticleCardList(page, pageSize) {
|
||||
)
|
||||
}
|
||||
|
||||
async function renderArticles(path, page, pageSize) {
|
||||
const articles = await createArticleCardList(page, pageSize)
|
||||
|
||||
const Component = (
|
||||
<div className="content content_wide">
|
||||
{articles}
|
||||
</div>
|
||||
)
|
||||
|
||||
return render(path, Component, getMeta({title: `Статьи`}))
|
||||
}
|
||||
|
||||
async function renderArticle(id) {
|
||||
const article = await Article.findById(id)
|
||||
if (!article) return null
|
||||
|
||||
const Component = (
|
||||
<div className="content content_thin">
|
||||
<ArticleComponent
|
||||
title={article.title}
|
||||
date={article.date}
|
||||
data={article.post}
|
||||
shareable={true}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
return render(article.url, Component, getMeta(article), {commentsEnabled: true})
|
||||
}
|
||||
|
||||
exports.createArticleCardList = createArticleCardList
|
||||
exports.renderArticles = renderArticles
|
||||
exports.renderArticle = renderArticle
|
||||
Reference in new issue
Block a user