2019-09-14 19:03:38 +00:00
|
|
|
const Fileinfo = require('./fileinfo')
|
2019-09-13 13:33:10 +00:00
|
|
|
|
|
|
|
const Newsentry = {
|
2019-09-14 19:03:38 +00:00
|
|
|
strip: function(html) {
|
|
|
|
var doc = new DOMParser().parseFromString(html, 'text/html')
|
|
|
|
var out = doc.body.textContent || ''
|
|
|
|
var splitted = out.split('.')
|
|
|
|
if (splitted.length > 2) {
|
|
|
|
return splitted.slice(0, 2).join('.') + '...'
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
},
|
|
|
|
|
2019-09-13 13:33:10 +00:00
|
|
|
view: function(vnode) {
|
|
|
|
return m('newsentry', [
|
|
|
|
vnode.attrs.media
|
|
|
|
? m('a.cover', {
|
2019-09-15 01:53:38 +00:00
|
|
|
href: '/article/' + vnode.attrs.path,
|
2019-09-16 16:47:29 +00:00
|
|
|
}, m('img', { src: vnode.attrs.media.small_url, alt: 'Article image for ' + vnode.attrs.name }))
|
2019-09-13 13:33:10 +00:00
|
|
|
: m('a.cover.nobg'),
|
|
|
|
m('div.entrycontent', [
|
2019-09-14 19:03:38 +00:00
|
|
|
m('div.title', [
|
|
|
|
m(m.route.Link,
|
|
|
|
{ href: '/article/' + vnode.attrs.path },
|
|
|
|
m('h3', [vnode.attrs.name])
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
(vnode.attrs.files && vnode.attrs.files.length
|
|
|
|
? vnode.attrs.files.map(function(file) {
|
|
|
|
return m(Fileinfo, { file: file, slim: true })
|
|
|
|
})
|
|
|
|
: vnode.attrs.description
|
|
|
|
? m('span.entrydescription', Newsentry.strip(vnode.attrs.description))
|
|
|
|
: null),
|
|
|
|
]),
|
2019-09-13 13:33:10 +00:00
|
|
|
])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Newsentry
|