Skip to content

Commit c635662

Browse files
committed
hits styled; slightly cleaned JS
1 parent 823fc42 commit c635662

File tree

5 files changed

+278
-225
lines changed

5 files changed

+278
-225
lines changed

docs/css/custom.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,3 @@ div.path {
630630
.path p.description {
631631
color: var(--ibexa-dusk-black);
632632
}
633-
634-
635-

docs/css/instantsearch.css

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
.md-content .ais-InstantSearch {
2+
letter-spacing: 0.12px;
3+
}
4+
5+
.md-content .ais-InstantSearch h1 {
6+
font-size: 32px;
7+
line-height: 36px;
8+
letter-spacing: 0.17px;
9+
margin: 8px 0 40px;
10+
}
11+
12+
.md-content .ais-InstantSearch .ais-SearchBox .ais-SearchBox-submit {
13+
left: 16px;
14+
}
15+
16+
.md-content .ais-InstantSearch .ais-SearchBox .ais-SearchBox-submitIcon {
17+
width: 16px;
18+
}
19+
20+
.md-content .ais-InstantSearch .ais-SearchBox .ais-SearchBox-input {
21+
font-size: 14px;
22+
line-height: 21px;
23+
height: 48px;
24+
padding-left: 48px;
25+
border-color: #A0A4A8;
26+
}
27+
28+
.md-content .ais-InstantSearch .ais-Hits-list {
29+
margin-left: 0;
30+
}
31+
32+
.md-content .ais-InstantSearch .ais-Hits-item {
33+
padding: 5px 0 10px;
34+
width: initial;
35+
margin: 0;
36+
border: 0;
37+
box-shadow: none;
38+
}
39+
40+
.md-content .ais-InstantSearch .ais-Highlight-highlighted {
41+
background-color: #ECF4FF;
42+
color: #4191FF;
43+
font-size: 14px;
44+
line-height: 21px;
45+
}
46+
47+
.md-content .ais-InstantSearch .instantsearch__group-header {
48+
display: flex;
49+
align-items: center;
50+
font-size: 14px;
51+
line-height: 21px;
52+
letter-spacing: 0.12px;
53+
height: 40px;
54+
margin: 0;
55+
padding: 0 16px;
56+
background-color: #F2F2F5;
57+
}
58+
59+
.md-content .ais-InstantSearch .instantsearch__group-header .ais-Highlight-highlighted {
60+
font-size: 14px;
61+
line-height: 21px;
62+
}
63+
64+
.md-content .ais-InstantSearch .instantsearch__entry + .instantsearch__entry {
65+
border-top: 1px solid #E0E0E8;
66+
margin-top: 16px;
67+
}
68+
69+
.md-content .ais-InstantSearch .instantsearch__entry-header {
70+
font-size: 18px;
71+
line-height: 20px;
72+
letter-spacing: 0.12px;
73+
margin: 24px 0 4px;
74+
}
75+
76+
.md-content .ais-InstantSearch .instantsearch__entry-header .ais-Highlight-highlighted {
77+
font-size: 18px;
78+
line-height: 20px;
79+
}
80+
81+
.md-content .ais-InstantSearch .instantsearch__entry-content {
82+
color: #3B424A;
83+
font-size: 14px;
84+
line-height: 21px;
85+
letter-spacing: 0.12px;
86+
}
87+
88+
.md-content .ais-InstantSearch .instantsearch__entry-content .ais-Highlight-highlighted {
89+
font-size: 14px;
90+
line-height: 21px;
91+
}
92+
93+
.md-content .ais-InstantSearch .instantsearch__entry-breadcrumbs {
94+
font-size: 12px;
95+
line-height: 21px;
96+
letter-spacing: 0.12px;
97+
margin-top: 16px;
98+
}
99+
100+
.md-content .ais-InstantSearch .instantsearch__entry-breadcrumbs-item + .instantsearch__entry-breadcrumbs-item {
101+
margin-left: 12px;
102+
}
103+
104+
.md-content .ais-InstantSearch .instantsearch__entry-breadcrumbs-item + .instantsearch__entry-breadcrumbs-item:before {
105+
content: '>';
106+
display: inline-block;
107+
padding-right: 12px;
108+
}

docs/js/instantsearch.js

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
(function (global, doc) {
2+
const getClearedItem = (item) => {
3+
const REMOVED_PATTERN = '¶';
4+
const hierarchy = Object.entries(item.hierarchy).reduce((output, [hierarchyIndex, hierarchy]) => {
5+
return {
6+
...output,
7+
[hierarchyIndex]: hierarchy?.replace(REMOVED_PATTERN, '') ?? null,
8+
};
9+
}, {});
10+
const highlightResultHierarchy = Object.entries(item._highlightResult.hierarchy).reduce((output, [hierarchyIndex, hierarchy]) => {
11+
return {
12+
...output,
13+
[hierarchyIndex]: {
14+
...hierarchy,
15+
value: hierarchy?.value.replace(REMOVED_PATTERN, '') ?? null,
16+
},
17+
};
18+
}, {});
19+
20+
return {
21+
...item,
22+
hierarchy,
23+
_highlightResult: {
24+
...item._highlightResult,
25+
hierarchy: highlightResultHierarchy,
26+
},
27+
}
28+
}
29+
const search_query = document.location.hash.match(/q=(.*)(&|$)/)[1] ?? '';
30+
const parsed_search_query = decodeURI(search_query.replace('+', ' '));
31+
const search_page = document.location.hash.match(/p=(\d*)(&|$)/)[1] ?? 1;
32+
const parsed_search_page = parseInt(search_page);
33+
const version = document.location.pathname.split('/')[2];
34+
const search = instantsearch({
35+
indexName: 'ezplatform',
36+
searchClient: algoliasearch('2DNYOU6YJZ', '21ce3e522455e18e7ee16cf7d66edb4b'),
37+
initialUiState: {
38+
ezplatform: {
39+
query: parsed_search_query,
40+
refinementList: {version: [version]},
41+
page: parsed_search_page,
42+
},
43+
},
44+
});
45+
46+
document.getElementById('searchbox').addEventListener('keyup', function (event) {
47+
window.location.hash = '#q=' + encodeURI(event.target.value) + '&p=1';
48+
})
49+
50+
document.getElementById('pagination').addEventListener('click', function (event) {
51+
let page = document.getElementsByClassName('ais-Pagination-item--selected').length ? parseInt(document.getElementsByClassName('ais-Pagination-item--selected')[0].innerText) : 1
52+
window.location.hash = window.location.hash.includes('p=') ? window.location.hash.replace(/p=\d*/, 'p=' + page) : window.location.hash + '&p=' + page;
53+
})
54+
55+
search.addWidgets([
56+
instantsearch.widgets.configure({
57+
hitsPerPage: 10,
58+
}),
59+
instantsearch.widgets.stats({
60+
container: '#stats',
61+
templates: {
62+
text: `<h1>
63+
Search results ({{#helpers.formatNumber}}{{nbHits}}{{/helpers.formatNumber}})
64+
</h1>`,
65+
},
66+
}),
67+
instantsearch.widgets.searchBox({
68+
container: '#searchbox',
69+
}),
70+
instantsearch.widgets.hits({
71+
container: '#hits',
72+
transformItems(items) {
73+
const outputItemsMap = {};
74+
75+
items.forEach((item) => {
76+
const hierarchy = Object.entries(item.hierarchy).filter(([, value]) => value);
77+
const breadcrumbsKeys = hierarchy.map(([key]) => key);
78+
const groupNameKey = breadcrumbsKeys.shift();
79+
const entryNameKey = breadcrumbsKeys.pop();
80+
const newItem = {
81+
entryNameKey,
82+
breadcrumbsKeys,
83+
item: getClearedItem(item),
84+
};
85+
const groupChildren = outputItemsMap[groupNameKey]?.children ?? [];
86+
87+
outputItemsMap[groupNameKey] = {
88+
groupNameKey,
89+
children: [...groupChildren, newItem],
90+
};
91+
});
92+
93+
return Object.values(outputItemsMap);
94+
},
95+
templates: {
96+
item: (hit) => {
97+
const { groupNameKey, children } = hit;
98+
const groupItem = children[0].item;
99+
const groupHeaderHTML = `<h2 class="instantsearch__group-header">
100+
${instantsearch.highlight({ attribute: `hierarchy.${groupNameKey}`, highlightedTagName: 'mark', hit: groupItem })}
101+
(${children.length})
102+
</h2>`;
103+
let groupContentHTML = '';
104+
105+
children.forEach((childHit) => {
106+
const { breadcrumbsKeys, entryNameKey, item: entryItem } = childHit;
107+
const headerHTML = `<h3 class="instantsearch__entry-header">
108+
${instantsearch.highlight({ attribute: `hierarchy.${entryNameKey}`, highlightedTagName: 'mark', hit: entryItem })}
109+
</h3>`;
110+
let breadcrumbsHTML = '';
111+
let contentHTML = '';
112+
113+
if (entryItem.content) {
114+
contentHTML = `<div class="instantsearch__entry-content">
115+
${instantsearch.highlight({ attribute: `content`, highlightedTagName: 'mark', hit: entryItem })}
116+
</div>`;
117+
}
118+
119+
breadcrumbsKeys?.forEach((breadcrumbKey) => {
120+
breadcrumbsHTML += `<span class="instantsearch__entry-breadcrumbs-item">
121+
${instantsearch.highlight({ attribute: `hierarchy.${breadcrumbKey}`, highlightedTagName: 'mark', hit: entryItem })}
122+
</span>`
123+
});
124+
125+
const childHTML = `<div class="instantsearch__entry">
126+
${headerHTML}
127+
${contentHTML}
128+
<div class="instantsearch__entry-breadcrumbs">
129+
${breadcrumbsHTML}
130+
</div>
131+
</div>`;
132+
133+
groupContentHTML += childHTML;
134+
});
135+
136+
return `<div class="instantsearch">
137+
${groupHeaderHTML}
138+
<div class="instantsearch__group">
139+
${groupContentHTML}
140+
</div>
141+
</div>`;
142+
},
143+
},
144+
}),
145+
instantsearch.widgets.pagination({
146+
container: '#pagination',
147+
}),
148+
instantsearch.widgets.stats({
149+
container: '#pagination-stats',
150+
templates: {
151+
text(data, {html}) {
152+
let page = 1 + data.page;
153+
return html`<span>${page} / ${data.nbPages}</span>`;
154+
},
155+
},
156+
}),
157+
instantsearch.widgets.refinementList({
158+
container: document.querySelector('#version'),
159+
attribute: 'version',
160+
}),
161+
]);
162+
163+
search.start();
164+
})(window, window.document);

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ extra_css:
648648
- css/page-not-found.css
649649
- css/navigation.css
650650
- css/docs.switcher.css
651+
- css/instantsearch.css
651652
- css/jquery-ui.min.css
652653
- '//cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css'
653654

@@ -656,6 +657,7 @@ extra_javascript:
656657
- js/jquery-ui.min.js
657658
- js/custom.js
658659
- js/docs.switcher.js
660+
- js/instantsearch.js
659661
- js/ez-guidelines-switchers.js
660662
- js/ez-guidelines-modals.js
661663
- js/ez-guidelines-tooltips.js

0 commit comments

Comments
 (0)