[www] Article metadata updated
This commit is contained in:
1 parent
597e87896e
commit
5ab4a1cbfc
2 files changed
+26
-1
No files matched your search
@@ -9,6 +9,8 @@ ImageArtifactType.MEDIUM = 'medium'
|
||||
ImageArtifactType.BIG = 'big'
|
||||
ImageArtifactType.ORIGIN = 'origin'
|
||||
|
||||
ImageArtifactType.FACEBOOK = 'fb'
|
||||
|
||||
ImageArtifactType.RETINA_DENSITY = 2
|
||||
ImageArtifactType.retina = type => `${type}@${ImageArtifactType.RETINA_DENSITY}`
|
||||
|
||||
|
||||
+24
-1
@@ -7,6 +7,8 @@ const Paginator = require('../components/Paginator')
|
||||
const {render} = require('../lib/render')
|
||||
const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash
|
||||
const timestamp = require('../lib/date').timestamp
|
||||
const ImageArtifactType = require('../core/ImageArtifactType')
|
||||
const Image = require('../core/Image')
|
||||
const {sortBy} = require('../utils/sort')
|
||||
const accepts = require('./index').accepts
|
||||
|
||||
@@ -88,9 +90,25 @@ async function getArticleListComponent(path, page, pageSize) {
|
||||
}
|
||||
|
||||
function getMeta(article) {
|
||||
return {
|
||||
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
|
||||
} catch (error) {
|
||||
meta.image = 'https://art.shlisselburg.org/entrance.jpg'
|
||||
}
|
||||
}
|
||||
return meta
|
||||
}
|
||||
|
||||
function getArticles(pageSize) {
|
||||
@@ -120,6 +138,11 @@ function getArticle() {
|
||||
const path = getPathWithNoTrailingSlash(ctx.path)
|
||||
const article = await findArticle(id)
|
||||
|
||||
const previewId = article.preview
|
||||
? article.preview
|
||||
: article.images[0]
|
||||
article.preview = await Image.findById(previewId)
|
||||
|
||||
if (article) {
|
||||
const Component = (
|
||||
<div className="content content_thin">
|
||||
|
||||
Reference in new issue
Block a user