Skip to content
This repository was archived by the owner on Jul 5, 2022. It is now read-only.

Commit 23eac1a

Browse files
166 ascii details (#3515)
* adjustments to yt generate descriptions script * add challenge 165 md * Add links, change descriptions * slide puzzle * Update 165-slidingpuzzle.md * fixing whitespace * adding links and timecodes * fixing up the page * extra file by accident Co-authored-by: Kobe Liesenborgs <[email protected]>
1 parent 702b9e2 commit 23eac1a

File tree

2 files changed

+95
-43
lines changed

2 files changed

+95
-43
lines changed

_CodingChallenges/166-ascii-image.md

+51
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,57 @@ variations:
2626
lang: 'p5js'
2727
folder: 'ascii-weather-api'
2828
web_editor: 'DhdqcoWn4'
29+
30+
links:
31+
- title: 'ASCII play by ertdfgcvb'
32+
url: 'https://play.ertdfgcvb.xyz/'
33+
- title: 'HTML Entity'
34+
url: 'https://developer.mozilla.org/en-US/docs/Glossary/Entity'
35+
- title: 'HTML div'
36+
url: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div'
37+
- title: 'p5.js loadPixels()'
38+
url: 'https://p5js.org/reference/#/p5/loadPixels'
39+
- title: 'p5.js brightness()'
40+
url: 'https://p5js.org/reference/#/p5/brightness'
41+
- title: 'CodingTrainChooChoo on Twitch'
42+
url: 'https://www.twitch.tv/codingtrainchoochoo'
43+
44+
videos:
45+
- title: 'The Pixel Array'
46+
author: 'The Coding Train'
47+
video_id: nMUMZ5YRxHI
48+
- title: 'Basics of CSS'
49+
author: 'The Coding Train'
50+
url: /Tutorials/8-html-css-dom/8.7-css-basics
51+
- title: 'p5.js Web Editor - Uploading Media Files'
52+
author: 'The Coding Train'
53+
video_id: rO6M5hj0V-o
54+
55+
topics:
56+
- title: 'Welcome! Choo choo!'
57+
time: '0:00'
58+
- title: 'Introducing Today’s Topic'
59+
time: '0:28'
60+
- title: 'Pixel to ASCII'
61+
time: '1:39'
62+
- title: 'Pixelating an image'
63+
time: '4:52'
64+
- title: 'Pixel Array Explanation'
65+
time: '7:03'
66+
- title: 'Back to the code'
67+
time: '8:40'
68+
- title: 'Adding Text'
69+
time: '10:18'
70+
- title: 'Mapping Brightness to Characters'
71+
time: '11:04'
72+
- title: 'Switching from canvas to DOM'
73+
time: '13:26'
74+
- title: 'Real-time ASCII video'
75+
time: '18:10'
76+
- title: 'Some refinements'
77+
time: '20:10'
78+
- title: 'See you next time!'
79+
time: '21:29'
2980
---
3081

3182
Let's make ASCII art in p5.js together! In this video, I demonstrate a variety of techniques for translating the pixels of an image into text and finish with rendering video as text ASCII characters in a DOM.

_scripts/generate-youtube-descriptions.js

+44-43
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const yaml = require('yaml-front-matter');
44

55
function findVideoFilesRecursive(dir, arrayOfFiles) {
66
const files = fs.readdirSync(dir);
7-
7+
88
arrayOfFiles = arrayOfFiles || [];
99

1010
for (const file of files) {
@@ -31,28 +31,27 @@ function getPlaylist(file) {
3131
}
3232

3333
function getVideoData() {
34-
3534
const directories = [
36-
'_learning',
37-
'_beginners',
38-
'_more',
39-
'_challenges',
35+
// '_learning',
36+
// '_beginners',
37+
// '_more',
38+
// '_challenges',
4039
'_CodingChallenges',
41-
'_Courses',
42-
'_GuestTutorials',
43-
'_Streams',
44-
'_TeachableMachine',
45-
'_Tutorials',
40+
// '_Courses',
41+
// '_GuestTutorials',
42+
// '_Streams',
43+
// '_TeachableMachine',
44+
// '_Tutorials',
4645
];
4746

4847
let files = [];
4948
for (const dir of directories) {
5049
findVideoFilesRecursive(dir, files);
5150
}
52-
53-
const videos = [];
5451

52+
const videos = [];
5553
for (const file of files) {
54+
console.log(file);
5655
const content = fs.readFileSync(`./${file}`, 'UTF8');
5756
const parsed = yaml.loadFront(content);
5857
let url = file.substring(1);
@@ -68,33 +67,31 @@ function getVideoData() {
6867
}
6968

7069
function primeDirectory(dir) {
71-
7270
fs.rmdirSync(dir, { recursive: true }, (err) => {
7371
if (err) {
74-
throw err;
72+
throw err;
7573
}
7674
});
77-
78-
fs.mkdirSync(dir, err => {
79-
if(err) {
75+
76+
fs.mkdirSync(dir, (err) => {
77+
if (err) {
8078
throw err;
8179
}
8280
});
83-
8481
}
8582

8683
function getVideoID(url) {
8784
const location = url.substring(1, url.length);
8885
let page;
8986
try {
9087
// link to page on the site
91-
page = fs.readFileSync(`./_${location}.md`, "UTF8");
88+
page = fs.readFileSync(`./_${location}.md`, 'UTF8');
9289
} catch (err) {
9390
try {
9491
// link to series on site
9592
const files = fs.readdirSync(`./_${location}`);
9693
// get first page in series
97-
page = fs.readFileSync(`./_${location}/${files[0]}.md`, "UTF8");
94+
page = fs.readFileSync(`./_${location}/${files[0]}.md`, 'UTF8');
9895
} catch (e) {
9996
// link to youtube playlist
10097
return url;
@@ -105,16 +102,14 @@ function getVideoID(url) {
105102
}
106103

107104
function writeDescriptions(videos) {
108-
109105
primeDirectory('./_descriptions');
110106

111107
for (let i = 0; i < videos.length; i++) {
112-
113108
const data = videos[i].data;
114109
const pageURL = videos[i].pageURL;
115110
const playlist = videos[i].playlist;
116111

117-
let description = "";
112+
let description = '';
118113

119114
// Description
120115
let content = data.__content;
@@ -132,7 +127,6 @@ function writeDescriptions(videos) {
132127
if (data.variations) {
133128
for (let j = 0; j < data.variations.length; ++j) {
134129
if (data.variations[j].web_editor) {
135-
136130
if (!hasWebEditorVariations) {
137131
description += '\np5.js Web Editor Sketches:\n';
138132

@@ -144,7 +138,6 @@ function writeDescriptions(videos) {
144138
description += `🕹️ ${data.variations[j].name}: https://editor.p5js.org/codingtrain/sketches/${data.variations[j].web_editor}\n`;
145139

146140
hasWebEditorVariations = true;
147-
148141
}
149142
}
150143
}
@@ -156,7 +149,10 @@ function writeDescriptions(videos) {
156149
// Next Video / Previous Video / Playlist
157150
let nextID;
158151
if (i !== videos.length - 1) {
159-
if (pageURL.substring(0, pageURL.lastIndexOf('/')) === videos[i + 1].pageURL.substring(0, videos[i + 1].pageURL.lastIndexOf('/'))) {
152+
if (
153+
pageURL.substring(0, pageURL.lastIndexOf('/')) ===
154+
videos[i + 1].pageURL.substring(0, videos[i + 1].pageURL.lastIndexOf('/'))
155+
) {
160156
nextID = videos[i + 1].data.video_id;
161157
} else {
162158
nextID = false;
@@ -167,7 +163,10 @@ function writeDescriptions(videos) {
167163

168164
let previousID;
169165
if (i !== 0) {
170-
if (pageURL.substring(0, pageURL.lastIndexOf('/')) === videos[i - 1].pageURL.substring(0, videos[i - 1].pageURL.lastIndexOf('/'))) {
166+
if (
167+
pageURL.substring(0, pageURL.lastIndexOf('/')) ===
168+
videos[i - 1].pageURL.substring(0, videos[i - 1].pageURL.lastIndexOf('/'))
169+
) {
171170
previousID = videos[i - 1].data.video_id;
172171
} else {
173172
previousID = false;
@@ -198,34 +197,36 @@ function writeDescriptions(videos) {
198197

199198
// Links
200199
if (data.links) {
201-
description += "\nLinks discussed in this video:\n";
200+
description += '\nLinks discussed in this video:\n';
202201
for (let i = 0; i < data.links.length; ++i) {
203202
const url = data.links[i].url;
204-
if (/https?:\/\/.*/.test(url)) { // starts with http:// or https://
205-
description += `🔗 ${data.links[i].title}: ${url}\n`
206-
} else { // assume relative link in thecodingtrain.com
207-
description += `🔗 ${data.links[i].title}: https://thecodingtrain.com${url}\n`
203+
if (/https?:\/\/.*/.test(url)) {
204+
// starts with http:// or https://
205+
description += `🔗 ${data.links[i].title}: ${url}\n`;
206+
} else {
207+
// assume relative link in thecodingtrain.com
208+
description += `🔗 ${data.links[i].title}: https://thecodingtrain.com${url}\n`;
208209
}
209210
}
210211
}
211212

212213
// Videos
213214
if (data.videos) {
214-
description += "\nOther videos mentioned in this video:\n";
215+
description += '\nOther videos mentioned in this video:\n';
215216
for (let i = 0; i < data.videos.length; ++i) {
216217
if (data.videos[i].video_id) {
217-
description += `🎥 ${data.videos[i].title}: https://youtu.be/${data.videos[i].video_id}\n`
218+
description += `🎥 ${data.videos[i].title}: https://youtu.be/${data.videos[i].video_id}\n`;
218219
} else if (data.videos[i].url) {
219-
description += `🎥 ${data.videos[i].title}: ${getVideoID(data.videos[i].url)}\n`
220+
description += `🎥 ${data.videos[i].title}: ${getVideoID(data.videos[i].url)}\n`;
220221
}
221222
}
222223
}
223224

224225
// Timestamps
225226
if (data.topics) {
226-
description += "\nTimestamps:\n";
227+
description += '\nTimestamps:\n';
227228
for (let i = 0; i < data.topics.length; ++i) {
228-
description += `${data.topics[i].time} ${data.topics[i].title}\n`
229+
description += `${data.topics[i].time} ${data.topics[i].title}\n`;
229230
}
230231
}
231232

@@ -253,15 +254,15 @@ function writeDescriptions(videos) {
253254
254255
This description was auto-generated. If you see a problem, please open an issue: https://github.com/CodingTrain/website/issues/new`;
255256

256-
fs.writeFileSync(`_descriptions/${data.video_id}.txt`, description);
257-
}
257+
//fs.writeFileSync(`_descriptions/${data.video_id}.txt`, description);
258258

259+
let filename = /\/((?:.(?!\/))+)$/.exec(pageURL)[1];
260+
fs.writeFileSync(`_descriptions/${filename}.txt`, description);
261+
}
259262
}
260263

261264
(() => {
262-
263-
console.log("💫 Generating YouTube Descriptions 💫")
265+
console.log('💫 Generating YouTube Descriptions 💫');
264266

265267
writeDescriptions(getVideoData());
266-
267268
})();

0 commit comments

Comments
 (0)