Skip to content

Commit ed09f5b

Browse files
committed
Add meilisearch UI and functinality
Signed-off-by: Md Mohin Uddin <[email protected]>
1 parent 7c0cf05 commit ed09f5b

File tree

13 files changed

+438
-148
lines changed

13 files changed

+438
-148
lines changed

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ assets: hugo-tools
2323
.PHONY: gen
2424
gen:
2525
rm -rf public
26-
@yqq w -i config.dev.yaml params.search_api_key --tag '!!str' $(GOOGLE_CUSTOM_SEARCH_API_KEY)
2726
hugo --config=config.dev.yaml
28-
@yqq w -i config.dev.yaml params.search_api_key --tag '!!str' '_replace_'
2927

3028
.PHONY: qa
3129
qa: gen
@@ -35,9 +33,7 @@ qa: gen
3533
.PHONY: gen-prod
3634
gen-prod:
3735
rm -rf public
38-
@yqq w -i config.yaml params.search_api_key --tag '!!str' $(GOOGLE_CUSTOM_SEARCH_API_KEY)
3936
hugo --minify --config=config.yaml
40-
@yqq w -i config.yaml params.search_api_key --tag '!!str' '_replace_'
4137

4238
.PHONY: release
4339
release: gen-prod

config.dev.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ params:
1818
domain_kubeshield: https://kubeshield-v1-hugo.web.app
1919
domain_bytebuilders: https://byte.builders
2020
domain_marketplace: https://marketplace.byte.builders
21-
search_engine_ID: 015199383701854252104:jccvu4eiulw
22-
search_api_key: AIzaSyBrcwLTnL09geNrFMUx1kpL--dT1379aag
21+
search_api_key: 8fd610038d901dd16a111e6f1568343bb969b084a1952dafdcb1545fd8c35e96
2322
blog_url: https://blog.byte.builders
2423
slack_url: https://slack.appscode.com
2524
github_url: https://github.com/appscode

config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ params:
1818
domain_kubeshield: https://kubeshield.com
1919
domain_bytebuilders: https://byte.builders
2020
domain_marketplace: https://marketplace.byte.builders
21-
search_engine_ID: 015199383701854252104:jccvu4eiulw
22-
search_api_key: _replace_
21+
search_api_key: 8fd610038d901dd16a111e6f1568343bb969b084a1952dafdcb1545fd8c35e96
2322
blog_url: https://blog.byte.builders
2423
slack_url: https://slack.appscode.com
2524
github_url: https://github.com/appscode

layouts/_default/baseof.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,10 @@ <h4>Legal</h4>
11121112
</script>
11131113
<!--End of Tawk.to Script-->
11141114

