File tree Expand file tree Collapse file tree 5 files changed +40
-20
lines changed Expand file tree Collapse file tree 5 files changed +40
-20
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { OPENAPI_PATHS } from "../public/components/openapi-paths.js";
5
5
import { parameterField } from "../public/components/parameter-field.js" ;
6
6
import { requestPreview } from "../public/components/request-preview.js" ;
7
7
import { getResponseHTML } from "../public/components/get-response-html.js" ;
8
+ import { search } from "../public/components/search.js" ;
8
9
9
10
const MarkdownIt = require ( "markdown-it" ) ;
10
11
@@ -118,13 +119,11 @@ module.exports = async (request, response) => {
118
119
<body>
119
120
<h1>octokit.rest</h1>
120
121
121
- <form action="/">
122
- <label>
123
- What would you like to request?<br />
124
- <input type="text" value="${ endpoint . method } ${ path } " name="query" />
125
- </label>
126
- <button type="submit">Go</button>
127
- </form>
122
+ <div id="search">
123
+ ${ search ( { query : `${ endpoint . method } ${ endpoint . url } ` } ) }
124
+ </div>
125
+
126
+ <div id="details">
128
127
129
128
<section>
130
129
<h2>${ endpoint . name } (<code>${ route } </code>)</h2>
@@ -178,7 +177,10 @@ module.exports = async (request, response) => {
178
177
endpoint . documentationUrl
179
178
} ">GitHub developer guides</a></p>
180
179
180
+ </div>
181
+
181
182
<script type="module" src="/detail.js"></script>
183
+ <script type="module" src="/search.js"></script>
182
184
</body>
183
185
</html>
184
186
` ) ;
Original file line number Diff line number Diff line change 1
1
import { OPENAPI_PATHS } from "../public/components/openapi-paths.js" ;
2
- import { searchResults } from "../public/components/search-results.js" ;
3
2
import { pageTitle } from "../public/components/page-title.js" ;
3
+ import { search } from "../public/components/search.js" ;
4
4
5
5
const allEndpointPaths = Object . keys ( OPENAPI_PATHS ) ;
6
6
@@ -59,16 +59,8 @@ module.exports = async (request, response) => {
59
59
<body>
60
60
<h1>octokit.rest</h1>
61
61
62
- <form action="/">
63
- <label>
64
- What would you like to request?<br />
65
- <input type="text" value="${ query } " name="query" />
66
- </label>
67
- <button type="submit">Go</button>
68
- </form>
69
-
70
- <div id="results">
71
- ${ searchResults ( { query, results } ) }
62
+ <div id="search">
63
+ ${ search ( { query, results } ) }
72
64
</div>
73
65
74
66
<script type="module" src="/search.js"></script>
Original file line number Diff line number Diff line change 1
1
export function searchResults ( { query, results } ) {
2
2
const queryRegex = new RegExp ( `(${ query } )` , "i" ) ;
3
3
4
- const resultsHTML = results
4
+ if ( ! results ) return "" ;
5
+
6
+ const resultsHTML = results ? results
5
7
. filter ( Boolean )
6
8
. map ( ( [ method , path , operation ] ) => {
7
9
const route = `${ method } ${ path } ` . replace ( queryRegex , `<mark>$1</mark>` ) ;
@@ -13,7 +15,7 @@ export function searchResults({ query, results }) {
13
15
</a>
14
16
</article>` ;
15
17
} )
16
- . join ( "\n" ) ;
18
+ . join ( "\n" ) : "" ;
17
19
18
20
if ( resultsHTML ) {
19
21
return `<h2>Results</h2>
Original file line number Diff line number Diff line change
1
+
2
+ import { searchResults } from "./search-results.js" ;
3
+
4
+ export function search ( { query, results } ) {
5
+
6
+ const resultsHTML = searchResults ( { query, results } ) ;
7
+
8
+ return `
9
+ <form action="/">
10
+ <label>
11
+ What would you like to request?<br />
12
+ <input type="text" value="${ query } " name="query" autocomplete="off" />
13
+ </label>
14
+ <button type="submit">Go</button>
15
+ </form>
16
+
17
+ <div id="results">
18
+ ${ resultsHTML }
19
+ </div>
20
+ ` ;
21
+
22
+ }
Original file line number Diff line number Diff line change @@ -3,12 +3,14 @@ import { pageTitle } from "/components/page-title.js";
3
3
4
4
const $queryField = document . querySelector ( `input[name="query"]` ) ;
5
5
const $results = document . querySelector ( `#results` ) ;
6
+ const $details = document . querySelector ( `#details` ) ;
6
7
7
8
$queryField . addEventListener ( "keyup" , async function ( event ) {
8
9
const query = $queryField . value . trim ( ) ;
9
10
const results = query ? await sendSearchRequest ( query ) : [ ] ;
10
11
11
12
$results . innerHTML = await searchResults ( { query, results } ) ;
13
+ $details . style . display = "none" ;
12
14
13
15
window . history . pushState (
14
16
{ } ,
You can’t perform that action at this time.
0 commit comments