Skip to content

Commit e5c9aa7

Browse files
authored
Merge pull request #1516 from CodingTrain/ytdesc-reduntant-title
Remove redundant video titles from descriptions
2 parents eecd048 + 06ef1f6 commit e5c9aa7

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

β€Žnode-scripts/yt-description.mjs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,14 @@ function writeDescription(video) {
383383
}
384384

385385
// Other Code Examples
386-
const otherCodeExamples = data.codeExamples?.filter(
387-
(ex) => !ex.urls.p5 && !ex.urls.github
388-
);
389386
const getURL = (urls) =>
390387
urls.p5 || urls.processing || urls.node || urls.other;
388+
const otherCodeExamples = data.codeExamples?.filter(
389+
(ex) =>
390+
!ex.urls.p5 &&
391+
getURL(ex.urls) !== repoLink &&
392+
!sketchUrls.includes(getURL(ex.urls))
393+
);
391394
if (otherCodeExamples && otherCodeExamples.length > 0) {
392395
if (otherCodeExamples.length > 1) {
393396
if (sketchUrls?.length > 0 || repoLink) description += '\n';
@@ -413,7 +416,7 @@ function writeDescription(video) {
413416
if (otherParts.length > 0) {
414417
description += '\nOther Parts of this Challenge:';
415418
for (const part of otherParts) {
416-
description += `\nπŸ“Ί ${part.data.partTitle}: https://youtu.be/${part.data.videoId}`;
419+
description += `\nπŸ“Ί https://youtu.be/${part.data.videoId}`;
417420
}
418421
description += '\n';
419422
}
@@ -476,14 +479,23 @@ function writeDescription(video) {
476479
description += `\n${group.title}:\n`;
477480
for (const link of group.links) {
478481
link.icon = link.icon || (group.title === 'Videos' ? 'πŸŽ₯' : 'πŸ”—');
479-
const url = link.url;
480-
if (/https?:\/\/.*/.test(url)) {
482+
let url;
483+
if (/https?:\/\/.*/.test(link.url)) {
481484
// Starts with http:// or https://
482-
description += `${link.icon} ${link.title}: ${url}\n`;
485+
url = link.url;
483486
} else {
484487
// assume relative link in thecodingtrain.com
485488
// try to get YT link instead of website link
486-
description += `${link.icon} ${link.title}: ${resolveCTLink(url)}\n`;
489+
url = resolveCTLink(link.url);
490+
}
491+
// if it's a youtube link, don't add the title (#1280)
492+
if (
493+
new URL(url).hostname.includes('youtube') ||
494+
new URL(url).hostname.includes('youtu.be')
495+
) {
496+
description += `${link.icon} ${url}\n`;
497+
} else {
498+
description += `${link.icon} ${link.title}: ${url}\n`;
487499
}
488500
}
489501
}
@@ -497,10 +509,8 @@ function writeDescription(video) {
497509
vid.urls.includes(`challenges/${challenge}`)
498510
);
499511
if (challengeData) {
500-
const { videoNumber, challengeTitle } = challengeData.data;
501512
const url = challengeData.canonicalURL;
502-
description +=
503-
`πŸš‚ ${videoNumber} ${challengeTitle}: ${resolveCTLink(url)}` + '\n';
513+
description += `πŸš‚ ${resolveCTLink(url)}` + '\n';
504514
} else {
505515
console.log(`Challenge ${challenge} not found`);
506516
}
@@ -550,8 +560,8 @@ Music from Epidemic Sound`;
550560
πŸ–‹οΈ Twitter: https://twitter.com/thecodingtrain
551561
πŸ“Έ Instagram: https://www.instagram.com/the.coding.train/
552562
553-
πŸŽ₯ Coding Challenges: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
554-
πŸŽ₯ Intro to Programming: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
563+
πŸŽ₯ https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
564+
πŸŽ₯ https://www.youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
555565
556566
πŸ”— p5.js: https://p5js.org
557567
πŸ”— p5.js Web Editor: https://editor.p5js.org/

0 commit comments

Comments
Β (0)