Skip to content

Commit 6208d1a

Browse files
committed
show all code examples (other than p5 and github)
1 parent dd74bfd commit 6208d1a

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

node-scripts/yt-description.mjs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,27 @@ function writeDescription(video) {
381381
description += `\n🕹️ p5.js Web Editor Sketch: ${sketchUrls[0].urls.p5}`;
382382
}
383383
}
384-
if (repoLink || sketchUrls?.length > 0) description += '\n';
384+
385+
// Other Code Examples
386+
const otherCodeExamples = data.codeExamples?.filter(
387+
(ex) => !ex.urls.p5 && !ex.urls.github
388+
);
389+
const getURL = (urls) =>
390+
urls.p5 || urls.processing || urls.node || urls.other;
391+
if (otherCodeExamples && otherCodeExamples.length > 0) {
392+
if (otherCodeExamples.length > 1) {
393+
if (sketchUrls?.length > 0 || repoLink) description += '\n';
394+
description += '\nCode Examples:';
395+
for (const ex of otherCodeExamples) {
396+
description += `\n💻 ${ex.title}: ${getURL(ex.urls)}`;
397+
}
398+
} else {
399+
const ex = otherCodeExamples[0];
400+
description += `\n💻 Code Example: ${getURL(ex.urls)}`;
401+
}
402+
}
403+
if (repoLink || sketchUrls?.length > 0 || otherCodeExamples?.length > 0)
404+
description += '\n';
385405

386406
// Other Parts of this Coding Challenge
387407

@@ -470,7 +490,6 @@ function writeDescription(video) {
470490
}
471491

472492
// Related Challenges
473-
474493
if (data.relatedChallenges && data.relatedChallenges.length > 0) {
475494
description += `\nRelated Coding Challenges:\n`;
476495
for (const challenge of data.relatedChallenges) {
@@ -587,7 +606,9 @@ const allTracks = [...mainTracks, ...sideTracks];
587606
const url = new URL(video);
588607
if (url.hostname == 'thecodingtrain.com') {
589608
const pathName = url.pathname;
590-
specifiedVideos = videos.filter((data) => data.urls.includes(pathName));
609+
specifiedVideos = videos.filter((data) =>
610+
data.urls.includes(pathName.slice(1))
611+
);
591612
} else {
592613
const video = resolveYTLink(url);
593614
if (video) {

0 commit comments

Comments
 (0)