Skip to content

Commit 7fe0840

Browse files
committed
feat: add DocSearch integration
1 parent db8f864 commit 7fe0840

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

.env.sample

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ export PORT=3000
33

44
# Simulate a Vercel deployment environment on a specific branch
55
# export VERCEL_GIT_COMMIT_REF=tip
6+
7+
8+
# Algolia's DocSearch config
9+
NEXT_PUBLIC_DOCSEARCH_APP_ID=
10+
NEXT_PUBLIC_DOCSEARCH_API_KEY=
11+
NEXT_PUBLIC_DOCSEARCH_INDEX=

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"zustand": "^5.0.2"
3030
},
3131
"devDependencies": {
32+
"@docsearch/css": "^4.1.0",
33+
"@docsearch/js": "^4.1.0",
3234
"@types/klaw-sync": "^6.0.5",
3335
"@types/node": "20.14.13",
3436
"@types/react": "18.3.3",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.docsearch {
2+
display: flex;
3+
justify-content: flex-end;
4+
flex: 1;
5+
padding: 0 30px;
6+
7+
:global(.DocSearch-Button-Key) {
8+
/* The default mix is at 20%, which is too subtle */
9+
border-color: color-mix(in srgb, var(--docsearch-subtle-color) 70%, transparent);
10+
}
11+
12+
@media(max-width: 768px) {
13+
padding-right: 0;
14+
15+
:global(.DocSearch-Button) {
16+
border: 0;
17+
}
18+
}
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use client";
2+
3+
import { useEffect } from "react";
4+
import docsearch from "@docsearch/js";
5+
import "@docsearch/css";
6+
import s from "./DocSearch.module.css";
7+
8+
export default function DocSearch() {
9+
useEffect(() => {
10+
if (process.env.NEXT_PUBLIC_DOCSEARCH_APP_ID
11+
&& process.env.NEXT_PUBLIC_DOCSEARCH_INDEX
12+
&& process.env.NEXT_PUBLIC_DOCSEARCH_API_KEY
13+
) {
14+
docsearch({
15+
container: "#docsearch",
16+
appId: process.env.NEXT_PUBLIC_DOCSEARCH_APP_ID,
17+
indexName: process.env.NEXT_PUBLIC_DOCSEARCH_INDEX,
18+
apiKey: process.env.NEXT_PUBLIC_DOCSEARCH_API_KEY,
19+
})
20+
}
21+
}, []);
22+
23+
return <div className={s.docsearch}>
24+
<div id="docsearch" />
25+
</div>;
26+
};

src/components/navbar/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import NavTree, { BreakNode, LinkNode, NavTreeNode } from "../nav-tree";
1010
import GhosttyWordmark from "./ghostty-wordmark.svg";
1111
import s from "./Navbar.module.css";
1212
import { useRouter } from "next/router";
13+
import DocSearch from "@/components/doc-search";
1314

1415
export interface NavbarProps {
1516
className?: string;
@@ -94,6 +95,7 @@ export default function Navbar({
9495
<NextLink href="/">
9596
<Image src={GhosttyWordmark} alt="Ghostty" />
9697
</NextLink>
98+
<DocSearch />
9799
<div className={s.desktopLinks}>
98100
{links && (
99101
<ul className={s.linkList}>

src/styles/globals.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ body {
6565
--callout-important: var(--atom-one-purple);
6666
--callout-warning: var(--atom-one-yellow);
6767
--callout-caution: var(--atom-one-red);
68+
69+
/* DocSearch customizations */
70+
--docsearch-primary-color: var(--brand-color);
71+
--docsearch-text-color: var(--gray-4);
72+
--docsearch-subtle-color: var(--gray-2);
73+
--docsearch-icon-color: var(--brand-color);
74+
--docsearch-background-color: var(--gray-1);
75+
--docsearch-modal-background: var(--gray-0);
76+
--docsearch-searchbox-focus-background: var(--gray-1);
77+
--docsearch-searchbox-background: var(--gray-0);
78+
--docsearch-footer-background: #1f2937;
79+
--docsearch-hit-background: #374151;
80+
--docsearch-hit-color: #f9fafb;
81+
--docsearch-key-background: transparent;
82+
--docsearch-hit-shadow: none;
6883
}
6984

7085
/* This a slightly modified atom-one-dark theme */

0 commit comments

Comments
 (0)