Feature: Dynamically sets the search shortcut key based on the user's platform (#2461)

This addresses issue #2437 by:
- Adding a new script that dynamically sets the search keyboard shortcut
by checking what platform the user is currently using
- Loading this script in `default.liquid`

<img width="1150" alt="SCR-20240529-cdfe"
src="https://github.com/alshedivat/al-folio/assets/16251412/7c4125fc-5028-422f-97d5-0df729e30fa7">
This commit is contained in:
Andrew Leonard 2024-05-31 17:23:46 -04:00 committed by GitHub
parent b35450e474
commit afc56cc987
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -73,5 +73,6 @@
{% include scripts/jekyll_tabs.liquid %} {% include scripts/jekyll_tabs.liquid %}
{% include scripts/back_to_top.liquid %} {% include scripts/back_to_top.liquid %}
{% include scripts/search.liquid %} {% include scripts/search.liquid %}
<script src="{{ '/assets/js/shortcut-key.js' | relative_url }}"></script>
</body> </body>
</html> </html>

11
assets/js/shortcut-key.js Normal file
View File

@ -0,0 +1,11 @@
// Check if the user is on a Mac and update the shortcut key for search accordingly
document.onreadystatechange = () => {
if (document.readyState === "interactive") {
let isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0;
let shortcutKeyElement = document.querySelector("#search-toggle .nav-link");
if (shortcutKeyElement && isMac) {
// use the unicode for command key
shortcutKeyElement.innerHTML = '&#x2318; k <i class="ti ti-search"></i>';
}
}
};