Skip to content

Commit

Permalink
Make Youtube link clikable
Browse files Browse the repository at this point in the history
  • Loading branch information
tpmai22 committed Feb 1, 2022
1 parent 1d3a59e commit fef4294
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
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
21 changes: 21 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 2 additions & 0 deletions src/api/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"bull": "3.29.3",
"bull-board": "2.1.3",
"jsdom": "18.1.1",
"linkify-html": "3.0.5",
"linkifyjs": "3.0.5",
"normalize-url": "6.1.0",
"rss-parser": "3.12.0"
}
Expand Down
2 changes: 2 additions & 0 deletions src/api/parser/src/data/post.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { hash } = require('@senecacdot/satellite');
const linkifyHtml = require('linkify-html');
const { getPost, addPost } = require('../storage');
const Feed = require('./feed');
const textParser = require('../text-parser');
Expand Down Expand Up @@ -85,6 +86,7 @@ class Post {
static async create(postData) {
// If we only have a feed id, get the full Feed Object instead.
const feed = await ensureFeed(postData.feed);
postData.html = linkifyHtml(postData.html);
const post = new Post(
postData.title,
postData.html,
Expand Down
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
3 changes: 3 additions & 0 deletions test/post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ describe('Post data class tests', () => {
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 fef4294

Please sign in to comment.