diff --git a/astro.config.mjs b/astro.config.mjs index 5613aa0f8..4ba077e80 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -123,6 +123,12 @@ export default defineConfig({ editLink: { baseUrl: 'https://github.com/tauri-apps/tauri-docs/edit/starlight', }, + head: [ + { + tag: 'script', + attrs: { src: '/javascript/navigator.js' }, + }, + ], customCss: ['./src/styles/custom.css'], sidebar: [ { diff --git a/public/javascript/navigator.js b/public/javascript/navigator.js new file mode 100644 index 000000000..678ff0f1c --- /dev/null +++ b/public/javascript/navigator.js @@ -0,0 +1,27 @@ +(function chapterNavigation() { + document.addEventListener('keydown', function (e) { + if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { + return; + } + if (window.search && window.search.hasFocus()) { + return; + } + + switch (e.key) { + case 'ArrowRight': + e.preventDefault(); + var nextButton = document.querySelector('a[rel="next"]'); + if (nextButton) { + window.location.href = nextButton.href; + } + break; + case 'ArrowLeft': + e.preventDefault(); + var previousButton = document.querySelector('a[rel="prev"]'); + if (previousButton) { + window.location.href = previousButton.href; + } + break; + } + }); +})();