Skip to content

Open-source status page, incident response and uptime monitoring

chore: cmdk nit (#1674)

Maximilian Kaske15fc6e1d5829
diff --git a/apps/web/src/app/api/search/route.ts b/apps/web/src/app/api/search/route.ts
index 9a6209112..38fd4ae15 100644
--- a/apps/web/src/app/api/search/route.ts
+++ b/apps/web/src/app/api/search/route.ts
@@ -1,20 +1,15 @@
import { slugify } from "@/content/mdx";
import {
type MDXData,
- getBlogPosts,
- getChangelogPosts,
- getComparePages,
+ PAGE_TYPES,
getHomePage,
- getProductPages,
- getToolsPages,
+ getPages,
} from "@/content/utils";
import sanitizeHtml from "sanitize-html";
import { z } from "zod";
const SearchSchema = z.object({
- p: z
- .enum(["blog", "changelog", "tools", "compare", "product", "all"])
- .nullish(),
+ p: z.enum(PAGE_TYPES).nullish(),
q: z.string().nullish(),
});
@@ -56,33 +51,29 @@ function search(params: SearchParams) {
const { p, q } = params;
let results: MDXData[] = [];
- if (p === "blog") {
- results = getBlogPosts();
- } else if (p === "changelog") {
- results = getChangelogPosts();
- } else if (p === "tools") {
- results = getToolsPages().filter((tool) => tool.slug !== "checker-slug");
- } else if (p === "compare") {
- results = getComparePages();
+ if (p === "tools") {
+ results = getPages("tools").filter((tool) => tool.slug !== "checker-slug");
} else if (p === "product") {
const home = getHomePage();
// NOTE: we override /home with / for the home.mdx file
home.href = "/";
home.metadata.title = "Homepage";
- results = [home, ...getProductPages()];
+ results = [home, ...getPages("product")];
} else if (p === "all") {
const home = getHomePage();
// NOTE: we override /home with / for the home.mdx file
home.href = "/";
home.metadata.title = "Homepage";
results = [
- ...getBlogPosts(),
- ...getChangelogPosts(),
- ...getToolsPages().filter((tool) => tool.slug !== "checker-slug"),
- ...getComparePages(),
- ...getProductPages(),
+ ...getPages("blog"),
+ ...getPages("changelog"),
+ ...getPages("tools").filter((tool) => tool.slug !== "checker-slug"),
+ ...getPages("compare"),
+ ...getPages("product"),
home,
];
+ } else {
+ if (p) results = getPages(p);
}
const searchMap = new Map<
diff --git a/apps/web/src/content/cmdk.tsx b/apps/web/src/content/cmdk.tsx
index 429592053..10a82662b 100644
--- a/apps/web/src/content/cmdk.tsx
+++ b/apps/web/src/content/cmdk.tsx
@@ -55,6 +55,11 @@ const CONFIG: ConfigSection[] = [
heading: "All pages",
page: "all",
},
+ {
+ type: "item",
+ label: "Go to Home",
+ href: "/",
+ },
{
type: "item",
label: "Go to Pricing",
@@ -259,10 +264,10 @@ export function CmdK() {
)}
onClick={() => setOpen(true)}
>
- <span className="truncate">
- Search<span className="text-muted-foreground text-xs">...</span>
+ <span className="truncate text-muted-foreground">
+ Search<span className="text-xs">...</span>
</span>
- <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">
+ <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">
<span className="text-xs">⌘</span>K
</kbd>
</button>
diff --git a/apps/web/src/content/utils.ts b/apps/web/src/content/utils.ts
index f77803c29..f8dfee0fa 100644
--- a/apps/web/src/content/utils.ts
+++ b/apps/web/src/content/utils.ts
@@ -144,6 +144,46 @@ export function getToolsPage(slug: string): MDXData {
);
}
+export const PAGE_TYPES = [
+ "blog",
+ "changelog",
+ "product",
+ "unrelated",
+ "compare",
+ "tools",
+ "all",
+] as const;
+
+export type PageType = (typeof PAGE_TYPES)[number];
+
+export function getPages(type: PageType) {
+ switch (type) {
+ case "blog":
+ return getBlogPosts();
+ case "changelog":
+ return getChangelogPosts();
+ case "product":
+ return getProductPages();
+ case "unrelated":
+ return getUnrelatedPages();
+ case "compare":
+ return getComparePages();
+ case "tools":
+ return getToolsPages();
+ case "all":
+ return [
+ ...getBlogPosts(),
+ ...getChangelogPosts(),
+ ...getProductPages(),
+ ...getUnrelatedPages(),
+ ...getComparePages(),
+ ...getToolsPages(),
+ ];
+ default:
+ throw new Error(`Unknown page type: ${type}`);
+ }
+}
+
export function getCategories() {
return [
...new Set([