@@ -15,9 +15,9 @@ const md = new MarkdownIt({
1515 } </div>`
1616} ) ;
1717
18- const renderMethod = ( method : Method ) => `<div class="mb-5"><a name="${
19- method . slug
20- } " />
18+ const renderMethod = ( method : Method ) => `<div class="mb-5" data-method- name="${
19+ method . name
20+ } "><a name=" ${ method . slug } " />
2121
2222<h2 class="method-name">
2323 <a href="#${
@@ -72,7 +72,9 @@ const renderFileNav = (file: File) => `<p><a href="#${
7272${ file . methods
7373 . map (
7474 method =>
75- `<li class="method-name"><a href="#${ method . slug } " class="${
75+ `<li class="method-name" data-method-name="${
76+ method . name
77+ } "><a href="#${ method . slug } " class="${
7678 method . private ? 'text-muted' : ''
7779 } ">${ method . name } </a></li>`
7880 )
@@ -140,6 +142,10 @@ export default async (doc: Doc): Promise<string> => `<!DOCTYPE html>
140142 color: #eee;
141143 text-decoration: none;
142144 }
145+
146+ .hidden {
147+ display: none;
148+ }
143149 </style>
144150 </head>
145151 <body>
@@ -162,6 +168,13 @@ export default async (doc: Doc): Promise<string> => `<!DOCTYPE html>
162168 <div class="container">
163169 <div class="row">
164170 <nav class="p-5 col-md-3">
171+ <form>
172+ <div class="form-group mb-3">
173+ <input type="search" class="form-control" id="filter-methods" name="q" placeholder="Filter methods..."
174+ autocomplete="off">
175+ </div>
176+ </form>
177+
165178 ${ doc . files
166179 . filter ( file => file . methods . length )
167180 . map ( file => renderFileNav ( file ) )
@@ -189,6 +202,32 @@ export default async (doc: Doc): Promise<string> => `<!DOCTYPE html>
189202 </p>
190203 </div>
191204 </footer>
205+ <script>
206+ const params = new URLSearchParams(window.location.search);
207+
208+ const q = params.get('q');
209+
210+ const filterInput = document.querySelector('#filter-methods');
211+
212+ const methods = Array.from(document.querySelectorAll('[data-method-name]'));
213+
214+ const filterMethods = keyword => {
215+ const keywordsPattern = RegExp(keyword.trim().split(/[^A-Za-z]+/).join('|'), 'i')
216+
217+ const matched = methods.filter(method => method.dataset.methodName.match(keywordsPattern));
218+ const notMatched = methods.filter(method => !method.dataset.methodName.match(keywordsPattern));
219+
220+ matched.map(match => match.classList.remove('hidden'));
221+ notMatched.map(match => match.classList.add('hidden'));
222+ }
223+
224+ filterInput.addEventListener('keyup', e => filterMethods(e.target.value));
225+ filterInput.addEventListener('search', e => filterMethods(e.target.value));
226+
227+ filterInput.value = q;
228+
229+ filterMethods(q);
230+ </script>
192231 </body>
193232</html>
194233` ;
0 commit comments