Skip to content

Commit

Permalink
Rough implementation of algolia-based search box
Browse files Browse the repository at this point in the history
  • Loading branch information
pepopowitz committed Feb 21, 2020
1 parent 876bd65 commit 39183e6
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/palette-docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,16 @@ module.exports = {
"gatsby-plugin-styled-components",
"gatsby-plugin-typescript",
"gatsby-plugin-sitemap",
{
// Currently this plugin is only being used to hook up the script & css, so the options don't matter a whole lot.
// We could probably just implement the few bits that work for our scenario instead.
resolve: `gatsby-plugin-algolia-docsearch`, //require.resolve("./gatsby-algolia-search.js"),
options: {
apiKey: "it-doesnt-matter-not-using-it", // required
indexName: "it-doesnt-matter-not-using-it", // required
inputSelector: ".it-doesnt-matter-not-using-it", // required
debug: true, // (bool)Optional. Default `false`
},
},
],
}
17 changes: 17 additions & 0 deletions packages/palette-docs/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
import React from "react"

/**
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
Expand All @@ -8,3 +9,19 @@
import { Boot } from "./src/Boot"

export const wrapRootElement = Boot

export function onRenderBody(
{ setHeadComponents, setPostBodyComponents },
{ apiKey, indexName, inputSelector, debug = false }
) {
setPostBodyComponents([
<script
key="plugin-docsearch-initiate"
type="text/javascript"
dangerouslySetInnerHTML={{
// I figure I can pull these values from gatsby-config.js somehow.
__html: `window.docsearchSettings = {apiKey: "e4ea4437446d07b0549e0db7928d92d1", indexName: "artsy_palette"}`,
}}
/>,
])
}
1 change: 1 addition & 0 deletions packages/palette-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"gatsby": "2.3.34",
"gatsby-image": "^2.0.20",
"gatsby-mdx": "^0.3.4",
"gatsby-plugin-algolia-docsearch": "^1.0.5",
"gatsby-plugin-catch-links": "^2.0.10",
"gatsby-plugin-force-trailing-slashes": "^1.0.4",
"gatsby-plugin-manifest": "^2.0.9",
Expand Down
15 changes: 15 additions & 0 deletions packages/palette-docs/src/components/Sidebar/SearchBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Input } from "@artsy/palette"
import React, { useEffect } from "react"

export function SearchBox() {
useEffect(() => {
console.log("doing the thing with ", window.docsearchSettings)
docsearch({
apiKey: window.docsearchSettings.apiKey,
indexName: window.docsearchSettings.indexName,
inputSelector: "#search",
debug: "false",
})
}, [])
return <Input id="search" placeholder="Search docs" />
}
2 changes: 2 additions & 0 deletions packages/palette-docs/src/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import styled from "styled-components"
import { NavTree } from "./NavTree"

import { ArtsyMarkBlackIcon, Box, Sans, Serif } from "@artsy/palette"
import { SearchBox } from "./SearchBox"

export const Sidebar = _props => {
return (
Expand All @@ -12,6 +13,7 @@ export const Sidebar = _props => {
<Serif size="4">Palette</Serif>
</Link>

<SearchBox />
<Box mt={2} mb={4}>
<NavTree />
</Box>
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10719,6 +10719,13 @@ gatsby-mdx@^0.3.4:
unist-util-remove "^1.0.1"
unist-util-visit "^1.4.0"

gatsby-plugin-algolia-docsearch@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/gatsby-plugin-algolia-docsearch/-/gatsby-plugin-algolia-docsearch-1.0.5.tgz#d6dea17deda8c8bf9ac8cd3e1fb8f6bf6591db01"
integrity sha512-2oylL3ioy22Cu24zP8SpanK09SlP8i3p1j9CQ2rTXJgdNmsK2QhqymaLOGBvzGDMpPRn1qJszlNz/EUNAHafjg==
dependencies:
"@babel/runtime" "^7.0.0"

gatsby-plugin-catch-links@^2.0.10:
version "2.0.13"
resolved "https://registry.yarnpkg.com/gatsby-plugin-catch-links/-/gatsby-plugin-catch-links-2.0.13.tgz#b49bb1e2383881cffca86a428348a7afdb6c3dd4"
Expand Down

0 comments on commit 39183e6

Please sign in to comment.