mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
RemoveLinks is better suited as a filter
Unfortunately with `v-html` you cannot use filters directly in handlebars. See: https://github.com/nuxt/nuxt.js/issues/231 I also fixed the tests even **without** mocking vue-filters.js plugin 👍
This commit is contained in:
parent
e595135e9d
commit
055b79bfe2
@ -76,7 +76,6 @@
|
||||
import HcUser from '~/components/User'
|
||||
import ContentMenu from '~/components/ContentMenu'
|
||||
import { randomBytes } from 'crypto'
|
||||
import RemoveLinks from '~/mixins/removeLinks.js'
|
||||
import { mapGetters } from 'vuex'
|
||||
|
||||
export default {
|
||||
@ -96,7 +95,7 @@ export default {
|
||||
user: 'auth/user'
|
||||
}),
|
||||
excerpt() {
|
||||
return RemoveLinks.methods.removeLinks(this.post.contentExcerpt)
|
||||
return this.$filters.removeLinks(this.post.contentExcerpt)
|
||||
},
|
||||
isAuthor() {
|
||||
const { author } = this.post
|
||||
|
||||
@ -2,11 +2,13 @@ import { config, mount, createLocalVue, RouterLinkStub } from '@vue/test-utils'
|
||||
import PostCard from '.'
|
||||
import Styleguide from '@human-connection/styleguide'
|
||||
import Vuex from 'vuex'
|
||||
import Filters from '~/plugins/vue-filters'
|
||||
|
||||
const localVue = createLocalVue()
|
||||
|
||||
localVue.use(Vuex)
|
||||
localVue.use(Styleguide)
|
||||
localVue.use(Filters)
|
||||
|
||||
config.stubs['no-ssr'] = '<span><slot /></span>'
|
||||
config.stubs['v-popover'] = '<span><slot /></span>'
|
||||
|
||||
@ -38,7 +38,6 @@
|
||||
|
||||
<script>
|
||||
import HcUser from '~/components/User'
|
||||
import RemoveLinks from '~/mixins/removeLinks'
|
||||
|
||||
export default {
|
||||
name: 'Notification',
|
||||
@ -53,7 +52,7 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
excerpt() {
|
||||
return RemoveLinks.methods.removeLinks(this.post.contentExcerpt)
|
||||
return this.$filters.removeLinks(this.post.contentExcerpt)
|
||||
},
|
||||
post() {
|
||||
return this.notification.post || {}
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { config, mount, createLocalVue, RouterLinkStub } from '@vue/test-utils'
|
||||
import Notification from '.'
|
||||
import Styleguide from '@human-connection/styleguide'
|
||||
import Filters from '~/plugins/vue-filters'
|
||||
|
||||
const localVue = createLocalVue()
|
||||
|
||||
localVue.use(Styleguide)
|
||||
localVue.use(Filters)
|
||||
|
||||
config.stubs['no-ssr'] = '<span><slot /></span>'
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ import NotificationList from '.'
|
||||
import Notification from '../Notification'
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import Filters from '~/plugins/vue-filters'
|
||||
|
||||
import Styleguide from '@human-connection/styleguide'
|
||||
|
||||
@ -16,6 +17,7 @@ const localVue = createLocalVue()
|
||||
|
||||
localVue.use(Vuex)
|
||||
localVue.use(Styleguide)
|
||||
localVue.use(Filters)
|
||||
localVue.filter('truncate', string => string)
|
||||
|
||||
config.stubs['no-ssr'] = '<span><slot /></span>'
|
||||
|
||||
@ -2,10 +2,12 @@ import { config, shallowMount, createLocalVue } from '@vue/test-utils'
|
||||
import NotificationMenu from '.'
|
||||
|
||||
import Styleguide from '@human-connection/styleguide'
|
||||
import Filters from '~/plugins/vue-filters'
|
||||
|
||||
const localVue = createLocalVue()
|
||||
|
||||
localVue.use(Styleguide)
|
||||
localVue.use(Filters)
|
||||
localVue.filter('truncate', string => string)
|
||||
|
||||
config.stubs['dropdown'] = '<span class="dropdown"><slot /></span>'
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
export default {
|
||||
methods: {
|
||||
removeLinks(content) {
|
||||
if (!content) return ''
|
||||
// remove all links from excerpt to prevent issues with the surrounding link
|
||||
let excerpt = content.replace(/<a.*>(.+)<\/a>/gim, '$1')
|
||||
// do not display content that is only linebreaks
|
||||
if (excerpt.replace(/<br>/gim, '').trim() === '') {
|
||||
excerpt = ''
|
||||
}
|
||||
|
||||
return excerpt
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,7 @@ import formatRelative from 'date-fns/formatRelative'
|
||||
import addSeconds from 'date-fns/addSeconds'
|
||||
import accounting from 'accounting'
|
||||
|
||||
export default ({ app }) => {
|
||||
export default ({ app = {} }) => {
|
||||
const locales = {
|
||||
en: enUS,
|
||||
de: de,
|
||||
@ -88,6 +88,17 @@ export default ({ app }) => {
|
||||
return index === 0 ? letter.toUpperCase() : letter.toLowerCase()
|
||||
})
|
||||
.replace(/\s+/g, '')
|
||||
},
|
||||
removeLinks: content => {
|
||||
if (!content) return ''
|
||||
// remove all links from excerpt to prevent issues with the surrounding link
|
||||
let excerpt = content.replace(/<a.*>(.+)<\/a>/gim, '$1')
|
||||
// do not display content that is only linebreaks
|
||||
if (excerpt.replace(/<br>/gim, '').trim() === '') {
|
||||
excerpt = ''
|
||||
}
|
||||
|
||||
return excerpt
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user