Skip to content

Commit b14553a

Browse files
Merge pull request #534 from aspeddro/new-doc-search
add DocSearch v3
2 parents e0b809a + 6f43723 commit b14553a

File tree

10 files changed

+1081
-306
lines changed

10 files changed

+1081
-306
lines changed

package-lock.json

Lines changed: 517 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
}
1616
},
1717
"dependencies": {
18+
"@docsearch/react": "^3.5.2",
1819
"@headlessui/react": "^1.2.0",
1920
"@mdx-js/loader": "^2.3.0",
2021
"@rescript/react": "^0.12.0-alpha.3",

pages/_document.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,7 @@ const isProduction = process.env.ENV === "production";
66
export default function Document() {
77
return (
88
<Html>
9-
<Head>
10-
<link
11-
rel="stylesheet"
12-
href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css"
13-
/>
14-
<script
15-
type="text/javascript"
16-
src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"
17-
/>
18-
</Head>
9+
<Head />
1910
<body>
2011
<Main />
2112
<NextScript />

src/bindings/DocSearch.res

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// API: https://github.com/algolia/docsearch/tree/v3.5.2/packages/docsearch-react/src/types
2+
type contentType =
3+
| @as("content") Content
4+
| @as("lvl0") Lvl0
5+
| @as("lvl1") Lvl1
6+
| @as("lvl2") Lvl2
7+
| @as("lvl3") Lvl3
8+
| @as("lvl4") Lvl4
9+
| @as("lvl5") Lvl5
10+
| @as("lvl6") Lvl6
11+
12+
type hierarchy = {
13+
lvl0: string,
14+
lvl1: string,
15+
lvl2: Js.Nullable.t<string>,
16+
lvl3: Js.Nullable.t<string>,
17+
lvl4: Js.Nullable.t<string>,
18+
lvl5: Js.Nullable.t<string>,
19+
lvl6: Js.Nullable.t<string>,
20+
}
21+
22+
type docSearchHit = {
23+
objectID: string,
24+
content: Js.Nullable.t<string>,
25+
url: string,
26+
url_without_anchor: string,
27+
@as("type") type_: contentType,
28+
anchor: Js.Nullable.t<string>,
29+
hierarchy: hierarchy,
30+
// NOTE: docsearch need these two fields to highlight results
31+
_highlightResult: {.},
32+
_snippetResult: {.},
33+
}
34+
type transformItems = array<docSearchHit>
35+
36+
type hitComponent = {
37+
hit: docSearchHit,
38+
children: React.element,
39+
}
40+
41+
type item = {itemUrl: string}
42+
43+
type navigator = {navigate: item => unit}
44+
45+
type searchParameters = {facetFilters: array<string>}
46+
47+
@module("@docsearch/react") @react.component
48+
external make: (
49+
~appId: string,
50+
~indexName: string,
51+
~apiKey: string,
52+
~transformItems: transformItems => transformItems=?,
53+
~hitComponent: hitComponent => React.element=?,
54+
~navigator: navigator=?,
55+
~onClose: unit => unit=?,
56+
~searchParameters: searchParameters=?,
57+
~initialScrollY: int=?,
58+
) => React.element = "DocSearchModal"

src/bindings/Webapi.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Document = {
66
module ClassList = {
77
type t
88
@send external toggle: (t, string) => unit = "toggle"
9+
@send external remove: (t, string) => unit = "remove"
910
}
1011

1112
module Element = {
@@ -14,6 +15,7 @@ module Element = {
1415
@set external setClassName: (Dom.element, string) => unit = "className"
1516
@get external classList: Dom.element => ClassList.t = "classList"
1617
@send external getBoundingClientRect: Dom.element => {..} = "getBoundingClientRect"
18+
@send external addEventListener: (Dom.element, string, unit => unit) => unit = "addEventListener"
1719

1820
module Style = {
1921
@scope("style") @set external width: (Dom.element, string) => unit = "width"

src/components/DocSearch.res

Lines changed: 0 additions & 213 deletions
This file was deleted.

src/components/DocSearch.resi

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/components/Navigation.res

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,6 @@ module MobileNav = {
372372
let extLink = "block hover:cursor-pointer hover:text-white text-gray-60"
373373
<div className="border-gray-80 border-t">
374374
<ul>
375-
<li className=base>
376-
<DocSearch.Textbox id="docsearch-mobile" />
377-
</li>
378375
<li className=base>
379376
<Link href="/try" className={linkOrActiveLink(~target="/try", ~route)}>
380377
{React.string("Playground")}
@@ -521,7 +518,7 @@ let make = (~fixed=true, ~overlayState: (bool, (bool => bool) => unit)) => {
521518
ref={ReactDOM.Ref.domRef(navRef)}
522519
id="header"
523520
style={ReactDOMStyle.make(~minWidth, ())}
524-
className={fixedNav ++ " z-50 px-4 flex xs:justify-center w-full h-16 bg-gray-90 shadow text-white-80 text-14"}>
521+
className={fixedNav ++ " items-center z-50 px-4 flex xs:justify-center w-full h-16 bg-gray-90 shadow text-white-80 text-14"}>
525522
<div className="flex justify-between items-center h-full w-full max-w-1280">
526523
<div className="h-8 w-8 lg:h-10 lg:w-32">
527524
<a
@@ -557,22 +554,22 @@ let make = (~fixed=true, ~overlayState: (bool, (bool => bool) => unit)) => {
557554
{React.string("Community")}
558555
</Link>
559556
</div>
560-
<div className="hidden md:flex items-center">
561-
<div className="hidden sm:block mr-6">
562-
<DocSearch />
557+
<div className="md:flex flex items-center">
558+
<Search />
559+
<div className="hidden md:flex items-center ml-5">
560+
<a href=githubHref rel="noopener noreferrer" className={"mr-5 " ++ link}>
561+
<Icon.GitHub className="w-6 h-6 opacity-50 hover:opacity-100" />
562+
</a>
563+
<a
564+
href="https://twitter.com/rescriptlang"
565+
rel="noopener noreferrer"
566+
className={"mr-5 " ++ link}>
567+
<Icon.Twitter className="w-6 h-6 opacity-50 hover:opacity-100" />
568+
</a>
569+
<a href=discourseHref rel="noopener noreferrer" className=link>
570+
<Icon.Discourse className="w-6 h-6 opacity-50 hover:opacity-100" />
571+
</a>
563572
</div>
564-
<a href=githubHref rel="noopener noreferrer" className={"mr-5 " ++ link}>
565-
<Icon.GitHub className="w-6 h-6 opacity-50 hover:opacity-100" />
566-
</a>
567-
<a
568-
href="https://twitter.com/rescriptlang"
569-
rel="noopener noreferrer"
570-
className={"mr-5 " ++ link}>
571-
<Icon.Twitter className="w-6 h-6 opacity-50 hover:opacity-100" />
572-
</a>
573-
<a href=discourseHref rel="noopener noreferrer" className=link>
574-
<Icon.Discourse className="w-6 h-6 opacity-50 hover:opacity-100" />
575-
</a>
576573
</div>
577574
</div>
578575
</div>

0 commit comments

Comments
 (0)