Skip to content

add DocSearch v3 #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f0ad46f
add docsearchv3
aspeddro Jun 24, 2022
996c903
update docsearc
aspeddro Jul 16, 2022
827691c
Merge branch 'master' into new-doc-search
aspeddro Dec 8, 2022
8cd42e8
initial refactor
aspeddro Dec 9, 2022
2bedb25
Merge branch 'master' into new-doc-search
aspeddro Jan 17, 2023
ff971ae
refactor update
aspeddro Jan 17, 2023
ee88111
remove .mjs files
aspeddro Jan 17, 2023
682fd43
update packge-lock.json
aspeddro Jan 17, 2023
d30048f
format
aspeddro Jan 17, 2023
74f825a
revert deleted script/generate_feed.mjs
aspeddro Jan 17, 2023
432662b
remove hitComponent and update css
aspeddro Jan 18, 2023
07109fc
fix close button
aspeddro Jan 19, 2023
2e22535
add fallback when content is null
aspeddro Feb 1, 2023
aad0de1
Merge branch 'master' into new-doc-search
aspeddro Feb 2, 2023
5b7c22e
Merge branch 'master' into new-doc-search
aspeddro Nov 3, 2023
fa9ff78
update
aspeddro Nov 9, 2023
e45e96f
update ui
aspeddro Nov 12, 2023
4d77cdb
remove metatag docsearch
aspeddro Nov 12, 2023
3b3f8cb
add community desc
aspeddro Nov 12, 2023
431097d
show results for the version you are browsing
aspeddro Nov 12, 2023
3fd4d22
Merge branch 'master' into new-doc-search
aspeddro Dec 5, 2023
236d543
add animation on open/close
aspeddro Dec 9, 2023
1692899
Merge branch 'master' into new-doc-search
aspeddro Jan 7, 2024
4afbded
Merge branch 'master' into new-doc-search
aspeddro Jan 31, 2024
ff2c51c
add new api key
aspeddro Feb 1, 2024
7c10005
Merge branch 'master' into new-doc-search
aspeddro Feb 1, 2024
7f0afbd
remove redundant Util.Url.make
aspeddro Feb 1, 2024
27be7f1
remove comment
aspeddro Feb 1, 2024
39bb72c
update
aspeddro Feb 3, 2024
6f43723
add search parameters
aspeddro Feb 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
539 changes: 517 additions & 22 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
}
},
"dependencies": {
"@docsearch/react": "^3.5.2",
"@headlessui/react": "^1.2.0",
"@mdx-js/loader": "^2.3.0",
"@rescript/react": "^0.12.0-alpha.3",
Expand Down
11 changes: 1 addition & 10 deletions pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ const isProduction = process.env.ENV === "production";
export default function Document() {
return (
<Html>
<Head>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css"
/>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"
/>
</Head>
<Head />
<body>
<Main />
<NextScript />
Expand Down
58 changes: 58 additions & 0 deletions src/bindings/DocSearch.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// API: https://github.com/algolia/docsearch/tree/v3.5.2/packages/docsearch-react/src/types
type contentType =
| @as("content") Content
| @as("lvl0") Lvl0
| @as("lvl1") Lvl1
| @as("lvl2") Lvl2
| @as("lvl3") Lvl3
| @as("lvl4") Lvl4
| @as("lvl5") Lvl5
| @as("lvl6") Lvl6

type hierarchy = {
lvl0: string,
lvl1: string,
lvl2: Js.Nullable.t<string>,
lvl3: Js.Nullable.t<string>,
lvl4: Js.Nullable.t<string>,
lvl5: Js.Nullable.t<string>,
lvl6: Js.Nullable.t<string>,
}

type docSearchHit = {
objectID: string,
content: Js.Nullable.t<string>,
url: string,
url_without_anchor: string,
@as("type") type_: contentType,
anchor: Js.Nullable.t<string>,
hierarchy: hierarchy,
// NOTE: docsearch need these two fields to highlight results
_highlightResult: {.},
_snippetResult: {.},
}
type transformItems = array<docSearchHit>

type hitComponent = {
hit: docSearchHit,
children: React.element,
}

type item = {itemUrl: string}

type navigator = {navigate: item => unit}

type searchParameters = {facetFilters: array<string>}

@module("@docsearch/react") @react.component
external make: (
~appId: string,
~indexName: string,
~apiKey: string,
~transformItems: transformItems => transformItems=?,
~hitComponent: hitComponent => React.element=?,
~navigator: navigator=?,
~onClose: unit => unit=?,
~searchParameters: searchParameters=?,
~initialScrollY: int=?,
) => React.element = "DocSearchModal"
2 changes: 2 additions & 0 deletions src/bindings/Webapi.res
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Document = {
module ClassList = {
type t
@send external toggle: (t, string) => unit = "toggle"
@send external remove: (t, string) => unit = "remove"
}

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

module Style = {
@scope("style") @set external width: (Dom.element, string) => unit = "width"
Expand Down
213 changes: 0 additions & 213 deletions src/components/DocSearch.res

This file was deleted.

7 changes: 0 additions & 7 deletions src/components/DocSearch.resi

This file was deleted.

35 changes: 16 additions & 19 deletions src/components/Navigation.res
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,6 @@ module MobileNav = {
let extLink = "block hover:cursor-pointer hover:text-white text-gray-60"
<div className="border-gray-80 border-t">
<ul>
<li className=base>
<DocSearch.Textbox id="docsearch-mobile" />
</li>
<li className=base>
<Link href="/try" className={linkOrActiveLink(~target="/try", ~route)}>
{React.string("Playground")}
Expand Down Expand Up @@ -521,7 +518,7 @@ let make = (~fixed=true, ~overlayState: (bool, (bool => bool) => unit)) => {
ref={ReactDOM.Ref.domRef(navRef)}
id="header"
style={ReactDOMStyle.make(~minWidth, ())}
className={fixedNav ++ " z-50 px-4 flex xs:justify-center w-full h-16 bg-gray-90 shadow text-white-80 text-14"}>
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"}>
<div className="flex justify-between items-center h-full w-full max-w-1280">
<div className="h-8 w-8 lg:h-10 lg:w-32">
<a
Expand Down Expand Up @@ -557,22 +554,22 @@ let make = (~fixed=true, ~overlayState: (bool, (bool => bool) => unit)) => {
{React.string("Community")}
</Link>
</div>
<div className="hidden md:flex items-center">
<div className="hidden sm:block mr-6">
<DocSearch />
<div className="md:flex flex items-center">
<Search />
<div className="hidden md:flex items-center ml-5">
<a href=githubHref rel="noopener noreferrer" className={"mr-5 " ++ link}>
<Icon.GitHub className="w-6 h-6 opacity-50 hover:opacity-100" />
</a>
<a
href="https://twitter.com/rescriptlang"
rel="noopener noreferrer"
className={"mr-5 " ++ link}>
<Icon.Twitter className="w-6 h-6 opacity-50 hover:opacity-100" />
</a>
<a href=discourseHref rel="noopener noreferrer" className=link>
<Icon.Discourse className="w-6 h-6 opacity-50 hover:opacity-100" />
</a>
</div>
<a href=githubHref rel="noopener noreferrer" className={"mr-5 " ++ link}>
<Icon.GitHub className="w-6 h-6 opacity-50 hover:opacity-100" />
</a>
<a
href="https://twitter.com/rescriptlang"
rel="noopener noreferrer"
className={"mr-5 " ++ link}>
<Icon.Twitter className="w-6 h-6 opacity-50 hover:opacity-100" />
</a>
<a href=discourseHref rel="noopener noreferrer" className=link>
<Icon.Discourse className="w-6 h-6 opacity-50 hover:opacity-100" />
</a>
</div>
</div>
</div>
Expand Down
Loading