diff --git a/netlify.toml b/netlify.toml index 5543eca..40696b4 100644 --- a/netlify.toml +++ b/netlify.toml @@ -4,4 +4,5 @@ [[plugins]] package = "@algolia/netlify-plugin-crawler" [plugins.inputs] - renderJavaScript = true \ No newline at end of file + renderJavaScript = true + template = "hierarchical" \ No newline at end of file diff --git a/package.json b/package.json index 2e44b8b..626c52b 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@mdx-js/rollup": "^2.2.1", "@stefanprobst/rehype-extract-toc": "^2.2.0", "@types/mdx": "^2.0.3", + "algoliasearch": "^4.14.3", "bootstrap": "4.5.3", "classnames": "^2.3.2", "cron": "^2.2.0", diff --git a/src/App.tsx b/src/App.tsx index 06a7f65..a6cfcda 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -22,6 +22,10 @@ import { isProd } from "./lib/isProd"; import ReactGA from "react-ga"; import { useUser } from "./user-context"; import PrivacyPolicy from "./pages/PrivacyPolicy"; +import algoliasearch from "algoliasearch"; + +const client = algoliasearch('M5GQZF38JA', '1e3b529b909acf72fde1515f520f3913'); +const index = client.initIndex('netlify_150beb8b-aae1-4cef-a05c-2add5d8904f7_master_all'); const chapters = content.reduce((chapters, item) => ( item.content @@ -36,6 +40,7 @@ if (isProd) { function App(props: any) { const [navOpen, setNavOpen] = useState(false); + const [search, setSearch] = useState(""); const navigate = useNavigate(); const { user } = useUser(); function logAnalytics() { @@ -59,6 +64,16 @@ function App(props: any) { logAnalytics(); // eslint-disable-next-line }, [window.location.pathname]); + function handleSearch(s: string) { + setSearch(s); + index.search(s, { + attributesToSnippet: [ + "content:20", + ], + }).then(({ hits }) => { + console.log(hits); + }); + } return ( <>
@@ -70,6 +85,7 @@ function App(props: any) { setNavOpen={setNavOpen} pathname={window.location.pathname} /> + handleSearch(e.target.value)} value={search} />