Skip to content

Commit 89a8400

Browse files
committed
Add pages navigation
1 parent d6bfa89 commit 89a8400

File tree

18 files changed

+251
-48
lines changed

18 files changed

+251
-48
lines changed

docs/docset.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,11 @@ toc:
105105
children:
106106
- file: first-page.md
107107
- file: second-page.md
108+
- folder: deeply-nested
109+
children:
110+
- file: index.md
111+
- file: foo.md
112+
- file: bar.md
113+
- folder: baz
114+
children:
115+
- file: qux.md

docs/testing/deeply-nested/bar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Bar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Qux

docs/testing/deeply-nested/foo.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Foo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Deeply Nested
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap');
1+
@font-face {
2+
font-family: "Inter";
3+
src: url("./fonts/InterVariable.woff2") format("woff2");
4+
}
25

6+
@font-face {
7+
font-family: "Mier B";
8+
src: url("./fonts/MierB-Regular.woff2") format("woff2");
9+
font-weight: normal;
10+
}
11+
12+
@font-face {
13+
font-family: "Mier B";
14+
src: url("./fonts/MierB-Bold.woff2") format("woff2");
15+
font-weight: bold;
16+
}
317

418
@font-face {
519
font-family: "Mier B";
6-
src: url("./fonts/MierB-Regular.woff2") format("woff2")
20+
src: url("./fonts/MierB-Demi.woff2") format("woff2");
21+
font-weight: 600;
722
}
337 KB
Binary file not shown.
51.9 KB
Binary file not shown.
52.4 KB
Binary file not shown.

src/Elastic.Markdown/Assets/main.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import hljs from "highlight.js";
22
import {mergeHTMLPlugin} from "./hljs-merge-html-plugin";
3+
import {$, $$} from 'select-dom/strict.js'
34

45
hljs.registerLanguage('apiheader', function() {
56
return {
@@ -16,3 +17,41 @@ hljs.registerLanguage('apiheader', function() {
1617

1718
hljs.addPlugin(mergeHTMLPlugin);
1819
hljs.highlightAll();
20+
21+
22+
type NavState = { [key: string]: boolean };
23+
24+
25+
function keepNavState(element: HTMLElement) {
26+
const inputs = $$('input[type="checkbox"]', element);
27+
const sessionState = JSON.parse(sessionStorage.getItem('pagesNavState')) as NavState
28+
if (sessionState) {
29+
inputs.forEach(input => {
30+
const key = input.id;
31+
input.checked = input.checked || sessionState[key];
32+
});
33+
}
34+
window.addEventListener('beforeunload', () => {
35+
const state = inputs.reduce((state: NavState, input) => {
36+
const key = input.id;
37+
const value = input.checked;
38+
return { ...state, [key]: value};
39+
}, {});
40+
sessionStorage.setItem('pagesNavState', JSON.stringify(state));
41+
});
42+
}
43+
44+
function keepNavPosition(element: HTMLElement) {
45+
const scrollPosition = sessionStorage.getItem('pagesNavScrollPosition');
46+
if (scrollPosition) {
47+
element.scrollTop = parseInt(scrollPosition);
48+
}
49+
window.addEventListener('beforeunload', () => {
50+
sessionStorage.setItem('pagesNavScrollPosition', element.scrollTop.toString());
51+
});
52+
}
53+
54+
const pagesNav = $('#pages-nav');
55+
56+
keepNavState(pagesNav);
57+
keepNavPosition(pagesNav);

0 commit comments

Comments
 (0)