Skip to content

Commit 5282566

Browse files
add capability to navigate between pages with p and n
1 parent 61f21d0 commit 5282566

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

docs/astro.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ export default defineConfig({
6161
starlightLinksValidator({ errorOnLocalLinks: false }),
6262
starlightImageZoom(),
6363
],
64+
head: [
65+
{
66+
tag: 'script',
67+
attrs: {
68+
src: '/dbLinter/keyboard-nav.js',
69+
defer: true,
70+
},
71+
},
72+
],
6473
}),
6574
mermaid({
6675
theme: 'forest',

docs/public/keyboard-nav.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
document.addEventListener('DOMContentLoaded', () => {
2+
document.addEventListener('keydown', (event) => {
3+
// Ignore if user is typing in an input, textarea, or contenteditable element
4+
if (
5+
event.target.matches('input, textarea, [contenteditable="true"]') ||
6+
event.ctrlKey ||
7+
event.metaKey ||
8+
event.altKey
9+
) {
10+
return;
11+
}
12+
13+
// Find pagination links
14+
const pagination = document.querySelector('.pagination-links');
15+
if (!pagination) return;
16+
17+
if (event.key === 'p' || event.key === 'P') {
18+
// Navigate to previous page
19+
const prevLink = pagination.querySelector('a[rel="prev"]');
20+
if (prevLink) {
21+
event.preventDefault();
22+
window.location.href = prevLink.href;
23+
}
24+
} else if (event.key === 'n' || event.key === 'N') {
25+
// Navigate to next page
26+
const nextLink = pagination.querySelector('a[rel="next"]');
27+
if (nextLink) {
28+
event.preventDefault();
29+
window.location.href = nextLink.href;
30+
}
31+
}
32+
});
33+
});

0 commit comments

Comments
 (0)