Skip to content

Commit 8c28162

Browse files
committed
search integration
1 parent f28cac5 commit 8c28162

File tree

15 files changed

+289
-16
lines changed

15 files changed

+289
-16
lines changed

packages/webdoc-cli/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,44 @@ The `docs` object has options to configure the generation of the document tree.
6565
* `"scope"`: Order by scope as follows: static, instance, inner.
6666
* `"access"`: Order by access as follows: public, protected, private.
6767
* `"name"`: Order alphabetically by the simple-name.
68+
69+
### opts
70+
71+
The `opts` object has additional CLI options.
72+
73+
```json
74+
{
75+
"opts": {
76+
"destination": "docs",
77+
"export": "api.json",
78+
"template": "@webdoc/default-template"
79+
}
80+
}
81+
```
82+
83+
* `opts.destination`: (optional) The destination path for the generated documentation files.
84+
* `opts.export`: (optional) The file where the API schema is exported.
85+
* `opts.template`: (optional) The template package to use. This defaults to "@webdoc/default-template".
86+
87+
#### template
88+
89+
The `template` object is used by the site template.
90+
91+
```json
92+
{
93+
"repository": "http://github.com/webdoc-labs/webdoc",
94+
"integrations": {
95+
"search": {
96+
"provider": "algolia",
97+
"apiKey": "kadlfj232983lkqwem",
98+
"indexName": "webdoc-example",
99+
"appId": "349o39841;akdsfu"
100+
}
101+
}
102+
}
103+
```
104+
105+
* `template.repository`: (optional) This can be used to link documents to their location in the source code. The only supported repository is GitHub.
106+
* `template.integrations`: (optional) Integrations with 3rd party solutions in your template. This object is dependent on which template you're using. For @webdoc/default-template, the following integrations are available:
107+
* `search`: This is used as the backend for the global site search. You'll need to create an Algolia account yourself and provide
108+
the `apiKey`, `appId`, `indexName`. (The only supported provider is "algolia" right now)

packages/webdoc-cli/src/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ type ConfigSchema = {
4343
mode?: string
4444
},
4545
repository?: string,
46-
outputSourceFiles?: boolean
46+
outputSourceFiles?: boolean,
47+
integrations: any,
4748
},
4849
version: {
4950
number?: 1
@@ -85,6 +86,7 @@ const defaultConfig: ConfigSchema = {
8586
},
8687
repository: undefined, // ex. GitHub repo holding source files to link source files
8788
// should contain branch - https://github.com/webdoc-js/webdoc/blob/master/
89+
integrations: {},
8890
},
8991
version: {
9092
number: 1,

packages/webdoc-default-template/publish.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ function outReference(
224224
}
225225

226226
page = linker.processInternalURI(page, {outputRelative: true});
227-
228227
let doc;
229228

230229
try {

packages/webdoc-default-template/src/app/components/Explorer/ExplorerItem.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ export default function ExplorerItem(props) {
3232
const nodeId = props.data.$nodeId;
3333
const primary = props.data.page && isSamePage(props.data);
3434

35-
if (primary) {
36-
console.log(props.data);
37-
}
38-
3935
const toggle = React.useCallback(
4036
() => props.toggle(nodeId),
4137
[nodeId],

packages/webdoc-default-template/src/app/components/Header/Header.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {ExplorerHeader} from "../Explorer";
2+
import Search from "./Search";
3+
import {appData} from "../../resource";
24
import {connect} from "react-redux";
35
import store from "../../store";
46

@@ -19,6 +21,7 @@ export default connect(({explorerOpen}) => ({
1921
<div className="header__contents">
2022
<a className="header__link header__link__current">API Reference</a>
2123
<a className="header__link">Guides</a>
24+
{appData.integrations.search && <Search integration={appData.integrations.search} />}
2225
</div>
2326
</div>
2427
);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React from "react";
2+
import {getResourceURI} from "../../resource";
3+
4+
export default function Search({
5+
integration,
6+
}) {
7+
const ref = React.useRef(null);
8+
const enabled = React.useRef(false);
9+
10+
React.useEffect(
11+
() => {
12+
if (!ref.current || enabled.current) {
13+
return;
14+
}
15+
if (integration.provider === "algolia") {
16+
if (!window.docsearch) {
17+
throw new Error("docsearch should be in global scope");
18+
}
19+
20+
window.docsearch({
21+
apiKey: integration.apiKey,
22+
appId: integration.appId,
23+
indexName: integration.indexName,
24+
inputSelector: "#search",
25+
debug: false,
26+
});
27+
28+
enabled.current = true;
29+
}
30+
},
31+
[ref.current],
32+
);
33+
34+
return (
35+
<div
36+
ref={ref}
37+
className="search-container"
38+
style={{
39+
display: "grid",
40+
}}
41+
>
42+
<input
43+
id="search"
44+
placeholder="Search"
45+
style={{
46+
backgroundColor: "#FBFBFB",
47+
border: "1px solid rgba(0, 0, 0, .04)",
48+
borderRadius: 4,
49+
color: "rgba(0, 0, 0, 0.34)",
50+
display: "flex",
51+
fontSize: "12px",
52+
height: "32px",
53+
paddingLeft: "18px",
54+
width: "240px",
55+
}}
56+
/>
57+
<img
58+
src={getResourceURI("/icons/search.svg")}
59+
style={{
60+
alignSelf: "center",
61+
justifySelf: "end",
62+
marginTop: 2,
63+
marginRight: 9,
64+
pointerEvents: "none",
65+
zIndex: 1,
66+
}}
67+
/>
68+
</div>
69+
);
70+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const appData = window.appData;
2+
3+
export function getResourceURI(path) {
4+
const root = window.appData.siteRoot;
5+
6+
if (!path.startsWith("/")) {
7+
path = `/${path}`;
8+
}
9+
10+
return root + path;
11+
}

packages/webdoc-default-template/src/styles/header.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
height: $header-height;
2323
top: 0;
2424
width: 100%;
25+
z-index: 1;
2526

2627
&__container {
2728
align-items: center;
@@ -40,7 +41,7 @@
4041
justify-content: flex-end;
4142
height: 100%;
4243

43-
* {
44+
> * {
4445
margin-right: 42px;
4546
}
4647
}

packages/webdoc-default-template/src/styles/index.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@
1313
@import "footer";
1414

1515
// @import "pages/api-index";
16+
17+
.search-container > * {
18+
grid-row: 1;
19+
grid-column: 1;
20+
}
21+
22+
#search:focus {
23+
border: 1px solid rgba(0, 0, 0, 0.4);
24+
outline: none;
25+
}
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)