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-26 02:55:37 +00:00
|
|
|
let article = vnode.attrs.article
|
|
|
|
if (article.media_prefix) {
|
|
|
|
this.fallbackImage = article.media_prefix + '_small.jpg'
|
|
|
|
this.srcsetJpeg = article.media_prefix + '_small.jpg' + ' 720w, '
|
|
|
|
+ article.media_prefix + '_medium.jpg' + ' 1300w, '
|
|
|
|
+ article.media_prefix + '_large.jpg'
|
|
|
|
this.srcsetAvif = article.media_prefix + '_small.avif' + ' 720w, '
|
|
|
|
+ article.media_prefix + '_medium.avif' + ' 1300w, '
|
|
|
|
+ article.media_prefix + '_large.avif'
|
|
|
|
|
2021-02-05 11:50:01 +00:00
|
|
|
this.coverSizes = '(max-width: 639px) calc(100vw - 40px), '
|
|
|
|
+ '(max-width: 1000px) 300px, '
|
|
|
|
+ '400px'
|
2022-07-26 02:55:37 +00:00
|
|
|
} else {
|
|
|
|
this.fallbackImage = null
|
|
|
|
this.srcsetJpeg = null
|
|
|
|
this.srcsetAvif = null
|
|
|
|
this.coverSizes = 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-26 02:55:37 +00:00
|
|
|
this.fallbackImage
|
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', [
|
|
|
|
this.srcsetAvif ? m('source', {
|
|
|
|
srcset: this.srcsetAvif,
|
|
|
|
sizes: this.coverSizes,
|
|
|
|
type: 'image/avif',
|
|
|
|
}) : null,
|
|
|
|
m('img', {
|
|
|
|
srcset: this.srcsetJpeg,
|
|
|
|
sizes: this.coverSizes,
|
2022-07-26 02:55:37 +00:00
|
|
|
alt: 'Image for news item ' + article.name,
|
|
|
|
src: this.fallbackImage,
|
|
|
|
}),
|
2021-01-05 19:12:10 +00:00
|
|
|
])
|
|
|
|
)
|
2019-10-01 03:45:44 +00:00
|
|
|
: null,
|
|
|
|
m('div.entrycontent', {
|
2022-07-26 02:55:37 +00:00
|
|
|
class: article.media ? '' : 'extrapadding',
|
2019-10-01 03:45:44 +00:00
|
|
|
}, [
|
2022-07-26 02:55:37 +00:00
|
|
|
(article.content
|
|
|
|
? m('.fr-view', m.trust(article.content))
|
2019-09-14 19:03:38 +00:00
|
|
|
: null),
|
2022-07-26 02:55:37 +00:00
|
|
|
(article.files && article.files.length
|
|
|
|
? article.files.map(function(file) {
|
2019-10-02 17:40:32 +00:00
|
|
|
return m(Fileinfo, { file: file, trim: true })
|
2019-09-14 19:03:38 +00:00
|
|
|
})
|
|
|
|
: null),
|
2019-10-02 17:40:32 +00:00
|
|
|
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-10-02 17:40:32 +00:00
|
|
|
]),
|
2019-09-14 19:03:38 +00:00
|
|
|
]),
|
|
|
|
]),
|
|
|
|
])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Newsitem
|