Skip to content

Commit

Permalink
Added support for search (#2415)
Browse files Browse the repository at this point in the history
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 <george.gcac@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
george-gca and dependabot[bot] committed May 24, 2024
1 parent eef62a3 commit 92cebc9
Show file tree
Hide file tree
Showing 43 changed files with 1,603 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
**/*.min.css
**/*.min.js
assets/css/main.scss
assets/js/search-data.js
assets/js/distillpub/template.v2.js
assets/js/search/*.js
assets/plotly/demo.html
lighthouse_results/**
_posts/2015-10-20-math.md
6 changes: 4 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ rss_icon: true

navbar_fixed: true
footer_fixed: true
search_enabled: true
socials_in_search: true

# Dimensions
max_width: 800px
max_width: 930px

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

Expand Down Expand Up @@ -266,7 +268,7 @@ sass:
# -----------------------------------------------------------------------------

jekyll-minifier:
exclude: ["robots.txt"]
exclude: ["robots.txt", "assets/js/search/*.js"]
uglifier_args:
harmony: true

Expand Down
8 changes: 8 additions & 0 deletions _includes/header.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@
{% endif %}
{% endif %}
{% endfor %}
{% if site.search_enabled %}
<!-- Search -->
<li class="nav-item">
<button id="search-toggle" title="Search" onclick="openSearchModal()">
<span class="nav-link">ctrl k <i class="ti ti-search"></i></span>
</button>
</li>
{% endif %}
{% if site.enable_darkmode %}
<!-- Toogle theme mode -->
<li class="toggle-container">
Expand Down
24 changes: 24 additions & 0 deletions _includes/scripts/search.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% if site.search_enabled %}
<script type="module" src="{{ '/assets/js/search/ninja-keys.min.js' | relative_url | bust_file_cache }}"></script>
<ninja-keys hideBreadcrumbs noAutoLoadMdIcons placeholder="Type to start searching"></ninja-keys>
<script src="{{ '/assets/js/search-data.js' | relative_url | bust_file_cache }}"></script>
<script>
let theme = determineComputedTheme();
const ninjaKeys = document.querySelector('ninja-keys');
if (theme === 'dark') {
ninjaKeys.classList.add('dark');
} else {
ninjaKeys.classList.remove('dark');
}
const openSearchModal = () => {
// collapse navbarNav if expanded on mobile
const navbarNav = document.querySelector('.navbar-collapse');
if (navbarNav.classList.contains('show')) {
navbarNav.classList.remove('show');
}
ninjaKeys.open();
};
</script>
{% endif %}
1 change: 1 addition & 0 deletions _layouts/default.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@
{% include scripts/imageLayouts.liquid %}
{% include scripts/jekyll_tabs.liquid %}
{% include scripts/back_to_top.liquid %}
{% include scripts/search.liquid %}
</body>
</html>
16 changes: 15 additions & 1 deletion _sass/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ ul.task-list input[type="checkbox"] {
}
}

#light-toggle {
#light-toggle,
#search-toggle {
padding: 0;
border: 0;
background-color: inherit;
Expand Down Expand Up @@ -1109,3 +1110,16 @@ swiper-container {
border-bottom: 2px solid var(--global-text-color);
}
}

// Ninja Keys
// for more options, check https://github.com/ssleptsov/ninja-keys?tab=readme-ov-file#css-variables
ninja-keys {
--ninja-accent-color: var(--global-theme-color);
--ninja-icon-size: 0px;
--ninja-modal-background: var(--global-bg-color);
--ninja-z-index: 1031;
}

ninja-keys::part(ninja-input-wrapper) {
background: var(--global-bg-color);
}
Loading

0 comments on commit 92cebc9

Please sign in to comment.