Commit 46c301af72
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/Feedback.vue +12 −16
| @@ -13,6 +13,7 @@ import { | ||
| 13 | 13 | type FeedbackType, |
| 14 | 14 | getFeedbackOption |
| 15 | 15 | } from '../../types/Feedback' |
| 16 | import { resolvePrompts } from '../../utils/promptConfig' | |
| 16 | 17 | |
| 17 | 18 | const props = defineProps<{ |
| 18 | 19 | heading?: string |
| @@ -29,21 +30,17 @@ const sluggify = (text: string) => | ||
| 29 | 30 | const getURL = (heading: string) => |
| 30 | 31 | `https://wotaku.wiki${withBase(router.route.path)}#${sluggify(heading)}` |
| 31 | 32 | |
| 32 | const prompts = [ | |
| 33 | "Tips: Starring our GitHub repo increases the chances of your feedback being accepted twofold.", | |
| 34 | "Tips: Keep your feedback precise.", | |
| 35 | "Tips: Don't ask us questions as we can't really answer you here, join our Discord instead.", | |
| 36 | "Tips: If you are submitting a scraper site, mention all the sources.", | |
| 37 | "Tips: English, motherf**ker, do you speak it?!", | |
| 38 | "Fun fact: We don't maintain any extension repos, complaining to us won't solve your issue.", | |
| 39 | "Fun fact: We can't really add or fix any type of extensions.", | |
| 40 | "Fun fact: Meme is evil and has almost taken over the wiki.", | |
| 41 | "Fun fact: Bloat ≠ quality.", | |
| 42 | "Damn! We got a visitor!" | |
| 43 | ] | |
| 44 | ||
| 45 | function getPrompt() { | |
| 46 | return prompts[Math.floor(Math.random() * prompts.length)] | |
| 33 | const router = useRouter() | |
| 34 | ||
| 35 | /** | |
| 36 | * Resolve the prompt pool once on mount. | |
| 37 | * Re-evaluates reactively if the route changes (SPA navigation). | |
| 38 | */ | |
| 39 | const promptPool = computed(() => resolvePrompts(router.route.path)) | |
| 40 | ||
| 41 | function getPrompt(): string { | |
| 42 | const pool = promptPool.value | |
| 43 | return pool[Math.floor(Math.random() * pool.length)] | |
| 47 | 44 | } |
| 48 | 45 | |
| 49 | 46 | const loading = ref<boolean>(false) |
| @@ -58,7 +55,6 @@ const isDisabled = computed(() => { | ||
| 58 | 55 | ) |
| 59 | 56 | }) |
| 60 | 57 | |
| 61 | const router = useRouter() | |
| 62 | 58 | // prettier-ignore |
| 63 | 59 | const feedback = reactive< |
| 64 | 60 | Pick<FeedbackType, 'message' | 'page'> & Partial<Pick<FeedbackType, 'type'>> |
docs/.vitepress/utils/promptConfig.ts added +60
| @@ -0,0 +1,60 @@ | ||
| 1 | export interface PromptRule { | |
| 2 | pattern: string | |
| 3 | prompts: string[] | |
| 4 | includeDefault?: boolean | |
| 5 | } | |
| 6 | ||
| 7 | export 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 | ||
| 18 | export 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 | ||
| 42 | function 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 | ||
| 50 | export 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 | } | |
| \ No newline at end of file | ||