nfp_sites/app/widgets/newsentry.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

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', {
href: '/article/' + vnode.attrs.path,
}, 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