mirror of
https://github.com/flarum/framework.git
synced 2025-04-26 06:34:06 +08:00
Extract into truncate helper
This commit is contained in:
parent
64b87f55c5
commit
bb651899b1
@ -3,6 +3,7 @@ import avatar from 'flarum/helpers/avatar';
|
|||||||
import username from 'flarum/helpers/username';
|
import username from 'flarum/helpers/username';
|
||||||
import humanTime from 'flarum/helpers/human-time';
|
import humanTime from 'flarum/helpers/human-time';
|
||||||
import highlight from 'flarum/helpers/highlight';
|
import highlight from 'flarum/helpers/highlight';
|
||||||
|
import truncate from 'flarum/utils/truncate';
|
||||||
|
|
||||||
export default class PostPreview extends Component {
|
export default class PostPreview extends Component {
|
||||||
view() {
|
view() {
|
||||||
@ -17,7 +18,7 @@ export default class PostPreview extends Component {
|
|||||||
start = Math.max(0, excerpt.search(regexp) - 100);
|
start = Math.max(0, excerpt.search(regexp) - 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
excerpt = (start > 0 ? '...' : '')+excerpt.substring(start, start + 200)+(excerpt.length > start + 200 ? '...' : '');
|
excerpt = truncate(excerpt, 200, start);
|
||||||
|
|
||||||
if (this.props.highlight) {
|
if (this.props.highlight) {
|
||||||
excerpt = highlight(excerpt, regexp);
|
excerpt = highlight(excerpt, regexp);
|
||||||
|
5
js/lib/utils/truncate.js
Normal file
5
js/lib/utils/truncate.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export default function truncate(string, length, start) {
|
||||||
|
start = start || 0;
|
||||||
|
|
||||||
|
return (start > 0 ? '...' : '')+string.substring(start, start + length)+(string.length > start + length ? '...' : '');
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user