docs/.vitepress/utils/promptConfig.ts

fabbc73f44fa8a9ed8d745b70c2681e7a9f4df4e
wotaku/docs/.vitepress/utils/promptConfig.ts history · blame · raw

60 lines · 1851 bytes

 1export interface PromptRule {
 2  pattern: string
 3  prompts: string[]
 4  includeDefault?: boolean
 5}
 6
 7export const DEFAULT_PROMPTS: string[] = [
 8  "Tips: Starring our GitHub repo increases the chances of your feedback being accepted twofold.",
 9  "Tips: Keep your feedback precise.",
10  "Tips: Don't ask us questions as we can't really answer you here, join our Discord instead.",
11  "Tips: You should read rules before submitting links.",
12  "Tips: English, motherf**ker, do you speak it?!",
13  "Fun fact: Meme is evil and has almost taken over the wiki.",
14  "Fun fact: Bloat ≠ quality.",
15  "Damn! We got a visitor!"
16]
17
18export const PAGE_PROMPT_CONFIG: PromptRule[] = [
19  {
20    pattern: "/ext/*",
21    prompts: [
22      "Fun fact: We don't maintain any extension repos, complaining to us won't solve your issue.",
23      "Fun fact: We can't really add or fix any type of extensions.",
24      "Tips: Visit the extensions homepage to see which apps support which extension systems."
25    ]
26  },
27  {
28    pattern: "/websites",
29    includeDefault: true,
30    prompts: [
31      "Tips: If you are submitting a scraper site, mention all the sources.",
32    ]
33  },
34  {
35    pattern: "/japan/*",
36    prompts: [
37      "We're in urgent need of some solid contributions right now, especially on the software side of things."
38    ]
39  }
40]
41
42function matchPattern(pattern: string, path: string): boolean {
43  if (pattern.endsWith("/*")) {
44    const base = pattern.slice(0, -2)
45    return path === base || path.startsWith(base + "/") || path.startsWith(base)
46  }
47  return path === pattern
48}
49
50export function resolvePrompts(path: string): string[] {
51  const matched = PAGE_PROMPT_CONFIG.find((rule) =>
52    matchPattern(rule.pattern, path)
53  )
54
55  if (!matched) return DEFAULT_PROMPTS
56
57  return matched.includeDefault
58    ? [...matched.prompts, ...DEFAULT_PROMPTS]
59    : matched.prompts
60}