forked from timqian/openprompt.co
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
74 lines (59 loc) · 1.86 KB
/
index.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
import * as dotenv from "dotenv";
dotenv.config();
import { createClient } from "@supabase/supabase-js";
import { writeFileSync } from "fs";
// Create a single supabase client for interacting with your database
const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_ANON_KEY
);
const { data, error } = await supabase.from("prompts").select(`
name,
description,
messages,
handles!handles_prompt_id_fkey(
handle
),
created_by:profiles!prompts_created_by_fkey(
handles!handles_user_id_fkey(
handle
)
),
star_count:user-star-prompts(
count
),
created_at
`);
const result = data
.sort((a, b) => b.star_count[0].count - a.star_count[0].count)
// .filter((prompt) => prompt.messages && prompt.messages[0])
.slice(0, 50)
.map((prompt) => {
return {
name: prompt.name,
description: prompt.description,
prompt:
prompt.messages && prompt.messages[0] ? prompt.messages[0].content : "",
handle: prompt.handles.handle,
created_by: prompt.created_by.handles.handle,
star_count: prompt.star_count[0].count,
};
});
writeFileSync("TopPrompts.json", JSON.stringify(result, null, 2));
const promptContentList = result.map(
(prompt, i) => `
## [${i}. ${prompt.name}](https://openprompt.co/${prompt.handle})
${prompt.description}
> ${prompt.prompt}
[📝: ${prompt.created_by}](https://openprompt.co/${
prompt.created_by
}) 🌟: ${prompt.star_count}
`
);
// Generate README.md
const readme = `# OpenPrompt
This is a list of the most starred prompts on [OpenPrompt.co](https://openprompt.co). The list is updated every 24 hours.
The data is also available in the JSON format: [TopPrompts.json](./TopPrompts.json). If you have any suggestion for OpenPrompt, please [open an issue](https://github.com/timqian/openprompt.co/issues)
${promptContentList.join("")}
`;
writeFileSync("README.md", readme);