mirror of
https://github.com/flarum/framework.git
synced 2025-05-30 12:05:47 +08:00
Rejig formatting API. closes flarum/core#85
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!
This commit is contained in:
@ -9,6 +9,20 @@ export default class PostPreview extends Component {
|
||||
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,
|
||||
@ -17,7 +31,7 @@ export default class PostPreview extends Component {
|
||||
avatar(user), ' ',
|
||||
username(user), ' ',
|
||||
humanTime(post.time()), ' ',
|
||||
highlight(post.excerpt(), this.props.highlight)
|
||||
excerpt
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ Post.prototype.user = Model.one('user');
|
||||
Post.prototype.contentType = Model.prop('contentType');
|
||||
Post.prototype.content = Model.prop('content');
|
||||
Post.prototype.contentHtml = Model.prop('contentHtml');
|
||||
Post.prototype.excerpt = Model.prop('excerpt');
|
||||
Post.prototype.contentPlain = computed('contentHtml', contentHtml => $('<div/>').html(contentHtml.replace(/(<\/p>|<br>)/g, '$1 ')).text());
|
||||
|
||||
Post.prototype.editTime = Model.prop('editTime', Model.date);
|
||||
Post.prototype.editUser = Model.one('editUser');
|
||||
|
Reference in New Issue
Block a user