Openstatus www.openstatus.dev

chore: cmdk nit (#1674)

* chore: text-muted and go to home

* chore: unify getPage

authored by

Maximilian Kaske and committed by
GitHub
15fc6e1d cc9bba3a

+61 -25
+13 -22
apps/web/src/app/api/search/route.ts
··· 1 1 import { slugify } from "@/content/mdx"; 2 2 import { 3 3 type MDXData, 4 - getBlogPosts, 5 - getChangelogPosts, 6 - getComparePages, 4 + PAGE_TYPES, 7 5 getHomePage, 8 - getProductPages, 9 - getToolsPages, 6 + getPages, 10 7 } from "@/content/utils"; 11 8 import sanitizeHtml from "sanitize-html"; 12 9 import { z } from "zod"; 13 10 14 11 const SearchSchema = z.object({ 15 - p: z 16 - .enum(["blog", "changelog", "tools", "compare", "product", "all"]) 17 - .nullish(), 12 + p: z.enum(PAGE_TYPES).nullish(), 18 13 q: z.string().nullish(), 19 14 }); 20 15 ··· 56 51 const { p, q } = params; 57 52 let results: MDXData[] = []; 58 53 59 - if (p === "blog") { 60 - results = getBlogPosts(); 61 - } else if (p === "changelog") { 62 - results = getChangelogPosts(); 63 - } else if (p === "tools") { 64 - results = getToolsPages().filter((tool) => tool.slug !== "checker-slug"); 65 - } else if (p === "compare") { 66 - results = getComparePages(); 54 + if (p === "tools") { 55 + results = getPages("tools").filter((tool) => tool.slug !== "checker-slug"); 67 56 } else if (p === "product") { 68 57 const home = getHomePage(); 69 58 // NOTE: we override /home with / for the home.mdx file 70 59 home.href = "/"; 71 60 home.metadata.title = "Homepage"; 72 - results = [home, ...getProductPages()]; 61 + results = [home, ...getPages("product")]; 73 62 } else if (p === "all") { 74 63 const home = getHomePage(); 75 64 // NOTE: we override /home with / for the home.mdx file 76 65 home.href = "/"; 77 66 home.metadata.title = "Homepage"; 78 67 results = [ 79 - ...getBlogPosts(), 80 - ...getChangelogPosts(), 81 - ...getToolsPages().filter((tool) => tool.slug !== "checker-slug"), 82 - ...getComparePages(), 83 - ...getProductPages(), 68 + ...getPages("blog"), 69 + ...getPages("changelog"), 70 + ...getPages("tools").filter((tool) => tool.slug !== "checker-slug"), 71 + ...getPages("compare"), 72 + ...getPages("product"), 84 73 home, 85 74 ]; 75 + } else { 76 + if (p) results = getPages(p); 86 77 } 87 78 88 79 const searchMap = new Map<
+8 -3
apps/web/src/content/cmdk.tsx
··· 57 57 }, 58 58 { 59 59 type: "item", 60 + label: "Go to Home", 61 + href: "/", 62 + }, 63 + { 64 + type: "item", 60 65 label: "Go to Pricing", 61 66 href: "/pricing", 62 67 }, ··· 259 264 )} 260 265 onClick={() => setOpen(true)} 261 266 > 262 - <span className="truncate"> 263 - Search<span className="text-muted-foreground text-xs">...</span> 267 + <span className="truncate text-muted-foreground"> 268 + Search<span className="text-xs">...</span> 264 269 </span> 265 - <kbd className="ml-auto bg-muted text-muted-foreground pointer-events-none inline-flex h-5 items-center gap-1 border px-1.5 font-mono text-[10px] font-medium opacity-100 select-none"> 270 + <kbd className="pointer-events-none ml-auto inline-flex h-5 select-none items-center gap-1 border bg-muted px-1.5 font-medium font-mono text-[10px] text-muted-foreground opacity-100"> 266 271 <span className="text-xs">⌘</span>K 267 272 </kbd> 268 273 </button>
+40
apps/web/src/content/utils.ts
··· 144 144 ); 145 145 } 146 146 147 + export const PAGE_TYPES = [ 148 + "blog", 149 + "changelog", 150 + "product", 151 + "unrelated", 152 + "compare", 153 + "tools", 154 + "all", 155 + ] as const; 156 + 157 + export type PageType = (typeof PAGE_TYPES)[number]; 158 + 159 + export function getPages(type: PageType) { 160 + switch (type) { 161 + case "blog": 162 + return getBlogPosts(); 163 + case "changelog": 164 + return getChangelogPosts(); 165 + case "product": 166 + return getProductPages(); 167 + case "unrelated": 168 + return getUnrelatedPages(); 169 + case "compare": 170 + return getComparePages(); 171 + case "tools": 172 + return getToolsPages(); 173 + case "all": 174 + return [ 175 + ...getBlogPosts(), 176 + ...getChangelogPosts(), 177 + ...getProductPages(), 178 + ...getUnrelatedPages(), 179 + ...getComparePages(), 180 + ...getToolsPages(), 181 + ]; 182 + default: 183 + throw new Error(`Unknown page type: ${type}`); 184 + } 185 + } 186 + 147 187 export function getCategories() { 148 188 return [ 149 189 ...new Set([