Skip to content

Commit

Permalink
Make Youtube link clikable
Browse files Browse the repository at this point in the history
  • Loading branch information
tpmai22 authored and aserputov committed Feb 2, 2022
1 parent 95b8850 commit 4cec3c2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"ioredis": "4.28.2",
"ioredis-mock": "5.8.1",
"jsdom": "18.1.1",
"linkify-html": "3.0.5",
"linkifyjs": "3.0.5",
"node-fetch": "2.6.7",
"normalize-url": "6.1.0",
"opml-generator": "1.1.1",
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/backend/data/post.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const linkifyHtml = require('linkify-html');
const { getPost, addPost } = require('../utils/storage');
const { logger } = require('../utils/logger');
const processHTML = require('../utils/html');
Expand Down Expand Up @@ -148,7 +149,16 @@ class Post {
article.date = article.pubdate;
}

// All the Youtube feed return an array off html so we will need to convert it to a string so as to process and sanitize it
if (Array.isArray(article.content)) {
article.content = article.content.join(' ');
}

// Wrap an <a> tag on any link inside our content
article.content = linkifyHtml(article.content);

let html;

try {
// The article.content is frequently the full HTML article content.
// Sanitize it of any scripts or other dangerous attributes/elements,
Expand Down
5 changes: 4 additions & 1 deletion test/post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,17 @@ describe('Post data class tests', () => {
expect(articles.items.length).toBe(15);
});

test('Post.createFromArticle() should create Post with YouTube video article', async () => {
test('Post.createFromArticle() should create Post with YouTube video article, with linkified content', async () => {
const article = articles.items[0];
const id = await Post.createFromArticle(article, feed);
const videoPost = await Post.byId(id);

expect(videoPost.title).toBe('DPS909 OSD600 Week 03 - Fixing a Bug in the Azure JS SDK');
expect(videoPost.url).toBe('https://www.youtube.com/watch?v=mNuHA7vH6Wc');
expect(videoPost.type).toBe('video');
expect(videoPost.html).toBe(
'Walkthrough and discussion of fixing a bug in <a href="https://github.com/Azure/azure-sdk-for-js">https://github.com/Azure/azure-sdk-for-js</a>. Issue at <a href="https://github.com/Azure/azure-sdk-for-js/issues/15772">https://github.com/Azure/azure-sdk-for-js/issues/15772</a>. PR at <a href="https://github.com/Azure/azure-sdk-for-js/pull/17820">https://github.com/Azure/azure-sdk-for-js/pull/17820</a>.'
);
});
});
});

0 comments on commit 4cec3c2

Please sign in to comment.