nfp_sites/app/widgets/newsitem.js

89 lines
2.9 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')
2019-09-14 19:03:38 +00:00
2021-01-05 19:12:10 +00:00
const Newsitem = {
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
if (article.media_alt_prefix) {
this.pictureFallback = article.media_alt_prefix + '_small.jpg'
this.pictureJpeg = article.media_alt_prefix + '_small.jpg' + ' 720w, '
+ article.media_alt_prefix + '_medium.jpg' + ' 1300w, '
+ article.media_alt_prefix + '_large.jpg 1920w'
this.pictureAvif = article.media_alt_prefix + '_small.avif' + ' 720w, '
+ article.media_alt_prefix + '_medium.avif' + ' 1300w, '
+ article.media_alt_prefix + '_large.avif 1920w'
this.pictureCover = '(max-width: 639px) calc(100vw - 40px), '
+ '(max-width: 1000px) 300px, '
+ '400px'
} else {
this.pictureFallback = null
this.pictureJpeg = null
this.pictureAvif = null
this.pictureCover = null
}
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
2019-09-14 19:03:38 +00:00
return m('newsitem', [
m(m.route.Link,
2022-07-26 02:55:37 +00:00
{ href: '/article/' + article.path, class: 'title' },
m('h3', [article.name])
2019-09-14 19:03:38 +00:00
),
m('div.newsitemcontent', [
2022-07-27 08:41:18 +00:00
this.pictureFallback
2021-01-05 19:12:10 +00:00
? m(m.route.Link, {
class: 'cover',
2022-07-26 02:55:37 +00:00
href: '/article/' + article.path,
2021-01-05 19:12:10 +00:00
},
m('picture', [
2022-07-27 08:41:18 +00:00
m('source', {
srcset: this.pictureAvif,
sizes: this.pictureCover,
2021-01-05 19:12:10 +00:00
type: 'image/avif',
2022-07-27 08:41:18 +00:00
}),
2021-01-05 19:12:10 +00:00
m('img', {
2022-07-27 08:41:18 +00:00
srcset: this.pictureJpeg,
sizes: this.pictureCover,
2022-07-26 02:55:37 +00:00
alt: 'Image for news item ' + article.name,
2022-07-27 08:41:18 +00:00
src: this.pictureFallback,
2022-07-26 02:55:37 +00:00
}),
2021-01-05 19:12:10 +00:00
])
)
2019-10-01 03:45:44 +00:00
: null,
2022-07-27 08:41:18 +00:00
m('div.entrycontent', [
article.content.blocks.map(block => {
return m(EditorBlock, { block: block })
}),
2022-07-26 02:55:37 +00:00
(article.files && article.files.length
? 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-26 02:55:37 +00:00
(article.page_path ? 'in' : ''),
(article.page_path ? m(m.route.Link, { href: '/page/' + article.page_path }, article.page_name) : null),
'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 = Newsitem