Skip to content

Commit 92cebc9

Browse files
Added support for search (#2415)
Added support for search within the template as suggested in #581. I decided to go with a client side search based on [Ninja keys](https://github.com/ssleptsov/ninja-keys), but using [deepdub's fork](https://github.com/deepdub-ai/ninja-keys) as basis since it supports fuzzy search. Had to do a bunch of changes to their code to make it work without using node to install everything. Also changed to use some colors defined in our side and using both pages' titles and descriptions for search. Also had to increase the template max width to better accomodate the new item in navigation bar. Missing implementations: - [ ] One thing I'd love to do (but currently have no idea how) would be to change the text next to the search button depending on the platform. For example, if the user is accessing the site on a mac they should use ⌘k instead of ctrl k. - [x] Test how this looks like (and how it is supposed to work) on devices with smaller screens - [x] Support for offline mode Some screenshots: --- ## Dark version ![Screenshot from 2024-05-13 16-30-12](https://github.com/alshedivat/al-folio/assets/31376482/535acec5-dd7a-48cb-a17f-a295da98b5d3) ![Screenshot from 2024-05-13 16-30-26](https://github.com/alshedivat/al-folio/assets/31376482/6b2d94bb-3981-4252-ae2b-53994b514491) ![Screenshot from 2024-05-13 16-30-36](https://github.com/alshedivat/al-folio/assets/31376482/66262b56-2744-475d-b09f-2cb65210017b) --- ## Light version ![Screenshot from 2024-05-13 16-30-44](https://github.com/alshedivat/al-folio/assets/31376482/a0eec50c-e7ac-4b52-aee8-2050bff05d54) ![Screenshot from 2024-05-13 16-30-50](https://github.com/alshedivat/al-folio/assets/31376482/41d72066-3e68-4ec3-bf3d-140da621f67b) ![Screenshot from 2024-05-13 16-30-55](https://github.com/alshedivat/al-folio/assets/31376482/613fd56e-7180-4373-ab7a-dfed184b5a18) --------- Signed-off-by: George Araujo <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent eef62a3 commit 92cebc9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1603
-3
lines changed

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
**/*.min.css
33
**/*.min.js
44
assets/css/main.scss
5+
assets/js/search-data.js
56
assets/js/distillpub/template.v2.js
7+
assets/js/search/*.js
68
assets/plotly/demo.html
79
lighthouse_results/**
810
_posts/2015-10-20-math.md

_config.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ rss_icon: true
4848

4949
navbar_fixed: true
5050
footer_fixed: true
51+
search_enabled: true
52+
socials_in_search: true
5153

5254
# Dimensions
53-
max_width: 800px
55+
max_width: 930px
5456

5557
# TODO: add layout settings (single page vs. multi-page)
5658

@@ -266,7 +268,7 @@ sass:
266268
# -----------------------------------------------------------------------------
267269

268270
jekyll-minifier:
269-
exclude: ["robots.txt"]
271+
exclude: ["robots.txt", "assets/js/search/*.js"]
270272
uglifier_args:
271273
harmony: true
272274

_includes/header.liquid

+8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@
107107
{% endif %}
108108
{% endif %}
109109
{% endfor %}
110+
{% if site.search_enabled %}
111+
<!-- Search -->
112+
<li class="nav-item">
113+
<button id="search-toggle" title="Search" onclick="openSearchModal()">
114+
<span class="nav-link">ctrl k <i class="ti ti-search"></i></span>
115+
</button>
116+
</li>
117+
{% endif %}
110118
{% if site.enable_darkmode %}
111119
<!-- Toogle theme mode -->
112120
<li class="toggle-container">

_includes/scripts/search.liquid

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% if site.search_enabled %}
2+
<script type="module" src="{{ '/assets/js/search/ninja-keys.min.js' | relative_url | bust_file_cache }}"></script>
3+
<ninja-keys hideBreadcrumbs noAutoLoadMdIcons placeholder="Type to start searching"></ninja-keys>
4+
<script src="{{ '/assets/js/search-data.js' | relative_url | bust_file_cache }}"></script>
5+
<script>
6+
let theme = determineComputedTheme();
7+
const ninjaKeys = document.querySelector('ninja-keys');
8+
9+
if (theme === 'dark') {
10+
ninjaKeys.classList.add('dark');
11+
} else {
12+
ninjaKeys.classList.remove('dark');
13+
}
14+
15+
const openSearchModal = () => {
16+
// collapse navbarNav if expanded on mobile
17+
const navbarNav = document.querySelector('.navbar-collapse');
18+
if (navbarNav.classList.contains('show')) {
19+
navbarNav.classList.remove('show');
20+
}
21+
ninjaKeys.open();
22+
};
23+
</script>
24+
{% endif %}

_layouts/default.liquid

+1
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@
7272
{% include scripts/imageLayouts.liquid %}
7373
{% include scripts/jekyll_tabs.liquid %}
7474
{% include scripts/back_to_top.liquid %}
75+
{% include scripts/search.liquid %}
7576
</body>
7677
</html>

_sass/_base.scss

+15-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ ul.task-list input[type="checkbox"] {
355355
}
356356
}
357357

358-
#light-toggle {
358+
#light-toggle,
359+
#search-toggle {
359360
padding: 0;
360361
border: 0;
361362
background-color: inherit;
@@ -1109,3 +1110,16 @@ swiper-container {
11091110
border-bottom: 2px solid var(--global-text-color);
11101111
}
11111112
}
1113+
1114+
// Ninja Keys
1115+
// for more options, check https://github.com/ssleptsov/ninja-keys?tab=readme-ov-file#css-variables
1116+
ninja-keys {
1117+
--ninja-accent-color: var(--global-theme-color);
1118+
--ninja-icon-size: 0px;
1119+
--ninja-modal-background: var(--global-bg-color);
1120+
--ninja-z-index: 1031;
1121+
}
1122+
1123+
ninja-keys::part(ninja-input-wrapper) {
1124+
background: var(--global-bg-color);
1125+
}

0 commit comments

Comments
 (0)