mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 07:09:24 +02:00
Moment, markdown and truncate filters
This commit is contained in:
parent
999198b1c5
commit
7ffff90005
4 changed files with 69 additions and 0 deletions
31
front/src/filters.js
Normal file
31
front/src/filters.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import Vue from 'vue'
|
||||
|
||||
import moment from 'moment'
|
||||
import showdown from 'showdown'
|
||||
|
||||
export function truncate (str, max, ellipsis) {
|
||||
max = max || 100
|
||||
ellipsis = ellipsis || '…'
|
||||
if (str.length <= max) {
|
||||
return str
|
||||
}
|
||||
return str.slice(0, max) + ellipsis
|
||||
}
|
||||
|
||||
Vue.filter('truncate', truncate)
|
||||
|
||||
export function markdown (str) {
|
||||
const converter = new showdown.Converter()
|
||||
return converter.makeHtml(str)
|
||||
}
|
||||
|
||||
Vue.filter('markdown', markdown)
|
||||
|
||||
export function ago (date) {
|
||||
const m = moment(date)
|
||||
return m.fromNow()
|
||||
}
|
||||
|
||||
Vue.filter('ago', ago)
|
||||
|
||||
export default {}
|
Loading…
Add table
Add a link
Reference in a new issue