1115+
<!-- Meilisearch -->
1116+
{{ block "footer-script" . }}
1117+
{{ end }}
1118+
11151119
<script>
11161120
window.addEventListener('load', function() {
11171121
jQuery('a:contains("KubeDB")').click(function() {

layouts/products/single.html

Lines changed: 32 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,26 @@ <h6>{{ .Name }}</h6>
107107
{{ end }}
108108
</ul>
109109

110+
<!-- =============searchbar area start ===========================-->
110111
<div class="ac-searchbar">
111112
<label for="acSearch">
112113
<lord-icon src="https://cdn.lordicon.com/msoeawqm.json" target="#acSearch" trigger="hover"
113114
style="width:22px;height:22px">
114115
</lord-icon>
115116
</label>
116-
<input id="acSearch" type="search" placeholder="Search in {{ $p.name }} Documentation!">
117+
118+
<input id="acSearch" type="search" placeholder="Search in {{ $p.name }} documentation!" autocomplete="off">
119+
120+
<!-- search result start -->
121+
<div id="meilisearch-hideid" class="search-result-box is-hidden">
122+
<!-- add ".is-hidden" for hide item -->
123+
<div class="search-content" id="meilisearch-hits">
124+
<!-- Search List component will be generate here from dom -->
125+
</div>
126+
</div>
127+
<!-- search result end -->
117128
</div>
129+
<!-- =============searchbar area end ===========================-->
118130

119131
</div>
120132
<!-- searchbar component end -->
@@ -279,39 +291,33 @@ <h4>What's on this Page</h4>
279291
<div class="overlay-bg"></div>
280292
<!-- overlay end -->
281293

294+
<!-- responsive sidebar search area start -->
282295
<div class="sidebar-search-area">
283296
<button class="button ac-button inline-button back-button"><span
284297
class="material-icons-outlined">arrow_back</span>Back</button>
285298
<div class="search-area-top">
286299
<h5>Search</h5>
287300

288301
<div class="searchbar-area">
289-
<input type="search" name="search" id="searchbox" placeholder="Search..." />
290-
<button onclick="queryPage(1)">
302+
<input type="search" name="search" id="searchbox" placeholder="Search in {{ $p.name }} documentation!" />
303+
<button>
291304
<lord-icon src="https://cdn.lordicon.com/msoeawqm.json" colors="primary:#ffffff" target=".searchbar-area button"
292305
trigger="hover" style="width:22px;height:22px">
293306
</lord-icon>
294307
</button>
295308
</div>
296-
297-
<span id="searchbar-script-container" style="display:none"></span>
298-
299-
<div class="search-meta-information level">
300-
<div class="level-left">
301-
</div>
302-
</div>
303-
</div>
304-
305-
<div class="search-result-wrapper">
306309
</div>
307310

308-
<!-- pagination area start -->
309-
<div class="pagination-area">
310-
<div class="pagination-list">
311+
<!-- search content start -->
312+
<div id="meilisearch-hideid-mobile">
313+
<div class="search-content" id="meilisearch-mobile-hits">
314+
<!-- Generated search list for mobile device will be generate here -->
311315
</div>
312316
</div>
313-
<!-- pagination area end -->
317+
<!-- search content end -->
318+
314319
</div>
320+
<!-- responsive sidebar search area end -->
315321

316322
<!-- improve page section start -->
317323
<div class="improve-section-area">
@@ -330,122 +336,6 @@ <h5>Search</h5>
330336
</div>
331337
</div>
332338
<!-- improve page section end -->
333-
334-
<script type="text/javascript">
335-
var pageSize = 5;
336-
var acSearch = document.querySelector("#acSearch");
337-
var bodyOverlay = document.querySelector(".overlay-bg");
338-
var sidebarSearch = document.querySelector(".sidebar-search-area");
339-
340-
acSearch.addEventListener("click", function () {
341-
bodyOverlay.style.display = "block";
342-
sidebarSearch.style.right = "0";
343-
document.getElementById("searchbox").focus();
344-
bodyOverlay.addEventListener("click", function () {
345-
bodyOverlay.style.display = "none";
346-
sidebarSearch.style.right = "-100%";
347-
});
348-
});
349-
350-
function encodeQueryData(data) {
351-
var ret = [];
352-
for (var d in data)
353-
ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(data[d]));
354-
return ret.join('&');
355-
}
356-
357-
document.querySelector(".searchbar-area input[type=search]").addEventListener("keyup", function (event) {
358-
event.preventDefault();
359-
if (event.keyCode === 13) {
360-
queryPage(1);
361-
}
362-
});
363-
364-
function queryPage(idx) {
365-
var q = document.getElementById("searchbox").value;
366-
var cx = "{{.Site.Params.search_engine_ID}}";
367-
var key = "{{.Site.Params.search_api_key}}";
368-
var imgSize = "small";
369-
var callback = "renderResult";
370-
371-
var src = "https://www.googleapis.com/customsearch/v1?" + encodeQueryData({
372-
q: q,
373-
cx: cx,
374-
key: key,
375-
imgSize: imgSize,
376-
callback: callback,
377-
start: (idx - 1) * pageSize + 1,
378-
num: pageSize,
379-
});
380-
381-
var newScript = document.createElement("script");
382-
newScript.src = src;
383-
e = document.getElementById("searchbar-script-container");
384-
var child = e.lastElementChild;
385-
if (child) {
386-
e.removeChild(child);
387-
}
388-
e.appendChild(newScript);
389-
}
390-
391-
function renderSearchResultEntry(e) {
392-
var out = '<div class="single-search-result">' +
393-
'<h3><a href="' + e.link + '">' + e.title + '</a></h3>' +
394-
'<a href="' + e.link + '">' + e.htmlFormattedUrl + '</a>' +
395-
'<div class="result-description-wrapper">';
396-
if (e.pagemap && e.pagemap.cse_thumbnail) {
397-
out += '<div class="result-thumb">' +
398-
'<img src="' + e.pagemap.cse_thumbnail[0].src + '" alt="" />' +
399-
'</div>';
400-
}
401-
out += '<div class="result-description">' +
402-
'<p>' +
403-
e.snippet +
404-
'</p>' +
405-
'</div>' +
406-
'</div>' +
407-
'</div>';
408-
return out;
409-
}
410-
411-
function renderResult(response) {
412-
document.querySelector(".search-meta-information .level-left").innerHTML = '<div class="level-left">' +
413-
'<p>' +
414-
'About <span class="search-count">' + response.searchInformation.formattedTotalResults +
415-
'</span> results (<span class="time-count">' + response.searchInformation.formattedSearchTime +
416-
' </span>seconds)' +
417-
'</p>' +
418-
'</div>';
419-
420-
if (!response.items) {
421-
return;
422-
}
423-
424-
var searchResultWrapper = document.querySelector(".search-result-wrapper");
425-
searchResultWrapper.innerHTML = "";
426-
427-
for (var i = 0; i < response.items.length; i++) {
428-
searchResultWrapper.innerHTML += renderSearchResultEntry(response.items[i]);
429-
}
430-
431-
var pager = '<ul>';
432-
if (response.queries.previousPage) {
433-
var pageIndex = Math.floor(response.queries.previousPage[0].startIndex / pageSize) + 1;
434-
pager += '<li><a href="#" onclick="queryPage(' + pageIndex + ')">Previous</a></li>';
435-
}
436-
if (response.queries.request) {
437-
var pageIndex = Math.floor(response.queries.request[0].startIndex / pageSize) + 1;
438-
pager += '<li><a href="#" onclick="queryPage(' + pageIndex + ')" class="is-active">' + pageIndex + '</a></li>';
439-
}
440-
if (response.queries.nextPage) {
441-
var pageIndex = Math.floor(response.queries.nextPage[0].startIndex / pageSize) + 1;
442-
pager += '<li><a href="#" onclick="queryPage(' + pageIndex + ')">Next</a></li>';
443-
}
444-
pager += '</ul>';
445-
document.querySelector(".pagination-area .pagination-list").innerHTML = pager;
446-
}
447-
</script>
448-
449339
<!-- sidebar search area end -->
450340

451341
{{ end }}
@@ -462,3 +352,12 @@ <h5>Search</h5>
462352
{{ define "cta-install" }}
463353
<section></section>
464354
{{ end }}
355+
356+
{{ define "footer-script" }}
357+
{{ $js := resources.Get "/assets/js/meilisearch.js" | minify }}
358+
<script src="{{ $js.RelPermalink }}"></script>
359+
<script type="text/javascript">
360+
activate_search({{ (index .Site.Data.products (string .Params.product_name)).key }}, {{ .Site.Params.search_api_key }}, "acSearch","meilisearch-hits", "meilisearch-hideid");
361+
activate_search({{ (index .Site.Data.products (string .Params.product_name)).key }}, {{ .Site.Params.search_api_key }}, "searchbox","meilisearch-mobile-hits", "meilisearch-hideid-mobile");
362+
</script>
363+
{{ end }}

0 commit comments

Comments
 (0)