Skip to content

Commit 172d50a

Browse files
committed
improved nav link
1 parent 4da48da commit 172d50a

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

src/scss/page/_sidebar.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ aside.sidebar {
3737

3838
li {
3939
@extend .text-secondary;
40+
41+
&.active {
42+
@extend .text-body;
43+
}
44+
45+
li {
46+
@extend .ps-2;
47+
}
4048
}
4149

4250
line-height: 1.75;

src/views/guides/_sidebar.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* [GetMeNow](/guides/rooting/getmenow/)
1212
* [NVM](/guides/rooting/nvm/)
1313
* :bi-sliders:System Customization
14-
* [Multiview](/guides/customize/multiview/)
15-
* [Fix Jailer Config](/guides/customize/jail-fix/)
14+
* [Multi-View](/guides/customize/multiview/)
15+
* Fix Jailer Config
1616
* Move Apps to USB
1717
* Remove Store Demo

webpack/markdown-to-page.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {visit} from "unist-util-visit";
77
import {visitParents} from "unist-util-visit-parents";
88
import {toString} from "hast-util-to-string";
99
import rehypeStringify from "rehype-stringify";
10+
import {html} from "./htm-rehype.js";
11+
import {idFromTitle} from "./utils.js";
1012

1113
/**
1214
* @param relative {string}
@@ -56,12 +58,30 @@ export function sidebarProcessor(activePath) {
5658
*
5759
* @param li {import('hast').Element}
5860
*/
59-
function removeSubList(li) {
61+
function collapseSubList(li) {
6062
const ulIndex = li.children.findIndex(({tagName}) => tagName === 'ul');
6163
if (ulIndex < 0) {
6264
return;
6365
}
64-
li.children.splice(ulIndex, 1);
66+
const childrenBeforeUl = li.children.slice(0, ulIndex);
67+
let useCollapse = false;
68+
if (!childrenBeforeUl.find(({tagName}) => tagName === 'a')) {
69+
const index = childrenBeforeUl.findIndex(({type}) => type === 'text');
70+
if (index >= 0) {
71+
const title = li.children[index].value;
72+
const id = idFromTitle(title);
73+
li.children[index] = html`<a data-bs-toggle="collapse" href="#${id}" role="button" aria-expanded="false"
74+
aria-controls="${id}">${title}</a>`;
75+
li.children[ulIndex].properties = {
76+
'class': ['collapse'],
77+
'id': id
78+
}
79+
useCollapse = true;
80+
}
81+
}
82+
if (!useCollapse) {
83+
li.children.splice(ulIndex, 1);
84+
}
6585
}
6686

6787
return (tree, vfile) => {
@@ -83,7 +103,9 @@ export function sidebarProcessor(activePath) {
83103
let active = false;
84104
visit(li, node => node.tagName === 'a' && linkMatchesActive(node), () => active = true);
85105
if (!active) {
86-
removeSubList(li);
106+
collapseSubList(li);
107+
} else {
108+
li.properties.class = ['active'];
87109
}
88110
});
89111
};

webpack/remark/tabbed-code-block.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {visit} from "unist-util-visit";
22
import {toHtml} from "hast-util-to-html";
3-
import {kebabCase} from "lodash-es";
43
import {html} from "../htm-rehype.js";
4+
import {idFromTitle} from "../utils.js";
55

66
/** @typedef {Code & {tab: string, tabId: string}} TabbedCode */
77

@@ -21,7 +21,7 @@ export default function tabbedCodeBlock() {
2121
*/
2222
(node, index, parent) => {
2323
node['tab'] = node.meta;
24-
node['tabId'] = kebabCase(node.meta.replaceAll(/[^\w\s]+/g, (s) => `u${s.charCodeAt(0).toString(16)}`));
24+
node['tabId'] = idFromTitle(node.meta);
2525
if (isTabbedCodeBlock(parent.children[index + 1])) {
2626
return;
2727
}

webpack/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {kebabCase} from "lodash-es";
2+
3+
/**
4+
*
5+
* @param title {string}
6+
* @return {string}
7+
*/
8+
export function idFromTitle(title) {
9+
return kebabCase(title.replace(/[^\w\s]+/g, (s) => `u${s.charCodeAt(0).toString(16)}`));
10+
}

0 commit comments

Comments
 (0)