2019-09-14 19:03:38 +00:00
|
|
|
const Fileinfo = require('./fileinfo')
|
2022-08-08 07:22:41 +00:00
|
|
|
const media = require('./media')
|
2019-09-13 13:33:10 +00:00
|
|
|
|
2022-08-05 14:26:29 +00:00
|
|
|
const Articleslim = {
|
2022-07-27 08:41:18 +00:00
|
|
|
oninit: function(vnode) {
|
|
|
|
this.lastId = null
|
|
|
|
this.onbeforeupdate(vnode)
|
|
|
|
},
|
|
|
|
|
2019-09-14 19:03:38 +00:00
|
|
|
strip: function(html) {
|
2022-07-27 08:41:18 +00:00
|
|
|
var doc = new DOMParser().parseFromString(html, 'text/html')
|
2022-08-05 14:26:29 +00:00
|
|
|
var out = (doc.body.textContent || '').replace(/([\.!?])/g, '$1 ')
|
2022-07-27 08:41:18 +00:00
|
|
|
var splitted = out.split('.')
|
|
|
|
if (splitted.length > 2) {
|
2022-08-05 14:26:29 +00:00
|
|
|
return splitted.slice(0, 2).join('.') + '...'
|
2022-07-27 08:41:18 +00:00
|
|
|
}
|
|
|
|
return out
|
2019-09-14 19:03:38 +00:00
|
|
|
},
|
|
|
|
|
2022-07-27 08:41:18 +00:00
|
|
|
onbeforeupdate: function(vnode) {
|
|
|
|
let article = vnode.attrs.article
|
|
|
|
|
|
|
|
if (this.lastId !== article.id) {
|
|
|
|
this.lastId = article.id
|
|
|
|
this.description = null
|
|
|
|
|
2022-08-05 14:26:29 +00:00
|
|
|
if (article.content) {
|
|
|
|
for (let i = 0; i < article.content.blocks.length; i++) {
|
|
|
|
if (article.content.blocks[i].type === 'paragraph') {
|
|
|
|
this.description = article.content.blocks[i].data.text
|
|
|
|
break
|
|
|
|
} else if (article.content.blocks[i].type === 'htmlraw') {
|
|
|
|
this.description = this.strip(article.content.blocks[i].data.html)
|
|
|
|
break
|
|
|
|
}
|
2022-07-27 08:41:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-08 07:22:41 +00:00
|
|
|
this.pictureData = media.generatePictureSource(
|
|
|
|
article,
|
|
|
|
'(max-width: 440px) calc(100vw - 40px), '
|
|
|
|
+ '124px')
|
2019-10-02 21:48:50 +00:00
|
|
|
}
|
2022-07-27 08:41:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
view: function(vnode) {
|
|
|
|
let article = vnode.attrs.article
|
|
|
|
|
2022-08-05 14:26:29 +00:00
|
|
|
return m('articleslim', [
|
2022-08-08 07:22:41 +00:00
|
|
|
media.getArticlePicture(
|
|
|
|
this.pictureData,
|
|
|
|
true,
|
|
|
|
'/article/' + article.path,
|
|
|
|
'Image for news item ' + article.name,
|
|
|
|
m('a.cover.nobg')
|
|
|
|
),
|
2022-08-05 14:26:29 +00:00
|
|
|
m('div', [
|
|
|
|
m(m.route.Link,
|
|
|
|
{ class: 'title', href: '/article/' + article.path },
|
|
|
|
article.name
|
|
|
|
),
|
2022-07-27 08:41:18 +00:00
|
|
|
(article.files && article.files.length
|
|
|
|
? article.files.map(function(file) {
|
2019-09-14 19:03:38 +00:00
|
|
|
return m(Fileinfo, { file: file, slim: true })
|
|
|
|
})
|
2022-07-27 08:41:18 +00:00
|
|
|
: this.description
|
2022-08-05 14:26:29 +00:00
|
|
|
? m('p.description', this.description)
|
2019-09-14 19:03:38 +00:00
|
|
|
: null),
|
|
|
|
]),
|
2019-09-13 13:33:10 +00:00
|
|
|
])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-08-05 14:26:29 +00:00
|
|
|
module.exports = Articleslim
|