-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.js
More file actions
97 lines (83 loc) · 2.42 KB
/
Copy pathmod.js
File metadata and controls
97 lines (83 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import * as cheerio from 'cheerio';
import color from 'picocolors';
import open from 'open';
import {
intro,
outro,
log,
confirm,
select,
} from '@clack/prompts';
const rootUrl = 'https://heypresents.com/';
const talksUrl = `${rootUrl}/talks/`;
// rest here a while
const sleep = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
// Fetch a bunch of talks from the web
// and extract their titles and urls
const gatherTalks = async () => {
const $ = await cheerio.fromURL(talksUrl);
return $.extract({
talks: [
{
selector: 'main div.grid div',
value: {
name: {
selector: 'h3',
value: (el) => {
const talkTitle = $(el).next("h3").text().trim();
return `${$(el).text().trim()} - ${talkTitle}`
},
},
url: {
selector: 'a',
value: (el) => {
return $(el).attr('href') || '';
},
},
},
},
],
});
};
// Offer a random selection of nuggets to explore
const offerTalks = async () => {
const talks = await gatherTalks();
// Prompt the user to select a talk
const talk = await select({
message: "We've had such wonderful speakers and talks over the years",
options: talks.talks.map((el) => ({
value: el.url,
label: el.name,
})),
});
// Ask if the user wants to visit the talk on the Hey! website
const shouldVisit = await confirm({
message: 'This talk is available to watch on the Hey! website. Shall we take a look?',
});
if (shouldVisit) {
await open(`${rootUrl}${String(talk)}`);
log.info(`Ok! Pointing your browser at ${color.cyan(rootUrl + String(talk))}`);
}
// Ask if the user wants to see some other talks
const more = await confirm({
message: 'Want to see some other talks?',
});
if (more) {
offerTalks();
} else {
outro(color.yellow(color.inverse(' All Day Hey! May 7th, 2026. Leeds, UK ')) + '\n\n' + color.yellow(`Get tickets and more information about All Day Hey! at ${rootUrl}`));
}
};
// Show a simple CLI for browsing the talks and information from All Day Hey!
const main = async () => {
console.log(`
👋 Hey!
`);
intro(color.yellow(color.inverse(' Hey Presents, All Day Hey! ')));
log.info(`All Day Hey 2026 is coming!\nShall we explore some of the previous talks from All Day Hey?`);
await sleep(500);
offerTalks();
};
main();