nfp_sites/app/widgets/newsitem.js

71 lines
2.6 KiB
JavaScript
Raw Normal View History

2019-09-14 19:03:38 +00:00
const Fileinfo = require('./fileinfo')
2021-01-05 19:12:10 +00:00
const Newsitem = {
oninit: function(vnode) {
2022-07-20 00:33:06 +00:00
if (vnode.attrs.article.media) {
this.srcsetJpeg = vnode.attrs.article.media.small_url + ' 500w, '
+ vnode.attrs.article.media.medium_url + ' 800w '
if (vnode.attrs.article.media.small_url_avif) {
this.srcsetAvif = vnode.attrs.article.media.small_url_avif + ' 500w, '
+ vnode.attrs.article.media.medium_url_avif + ' 800w '
2021-02-05 11:50:01 +00:00
} else {
this.srcsetAvif = null
}
this.coverSizes = '(max-width: 639px) calc(100vw - 40px), '
+ '(max-width: 1000px) 300px, '
+ '400px'
2021-01-05 19:12:10 +00:00
}
},
2019-09-14 19:03:38 +00:00
view: function(vnode) {
return m('newsitem', [
m(m.route.Link,
2022-07-20 00:33:06 +00:00
{ href: '/article/' + vnode.attrs.article.path, class: 'title' },
m('h3', [vnode.attrs.article.name])
2019-09-14 19:03:38 +00:00
),
m('div.newsitemcontent', [
2022-07-20 00:33:06 +00:00
vnode.attrs.article.media
2021-01-05 19:12:10 +00:00
? m(m.route.Link, {
class: 'cover',
2022-07-20 00:33:06 +00:00
href: '/article/' + vnode.attrs.article.path,
2021-01-05 19:12:10 +00:00
},
m('picture', [
this.srcsetAvif ? m('source', {
srcset: this.srcsetAvif,
sizes: this.coverSizes,
type: 'image/avif',
}) : null,
m('img', {
srcset: this.srcsetJpeg,
sizes: this.coverSizes,
2022-07-20 00:33:06 +00:00
alt: 'Image for news item ' + vnode.attrs.article.name,
src: vnode.attrs.article.media.small_url }),
2021-01-05 19:12:10 +00:00
])
)
2019-10-01 03:45:44 +00:00
: null,
m('div.entrycontent', {
2022-07-20 00:33:06 +00:00
class: vnode.attrs.article.media ? '' : 'extrapadding',
2019-10-01 03:45:44 +00:00
}, [
2022-07-20 00:33:06 +00:00
(vnode.attrs.article.content
? m('.fr-view', m.trust(vnode.attrs.article.content))
2019-09-14 19:03:38 +00:00
: null),
2022-07-20 00:33:06 +00:00
(vnode.attrs.article.files && vnode.attrs.article.files.length
? vnode.attrs.article.files.map(function(file) {
return m(Fileinfo, { file: file, trim: true })
2019-09-14 19:03:38 +00:00
})
: null),
m('span.entrymeta', [
'Posted ',
2022-07-20 00:33:06 +00:00
(vnode.attrs.article.page_path ? 'in' : ''),
(vnode.attrs.article.page_path ? m(m.route.Link, { href: '/page/' + vnode.attrs.article.page_path }, vnode.attrs.article.page_name) : null),
'at ' + (vnode.attrs.article.publish_at.replace('T', ' ').split('.')[0]).substr(0, 16),
' by ' + (vnode.attrs.article.admin_name || 'Admin'),
]),
2019-09-14 19:03:38 +00:00
]),
]),
])
},
}
module.exports = Newsitem