mirror of
https://akkoma.dev/AkkomaGang/akkoma-fe.git
synced 2024-11-08 17:39:09 +00:00
Remove attachment links, as we are already showing them.
This commit is contained in:
parent
c9ab70db8e
commit
05733b6bc9
5 changed files with 42 additions and 6 deletions
|
@ -15,6 +15,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"moment": "^2.15.2",
|
"moment": "^2.15.2",
|
||||||
"node-sass": "^3.10.1",
|
"node-sass": "^3.10.1",
|
||||||
|
"sanitize-html": "^1.13.0",
|
||||||
"sass-loader": "^4.0.2",
|
"sass-loader": "^4.0.2",
|
||||||
"vue": "^2.0.1",
|
"vue": "^2.0.1",
|
||||||
"vue-router": "^2.0.1",
|
"vue-router": "^2.0.1",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { reduce, map, slice, last, intersectionBy, sortBy, unionBy, toInteger, groupBy, differenceBy, each, find } from 'lodash'
|
import { reduce, map, slice, last, intersectionBy, sortBy, unionBy, toInteger, groupBy, differenceBy, each, find } from 'lodash'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import apiService from '../services/api/api.service.js'
|
import apiService from '../services/api/api.service.js'
|
||||||
|
import parse from '../services/status_parser/status_parser.js'
|
||||||
|
|
||||||
export const defaultState = {
|
export const defaultState = {
|
||||||
allStatuses: [],
|
allStatuses: [],
|
||||||
|
@ -60,11 +61,7 @@ const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visib
|
||||||
const statusoid = status.retweeted_status || status
|
const statusoid = status.retweeted_status || status
|
||||||
|
|
||||||
statusoid.created_at_parsed = statusoid.created_at
|
statusoid.created_at_parsed = statusoid.created_at
|
||||||
|
statusoid.statusnet_html = parse(statusoid.statusnet_html)
|
||||||
if (statusoid.parsedText === undefined) {
|
|
||||||
// statusoid.parsedText = statusParserService.parse(statusoid)
|
|
||||||
statusoid.parsedText = statusoid.text
|
|
||||||
}
|
|
||||||
|
|
||||||
if (statusoid.nsfw === undefined) {
|
if (statusoid.nsfw === undefined) {
|
||||||
const nsfwRegex = /#nsfw/i
|
const nsfwRegex = /#nsfw/i
|
||||||
|
|
15
src/services/status_parser/status_parser.js
Normal file
15
src/services/status_parser/status_parser.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import sanitize from 'sanitize-html'
|
||||||
|
|
||||||
|
export const removeAttachmentLinks = (html) => {
|
||||||
|
return sanitize(html, {
|
||||||
|
allowedTags: false,
|
||||||
|
allowedAttributes: false,
|
||||||
|
exclusiveFilter: ({ tag, attribs: { class: klass } }) => tag === 'a' && klass.match(/attachment/)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const parse = (html) => {
|
||||||
|
return removeAttachmentLinks(html)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default parse
|
11
test/unit/specs/services/status_parser/status_parses.spec.js
Normal file
11
test/unit/specs/services/status_parser/status_parses.spec.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
const example = '<div class="status-content">@<a href="https://sealion.club/user/4" class="h-card mention" title="dewoo">dwmatiz</a> <a href="https://social.heldscal.la/file/3deb764ada10ce64a61b7a070b75dac45f86d2d5bf213bf18873da71d8714d86.png" title="https://social.heldscal.la/file/3deb764ada10ce64a61b7a070b75dac45f86d2d5bf213bf18873da71d8714d86.png" class="attachment" id="attachment-159853" rel="nofollow external">https://social.heldscal.la/attachment/159853</a></div>'
|
||||||
|
|
||||||
|
import { removeAttachmentLinks } from '../../../../../src/services/status_parser/status_parser.js'
|
||||||
|
|
||||||
|
describe('statusParser.removeAttachmentLinks', () => {
|
||||||
|
const exampleWithoutAttachmentLinks = '<div class="status-content">@<a href="https://sealion.club/user/4" class="h-card mention" title="dewoo">dwmatiz</a> </div>'
|
||||||
|
it('removes attachment links', () => {
|
||||||
|
const parsed = removeAttachmentLinks(example)
|
||||||
|
expect(parsed).to.eql(exampleWithoutAttachmentLinks)
|
||||||
|
})
|
||||||
|
})
|
14
yarn.lock
14
yarn.lock
|
@ -2614,7 +2614,7 @@ html-webpack-plugin@^2.8.1:
|
||||||
pretty-error "^2.0.2"
|
pretty-error "^2.0.2"
|
||||||
toposort "^1.0.0"
|
toposort "^1.0.0"
|
||||||
|
|
||||||
htmlparser2@^3.8.2:
|
htmlparser2@^3.8.2, htmlparser2@^3.9.0:
|
||||||
version "3.9.2"
|
version "3.9.2"
|
||||||
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.9.2.tgz#1bdf87acca0f3f9e53fa4fcceb0f4b4cbb00b338"
|
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.9.2.tgz#1bdf87acca0f3f9e53fa4fcceb0f4b4cbb00b338"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -4778,6 +4778,10 @@ regex-cache@^0.4.2:
|
||||||
is-equal-shallow "^0.1.3"
|
is-equal-shallow "^0.1.3"
|
||||||
is-primitive "^2.0.0"
|
is-primitive "^2.0.0"
|
||||||
|
|
||||||
|
regexp-quote@0.0.0:
|
||||||
|
version "0.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/regexp-quote/-/regexp-quote-0.0.0.tgz#1e0f4650c862dcbfed54fd42b148e9bb1721fcf2"
|
||||||
|
|
||||||
regexpu-core@^1.0.0:
|
regexpu-core@^1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-1.0.0.tgz#86a763f58ee4d7c2f6b102e4764050de7ed90c6b"
|
resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-1.0.0.tgz#86a763f58ee4d7c2f6b102e4764050de7ed90c6b"
|
||||||
|
@ -4961,6 +4965,14 @@ samsam@1.1.2:
|
||||||
version "1.1.2"
|
version "1.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.2.tgz#bec11fdc83a9fda063401210e40176c3024d1567"
|
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.2.tgz#bec11fdc83a9fda063401210e40176c3024d1567"
|
||||||
|
|
||||||
|
sanitize-html:
|
||||||
|
version "1.13.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/sanitize-html/-/sanitize-html-1.13.0.tgz#4ee17cbec516bfe32f2ce6686a569d7e6b4f3631"
|
||||||
|
dependencies:
|
||||||
|
htmlparser2 "^3.9.0"
|
||||||
|
regexp-quote "0.0.0"
|
||||||
|
xtend "^4.0.0"
|
||||||
|
|
||||||
sass-graph@^2.1.1:
|
sass-graph@^2.1.1:
|
||||||
version "2.1.2"
|
version "2.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/sass-graph/-/sass-graph-2.1.2.tgz#965104be23e8103cb7e5f710df65935b317da57b"
|
resolved "https://registry.yarnpkg.com/sass-graph/-/sass-graph-2.1.2.tgz#965104be23e8103cb7e5f710df65935b317da57b"
|
||||||
|
|
Loading…
Reference in a new issue