Skip to content

Commit 90d908c

Browse files
committed
Add youtube hashtag linking
1 parent b9db0db commit 90d908c

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

live-example/src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ $(document).ready(function () {
6767
hashtagOption = new RadioOption({
6868
name: 'hashtag',
6969
description: 'Hashtags',
70-
options: [false, 'twitter', 'facebook', 'instagram', 'tiktok'],
70+
options: [false, 'twitter', 'facebook', 'instagram', 'tiktok', 'youtube'],
7171
defaultValue: false,
7272
}).onChange(autolink);
7373

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"build:src": "ts-node scripts/build.ts",
1616
"build:live-example": "webpack",
1717
"clean": "rimraf dist",
18+
"devserver": "webpack-dev-server",
1819
"prepublishOnly": "npm-run-all build test",
1920
"start": "webpack serve --open",
2021
"test": "npm-run-all test:unit test:integration",

src/autolinker.ts

+2
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ export default class Autolinker {
265265
* - 'twitter'
266266
* - 'facebook'
267267
* - 'instagram'
268+
* - 'tiktok'
269+
* - 'youtube'
268270
*
269271
* Pass `false` to skip auto-linking of hashtags.
270272
*/

src/match/hashtag-match.ts

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export class HashtagMatch extends AbstractMatch {
9797
return 'https://instagram.com/explore/tags/' + hashtag;
9898
case 'tiktok':
9999
return 'https://www.tiktok.com/tag/' + hashtag;
100+
case 'youtube':
101+
return 'https://youtube.com/hashtag/' + hashtag;
100102

101103
default:
102104
// Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case

src/parser/hashtag-utils.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ export function isValidHashtag(hashtag: string): boolean {
1616
return hashtag.length <= 140;
1717
}
1818

19-
export type HashtagService = 'twitter' | 'facebook' | 'instagram' | 'tiktok';
20-
export const hashtagServices: HashtagService[] = ['twitter', 'facebook', 'instagram', 'tiktok'];
19+
export type HashtagService = 'twitter' | 'facebook' | 'instagram' | 'tiktok' | 'youtube';
20+
export const hashtagServices: HashtagService[] = [
21+
'twitter',
22+
'facebook',
23+
'instagram',
24+
'tiktok',
25+
'youtube',
26+
];

tests/autolinker-hashtag.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ describe(`Hashtag Matching >`, () => {
2121
hashtag: 'tiktok',
2222
newWindow: false,
2323
});
24+
const youtubeAutolinker = new Autolinker({
25+
hashtag: 'youtube',
26+
newWindow: false,
27+
});
2428

2529
const services: HashtagTestService[] = [
2630
{
@@ -43,6 +47,11 @@ describe(`Hashtag Matching >`, () => {
4347
urlPrefix: 'https://www.tiktok.com/tag',
4448
autolinker: tiktokAutolinker,
4549
},
50+
{
51+
serviceName: 'youtube',
52+
urlPrefix: 'https://youtube.com/hashtag',
53+
autolinker: youtubeAutolinker,
54+
},
4655
];
4756

4857
interface HashtagTestService {

0 commit comments

Comments
 (0)