diff options
-rw-r--r-- | server/controllers/feeds.ts | 9 | ||||
-rw-r--r-- | server/helpers/markdown.ts | 4 | ||||
-rw-r--r-- | server/tests/feeds/feeds.ts | 4 |
3 files changed, 9 insertions, 8 deletions
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index 29502a154..3c8680ca4 100644 --- a/server/controllers/feeds.ts +++ b/server/controllers/feeds.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import Feed from 'pfeed' | 2 | import Feed from 'pfeed' |
3 | import { mdToPlainText, toSafeHtml } from '@server/helpers/markdown' | ||
3 | import { getServerActor } from '@server/models/application/application' | 4 | import { getServerActor } from '@server/models/application/application' |
4 | import { getCategoryLabel } from '@server/models/video/formatter/video-format-utils' | 5 | import { getCategoryLabel } from '@server/models/video/formatter/video-format-utils' |
5 | import { VideoInclude } from '@shared/models' | 6 | import { VideoInclude } from '@shared/models' |
@@ -119,7 +120,7 @@ async function generateVideoCommentsFeed (req: express.Request, res: express.Res | |||
119 | title, | 120 | title, |
120 | id: comment.url, | 121 | id: comment.url, |
121 | link, | 122 | link, |
122 | content: comment.text, | 123 | content: toSafeHtml(comment.text), |
123 | author, | 124 | author, |
124 | date: comment.createdAt | 125 | date: comment.createdAt |
125 | }) | 126 | }) |
@@ -235,7 +236,7 @@ function initFeed (parameters: { | |||
235 | 236 | ||
236 | return new Feed({ | 237 | return new Feed({ |
237 | title: name, | 238 | title: name, |
238 | description, | 239 | description: mdToPlainText(description), |
239 | // updated: TODO: somehowGetLatestUpdate, // optional, default = today | 240 | // updated: TODO: somehowGetLatestUpdate, // optional, default = today |
240 | id: webserverUrl, | 241 | id: webserverUrl, |
241 | link: webserverUrl, | 242 | link: webserverUrl, |
@@ -298,8 +299,8 @@ function addVideosToFeed (feed, videos: VideoModel[]) { | |||
298 | title: video.name, | 299 | title: video.name, |
299 | id: video.url, | 300 | id: video.url, |
300 | link: WEBSERVER.URL + video.getWatchStaticPath(), | 301 | link: WEBSERVER.URL + video.getWatchStaticPath(), |
301 | description: video.getTruncatedDescription(), | 302 | description: mdToPlainText(video.getTruncatedDescription()), |
302 | content: video.description, | 303 | content: toSafeHtml(video.description), |
303 | author: [ | 304 | author: [ |
304 | { | 305 | { |
305 | name: video.VideoChannel.Account.getDisplayName(), | 306 | name: video.VideoChannel.Account.getDisplayName(), |
diff --git a/server/helpers/markdown.ts b/server/helpers/markdown.ts index ebf479b98..0b8c2fabc 100644 --- a/server/helpers/markdown.ts +++ b/server/helpers/markdown.ts | |||
@@ -10,7 +10,7 @@ const markdownIt = new MarkdownItClass('default', { linkify: true, breaks: true, | |||
10 | markdownIt.enable(TEXT_WITH_HTML_RULES) | 10 | markdownIt.enable(TEXT_WITH_HTML_RULES) |
11 | markdownIt.use(markdownItEmoji) | 11 | markdownIt.use(markdownItEmoji) |
12 | 12 | ||
13 | const toSafeHtml = text => { | 13 | const toSafeHtml = (text: string) => { |
14 | if (!text) return '' | 14 | if (!text) return '' |
15 | 15 | ||
16 | // Restore line feed | 16 | // Restore line feed |
@@ -23,7 +23,7 @@ const toSafeHtml = text => { | |||
23 | return sanitizeHtml(html, sanitizeOptions) | 23 | return sanitizeHtml(html, sanitizeOptions) |
24 | } | 24 | } |
25 | 25 | ||
26 | const mdToPlainText = text => { | 26 | const mdToPlainText = (text: string) => { |
27 | if (!text) return '' | 27 | if (!text) return '' |
28 | 28 | ||
29 | // Convert possible markdown (emojis, emphasis and lists) to html | 29 | // Convert possible markdown (emojis, emphasis and lists) to html |
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts index 24a518342..74cbaeb6d 100644 --- a/server/tests/feeds/feeds.ts +++ b/server/tests/feeds/feeds.ts | |||
@@ -274,8 +274,8 @@ describe('Test syndication feeds', () => { | |||
274 | 274 | ||
275 | const jsonObj = JSON.parse(json) | 275 | const jsonObj = JSON.parse(json) |
276 | expect(jsonObj.items.length).to.be.equal(2) | 276 | expect(jsonObj.items.length).to.be.equal(2) |
277 | expect(jsonObj.items[0].html_content).to.equal('super comment 2') | 277 | expect(jsonObj.items[0].html_content).to.contain('<p>super comment 2</p>') |
278 | expect(jsonObj.items[1].html_content).to.equal('super comment 1') | 278 | expect(jsonObj.items[1].html_content).to.contain('<p>super comment 1</p>') |
279 | } | 279 | } |
280 | }) | 280 | }) |
281 | 281 | ||