forked from friuns2/BlackFriday-GPTs-Prompts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.mjs
82 lines (50 loc) · 1.92 KB
/
update.mjs
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
import { promises as fs } from 'fs';
const jsonContents = await fs.readFile("data/gpts.json", 'utf8');
const flow = JSON.parse(jsonContents).filter(data => !data.nsfw && data.categoryId!=1 && data.category.name!="Models" );
//files
let i =0;
for (let data of flow) {
data.uri = data.uri.substring(0, 200);
let url = ``;
const markdown = `
[![${data.title}](${data.thumbnailURL})](${url})
# ${data.title}
${data.description.replace(/\n/g, '\n\n')}
# Prompt
\`\`\`
${data.initPrompt}
\`\`\`
## Conversation
${data.Conversation.messages.map(message => `**${message.role.toUpperCase()}**: ${message.content.replace(/\n/g, '\n\n')}`).join('\n')}
`;
await fs.writeFile(`gpts/${data.uri}.md`, markdown);
}
//categories
const groups = groupBy(flow, "categoryId");
let header = ``;
for (let groupId of Object.getOwnPropertyNames(groups)) {
let name = groups[groupId][0].category.name;
console.log(name);
// Append category links to readmeContent, renaming 'Others' to 'readme'
header += `- [${name}](./${name.replace(/\s+/g, '-')}.md)\n`;
}
await fs.writeFile(`README.md`, '+header);
for (let groupId of Object.getOwnPropertyNames(groups)) {
let name = groups[groupId][0].category.name;
let readmeContent = `${header}\n\n# ${name}\n\n`;
for (let item of groups[groupId]) {
let desc = item.description.replace(/[\r\n]+/g, ' ').trim().substring(0, 250);
readmeContent += `- [${item.title}](./gpts/${item.uri}.md) ${desc}\n`;
}
await fs.writeFile(`${name.replace(/\s+/g, '-')}.md`, readmeContent);
}
function groupBy(array, key) {
return array.reduce((result, currentItem) => {
const groupKey = currentItem[key];
if (!result[groupKey]) {
result[groupKey] = [];
}
result[groupKey].push(currentItem);
return result;
}, {});
}