mirror of
https://github.com/flarum/core.git
synced 2025-07-21 08:41:17 +02:00
It works but it’s not the most pretty thing in the world. @franzliedke Would be great if you could take a look at the whole formatting API and work your magic on it sometime… my brain is fried!
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
import Component from 'flarum/component';
|
|
import avatar from 'flarum/helpers/avatar';
|
|
import username from 'flarum/helpers/username';
|
|
import humanTime from 'flarum/helpers/human-time';
|
|
import highlight from 'flarum/helpers/highlight';
|
|
|
|
export default class PostPreview extends Component {
|
|
view() {
|
|
var post = this.props.post;
|
|
var user = post.user();
|
|
|
|
var excerpt = post.contentPlain();
|
|
var start = 0;
|
|
|
|
if (highlight) {
|
|
var regexp = new RegExp(this.props.highlight, 'gi');
|
|
start = Math.max(0, excerpt.search(regexp) - 100);
|
|
}
|
|
|
|
excerpt = (start > 0 ? '...' : '')+excerpt.substring(start, start + 200)+(excerpt.length > start + 200 ? '...' : '');
|
|
|
|
if (highlight) {
|
|
excerpt = highlight(excerpt, regexp);
|
|
}
|
|
|
|
return m('a.post-preview', {
|
|
href: app.route.post(post),
|
|
config: m.route,
|
|
onclick: this.props.onclick
|
|
}, m('div.post-preview-content', [
|
|
avatar(user), ' ',
|
|
username(user), ' ',
|
|
humanTime(post.time()), ' ',
|
|
excerpt
|
|
]));
|
|
}
|
|
}
|