Skip to content

Commit bd7b457

Browse files
author
fabianmoronzirfas
committed
feat(search):
1 parent 9563790 commit bd7b457

File tree

6 files changed

+59
-46
lines changed

6 files changed

+59
-46
lines changed

.bin/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,8 @@ json.forEach(ele => {
256256
});
257257

258258
// sort categories by name
259-
// console.log(json[0][0].cat);
260259
json.sort((a,b)=> a[0].cat.localeCompare(b[0].cat));
261-
// json.forEach((ele, i) => {
262-
// // console.log(ele[i].cat);
263-
// ele.sort((a,b) => a.cat.localeCompare(b.cat));
264-
// })
260+
265261

266262
fs.writeFile('./_data/cats-and-subcats.json', JSON.stringify(json, null, 2), (err)=>{
267263
if(err) {

assets/js/reference.bundle.js

Lines changed: 15 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/reference.bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/src/reference.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@ import List from 'list.js';
22

33

44
document.addEventListener('DOMContentLoaded',function() {
5-
const searchfield = document.querySelector('input.search');
6-
console.log(List);
5+
// const searchfield = document.querySelector('input.search');
6+
// console.log(List);
77
console.log('Vanilla doc ready');
88
var options = {
9-
valueNames: ['heading-category']
9+
valueNames: ['entry-heading-link'],
10+
// needs some tweaking
11+
location: 0,
12+
distance: 100,
13+
threshold: 0.4,
14+
multiSearch: true
1015
};
11-
const listObj = new List('reference', options);
12-
console.log(listObj);
13-
if (searchfield!==null) {
14-
searchfield.addEventListener('keyup', (event)=>{
15-
let txt = searchfield.value;
16-
listObj.search(txt);
17-
});
18-
}
16+
const listObj = new List('ref', options);
17+
18+
// console.log(listObj);
19+
// if (searchfield !== null) {
20+
// searchfield.addEventListener('keyup', (event)=>{
21+
// let txt = searchfield.value;
22+
// listObj.search(txt);
23+
// });
24+
// }
1925
});

reference/index.html

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@
5151
min-height: 6em;
5252
margin-top: 0.5em;
5353
}
54+
.fuzzy-search, input.fuzzy-search::placeholder {
55+
width: 100%;
56+
/* height: 2em; */
57+
/* font-weight: bold; */
58+
font-size: 1.2em;
59+
/* color: #9636FC; */
60+
font-family:'Times New Roman', Times, serif;
61+
}
5462
</style>
5563
<h1 id="new-cat-index">{{page.title}}</h1>
5664

@@ -71,15 +79,11 @@ <h2>Table Of Contents</h2>
7179

7280
</section>
7381
<!-- End of TOC loops -->
74-
<input class="search" placeholder="Search" />
75-
<!-- class="sort" automagically makes an element a sort buttons. The date-sort value decides what to sort by. -->
76-
<button class="sort" data-sort="name">
77-
Sort
78-
</button>
79-
<div class="reference">
80-
<!-- class="search" automagically makes an input a search field. -->
82+
<div class="ref" id="ref">
83+
<!-- class="fuzzy-search" automagically makes an input a search field. -->
84+
<input class="fuzzy-search" placeholder="Fuzzy Search List.js" />
85+
<section class="list">
8186
{%- for element in site.data.cats-and-subcats %}
82-
<!-- <section class="category"> -->
8387
{%- assign newcat = true -%}
8488
{%- for ele in element -%}
8589
{%- if newcat == true -%}
@@ -89,10 +93,9 @@ <h2 class="heading-category" id="{{ele.cat}}">{{ele.cat}}</h2>
8993
{%- unless ele.subcat == 'null' -%}<h3 id="{{ele.subcat}}">{{ele.cat}}#{{ele.subcat}}</h3>{%- endunless -%}
9094
<section class="sub-category">
9195
{%- for entry in ele.entries -%}
92-
{%- assign eid = entry.name |downcase -%}
96+
{%- assign eid = entry.name | downcase -%}
9397
<div class="new-entry" id="{{eid}}-ndx">
94-
<div class="entry-heading"><a href="/reference/{{ele.cat}}/{{entry.name}}.html">{{entry.codetitle}}</a></div>
95-
98+
<div class="entry-heading"><a class="entry-heading-link" href="/reference/{{ele.cat}}/{{entry.name}}.html">{{entry.codetitle}}</a></div>
9699
{%- if entry.summary != null -%}
97100
<p class="summary">{{entry.summary}}</p>
98101
{%- else -%}
@@ -108,17 +111,18 @@ <h2 class="heading-category" id="{{ele.cat}}">{{ele.cat}}</h2>
108111
</p>
109112
{%- endif -%}
110113
</div>
111-
{%- endfor -%} <!-- End of sub category loop-->
114+
{%- endfor -%} <!-- End of sub entries loop-->
112115
</section>
113116
<!-- <hr> -->
114-
115117
{%- endfor -%} <!-- End of category loop-->
116-
<!-- </section> -->
117-
{%- endfor -%} <!-- End of elements loop-->
118+
{%- endfor -%} <!-- End of elements loop-->
119+
</section>
118120
</div>
119121

120-
121-
122+
<script>
123+
// const searchstring = 'foo';
124+
// window.lunrjssearchdata = JSON.parse(searchstring);
125+
</script>
122126
{%- comment -%}
123127
<h2 id="cat-ndx">Categories</h2>
124128
<div class="index">

reference/lunrjs.data.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
[{%- for element in site.data.cats-and-subcats -%}{%- for ele in element -%}{%- for entry in ele.entries -%}{%- assign eid = entry.name | downcase -%} { "id":"{{eid}}","codetitle": "{{ entry.codetitle }}","summary":"{%- if entry.summary != null -%}{{ entry.summary | strip_newlines | escape }}{%- else -%}{{ entry.description | truncate: 150, '...' | markdownify | strip_html | strip_newlines | escape }}
4+
{%- endif -%}" } {%- if forloop.last != true -%},{%-endif-%}{%- endfor -%}{%- if forloop.last != true -%},{%-endif-%}{%- endfor -%}{%- if forloop.last != true -%},{%-endif-%}{%- endfor -%}]

0 commit comments

Comments
 (0)