-
Notifications
You must be signed in to change notification settings - Fork 45
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
Incorporate Algolia-based search #642
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/palette-docs/plugins/gatsby-plugin-local-algolia-docsearch/gatsby-ssr.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const React = require("react") | ||
|
||
exports.onRenderBody = ( | ||
{ setHeadComponents, setPostBodyComponents }, | ||
{ apiKey, indexName, debug = false } | ||
) => { | ||
setHeadComponents([ | ||
<link | ||
key="docsearch-css" | ||
rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" | ||
/>, | ||
]) | ||
|
||
setPostBodyComponents([ | ||
<script | ||
key="docsearch-js" | ||
type="text/javascript" | ||
src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js" | ||
/>, | ||
<script | ||
key="docsearch-settings" | ||
type="text/javascript" | ||
dangerouslySetInnerHTML={{ | ||
__html: `window.docsearchSettings = { | ||
apiKey: "${apiKey}", indexName: "${indexName}", debug: ${debug}}`, | ||
}} | ||
/>, | ||
]) | ||
} |
1 change: 1 addition & 0 deletions
1
packages/palette-docs/plugins/gatsby-plugin-local-algolia-docsearch/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// noop |
3 changes: 3 additions & 0 deletions
3
packages/palette-docs/plugins/gatsby-plugin-local-algolia-docsearch/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "gatsby-plugin-local-algolia-docsearch" | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/palette-docs/src/components/Sidebar/SearchBox.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Input } from "@artsy/palette" | ||
import React, { useEffect } from "react" | ||
import "./algolia.css" | ||
|
||
declare global { | ||
interface Window { | ||
docsearch: any | ||
docsearchSettings: any | ||
} | ||
} | ||
|
||
export function SearchBox() { | ||
useEffect(() => { | ||
if (window.docsearchSettings === undefined) { | ||
return | ||
} | ||
window.docsearch({ | ||
apiKey: window.docsearchSettings.apiKey, | ||
indexName: window.docsearchSettings.indexName, | ||
inputSelector: "#search", | ||
debug: window.docsearchSettings.indexName, | ||
}) | ||
}, []) | ||
return <Input id="search" placeholder="Search docs" /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* Main overlay */ | ||
.algolia-autocomplete .ds-dropdown-menu { | ||
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.15); | ||
} | ||
|
||
/* Category links */ | ||
.algolia-autocomplete .ds-dropdown-menu .ds-suggestions a { | ||
text-decoration: none; | ||
} | ||
.algolia-autocomplete .ds-dropdown-menu .ds-suggestions a:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
/* Main category (eg. Getting Started) */ | ||
.algolia-autocomplete .algolia-docsearch-suggestion--category-header { | ||
border-bottom: 1px solid #e5e5e5; | ||
font-size: 1.2em; | ||
} | ||
|
||
/* Category (eg. Downloads) */ | ||
.algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { | ||
color: #666; | ||
} | ||
|
||
/* Title (eg. Bootstrap CDN) */ | ||
.algolia-autocomplete .algolia-docsearch-suggestion--title { | ||
font-weight: bold; | ||
color: #000; | ||
} | ||
|
||
/* Description (eg. Bootstrap currently works...) */ | ||
.algolia-autocomplete .algolia-docsearch-suggestion--text { | ||
color: #000; | ||
} | ||
|
||
/* Highlighted text */ | ||
.algolia-autocomplete | ||
.algolia-docsearch-suggestion--category-header | ||
.algolia-docsearch-suggestion--category-header-lvl0 | ||
.algolia-docsearch-suggestion--highlight, | ||
.algolia-autocomplete | ||
.algolia-docsearch-suggestion--category-header | ||
.algolia-docsearch-suggestion--category-header-lvl1 | ||
.algolia-docsearch-suggestion--highlight, | ||
.algolia-autocomplete | ||
.algolia-docsearch-suggestion--text | ||
.algolia-docsearch-suggestion--highlight { | ||
color: #6e1eff; | ||
box-shadow: inset 0 -2px 0 0 #6e1eff; | ||
} | ||
|
||
/* Selected descriptions */ | ||
.algolia-autocomplete | ||
.ds-dropdown-menu | ||
.ds-suggestion.ds-cursor | ||
.algolia-docsearch-suggestion.suggestion-layout-simple, | ||
.algolia-autocomplete | ||
.ds-dropdown-menu | ||
.ds-suggestion.ds-cursor | ||
.algolia-docsearch-suggestion:not(.suggestion-layout-simple) | ||
.algolia-docsearch-suggestion--content { | ||
background-color: #f8f8f8; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to make this plugin work with ES module syntax, but it isn't something that bothers me. If it bothers anyone else, maybe we could pair on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ES module syntax doesn't work completely in gatsby yet. Caused a bit of stress trying to figure that out when i was working on this before because it kinda worked at times, and was confusing.