nfp_sites/nfp_moe/app/article.js

71 lines
2 KiB
JavaScript
Raw Normal View History

2019-09-14 19:03:38 +00:00
const Fileinfo = require('./fileinfo')
2022-07-27 08:41:18 +00:00
const EditorBlock = require('./editorblock')
2022-08-08 07:22:41 +00:00
const media = require('./media')
2019-09-14 19:03:38 +00:00
const Article = {
2021-01-05 19:12:10 +00:00
oninit: function(vnode) {
2022-07-27 08:41:18 +00:00
this.lastId = null
this.onbeforeupdate(vnode)
},
onbeforeupdate: function(vnode) {
2022-07-26 02:55:37 +00:00
let article = vnode.attrs.article
2022-07-27 08:41:18 +00:00
if (this.lastId !== article.id) {
this.lastId = article.id
2022-08-08 07:22:41 +00:00
let pictureCover = '(max-width: 639px) calc(100vw - 40px), '
+ '(max-width: 1000px) 300px, '
+ '400px'
if (vnode.attrs.full) {
pictureCover = '(max-width: 1280) calc(100vw - 2rem), '
+ '1248px'
2022-07-27 08:41:18 +00:00
}
2022-08-08 07:22:41 +00:00
this.pictureData = media.generatePictureSource(
article,
pictureCover)
2021-01-05 19:12:10 +00:00
}
},
2019-09-14 19:03:38 +00:00
view: function(vnode) {
2022-07-26 02:55:37 +00:00
let article = vnode.attrs.article
let files = vnode.attrs.files || article.files || []
2022-07-26 02:55:37 +00:00
return m('article', {
class: vnode.attrs.full ? 'fullsize' : '',
}, [
2019-09-14 19:03:38 +00:00
m(m.route.Link,
2022-07-26 02:55:37 +00:00
{ href: '/article/' + article.path, class: 'title' },
2022-08-08 16:58:20 +00:00
m('h2.title', article.name)
2019-09-14 19:03:38 +00:00
),
m('div.row', [
2022-08-08 07:22:41 +00:00
media.getArticlePicture(
this.pictureData,
!vnode.attrs.full,
vnode.attrs.full ? article.media_path : '/article/' + article.path,
'Image for news item ' + article.name,
),
m('div', [
2022-08-08 16:58:20 +00:00
m('div.description.content',
article.content.blocks.map(block => {
return m(EditorBlock, { block: block })
}),
),
files.map(function(file) {
return m(Fileinfo, { file: file, trim: true })
2022-07-27 08:41:18 +00:00
}),
m('p.meta', [
'Posted ',
(article.page_path ? ['in ', m(m.route.Link, { href: '/page/' + article.page_path }, article.page_name), ' '] : ''),
2022-07-26 02:55:37 +00:00
'at ' + (article.publish_at.replace('T', ' ').split('.')[0]).substr(0, 16),
' by ' + (article.admin_name || 'Admin'),
]),
2019-09-14 19:03:38 +00:00
]),
]),
])
},
}
module.exports = Article