Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b7eace7

Browse files
committedSep 6, 2018
Trying to fix docsearch
1 parent 5c76fb6 commit b7eace7

File tree

2 files changed

+65
-29
lines changed

2 files changed

+65
-29
lines changed
 

‎package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"version": "1.0.0",
55
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
66
"dependencies": {
7-
"@jacobmischka/gatsby-plugin-react-svg": "git+https://github.com/jacobmischka/gatsby-plugin-react-svg.git",
7+
"@jacobmischka/gatsby-plugin-react-svg":
8+
"git+https://github.com/jacobmischka/gatsby-plugin-react-svg.git",
89
"docsearch.js": "^2.5.2",
910
"gatsby": "^1.9.73",
1011
"gatsby-link": "^1.6.22",
@@ -21,17 +22,18 @@
2122
"rucksack-css": "^1.0.2",
2223
"styled-jsx-plugin-postcss": "0.1.0"
2324
},
24-
"keywords": [
25-
"gatsby"
26-
],
25+
"keywords": ["gatsby"],
2726
"license": "MIT",
2827
"main": "n/a",
2928
"scripts": {
3029
"clean": "rm -rf ./public",
3130
"create-sphinx-theme": "./scripts/create_package",
32-
"build": "yarn clean && gatsby build --prefix-paths && ./scripts/replace && yarn create-sphinx-theme",
31+
"build":
32+
"yarn clean && gatsby build --prefix-paths && ./scripts/replace && yarn create-sphinx-theme",
3333
"develop": "gatsby develop",
34-
"format": "prettier --trailing-comma es5 --no-semi --single-quote --write 'src/**/*.js'",
34+
"serve": "gatsby serve",
35+
"format":
36+
"prettier --trailing-comma es5 --no-semi --single-quote --write 'src/**/*.js'",
3537
"test": "echo \"Error: no test specified\" && exit 1"
3638
},
3739
"devDependencies": {

‎src/layouts/index.js

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,27 @@ import "./index.css";
1313

1414
const SEARCH_DOCS = true;
1515

16-
let docsearch;
17-
if (typeof window !== "undefined" && SEARCH_DOCS) {
18-
docsearch = require("docsearch.js/dist/cdn/docsearch.min");
19-
try {
20-
docsearch({
21-
apiKey: "4b6d0afa80197db35886555b5ef4721f",
22-
inputSelector: "#search-docs",
23-
indexName: "graphene_python",
24-
debug: false
25-
});
26-
} catch (e) {}
27-
} else {
28-
docsearch = false;
29-
}
16+
// let docsearch;
17+
// if (typeof window !== "undefined" && SEARCH_DOCS) {
18+
// docsearch = require("docsearch.js/dist/cdn/docsearch.min");
19+
// try {
20+
// docsearch({
21+
// apiKey: "4b6d0afa80197db35886555b5ef4721f",
22+
// inputSelector: "#search-docs",
23+
// indexName: "graphene_python",
24+
// transformData: function(suggestions) {
25+
// return suggestions.map(function(suggestion) {
26+
// suggestion.url.replace("http:", "https:");
27+
// return suggestion;
28+
// });
29+
// },
30+
// // "start_urls": ["https://www.example.com/docs"],
31+
// debug: false
32+
// });
33+
// } catch (e) {}
34+
// } else {
35+
// docsearch = false;
36+
// }
3037

3138
const HeaderLink = ({ to, children, docs, ...extra }) => {
3239
if (docs) {
@@ -45,14 +52,23 @@ const HeaderLink = ({ to, children, docs, ...extra }) => {
4552

4653
class Header extends React.Component {
4754
componentDidMount() {
48-
if (SEARCH_DOCS && docsearch) {
49-
docsearch({
50-
apiKey: "4b6d0afa80197db35886555b5ef4721f",
51-
inputSelector: "#search-docs",
52-
indexName: "graphene_python"
53-
// debug: true
54-
});
55-
}
55+
try {
56+
if (SEARCH_DOCS && typeof window !== "undefined") {
57+
let docsearch = require("docsearch.js/dist/cdn/docsearch.min");
58+
docsearch({
59+
apiKey: "4b6d0afa80197db35886555b5ef4721f",
60+
inputSelector: "#search-docs",
61+
indexName: "graphene_python",
62+
transformData: function(suggestions) {
63+
return suggestions.map(function(suggestion) {
64+
suggestion.url = suggestion.url.replace("http:", "https:");
65+
return suggestion;
66+
});
67+
}
68+
// debug: true
69+
});
70+
}
71+
} catch (e) {}
5672
}
5773
render() {
5874
let { docs } = this.props;
@@ -378,7 +394,25 @@ const TemplateWrapper = ({ children, ...otherProps }) => {
378394
{ name: "description", content: "Graphene framework for Python" },
379395
{ name: "keywords", content: "graphene, graphql, python, framework" }
380396
]}
381-
/>
397+
>
398+
<script src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js" />
399+
<script
400+
dangerouslySetInnerHTML={{
401+
__html: `
402+
docsearch({
403+
apiKey: "4b6d0afa80197db35886555b5ef4721f",
404+
inputSelector: "#search-docs",
405+
indexName: "graphene_python",
406+
transformData: function(suggestions) {
407+
return suggestions.map(function(suggestion) {
408+
suggestion.url = suggestion.url.replace("http:", "https:");
409+
return suggestion;
410+
});
411+
}
412+
});`
413+
}}
414+
/>
415+
</Helmet>
382416
<Header docs={docs} />
383417
<div>{children()}</div>
384418
</div>

0 commit comments

Comments
 (0)