Skip to content

Commit f44585d

Browse files
committed
feat: fold toc, fix z-index issue
1 parent 721a880 commit f44585d

File tree

9 files changed

+228
-126
lines changed

9 files changed

+228
-126
lines changed

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Hi [👋]{.waving} 欢迎来到我的笔记本~
1616
:::
1717
::
1818

19-
::grid{align=equal gapx=15px gapy=20px}
19+
::grid{align=equal gapx=10px gapy=20px .home-grid}
2020
:sep{span=24}
2121
:::fold{always expand title="关于我" info .home-fontawesome-list}
2222
 :user: 网名 Xecades,读作 /'zɛkeɪdz/

src/assets/css/markdown.styl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ schemer(--quote-background-invert, 0, 1);
4444
.katex
4545
font-size: 1.08em;
4646

47+
.cjk_fallback
48+
font-family: $font-family;
49+
4750
.katex-display
4851
margin: 0.3em 2px;
4952

@@ -354,6 +357,12 @@ schemer(--quote-background-invert, 0, 1);
354357

355358
&:hover
356359
color: var(--color);
360+
361+
/* .home-grid 标签 */
362+
.home-grid .fold
363+
.fold-height-listener
364+
dual(--wrapper-padding, 0.8em 1.4em, 0.2em 0.9em);
365+
357366

358367
/* Animation */
359368
@keyframes waving

src/assets/ts/rightbar.ts

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,23 @@ import type { MarkdownHeaderJsx } from "vite-plugin-vue-xecades-note";
55
import type { Ref } from "vue";
66

77
/** Header type used for ref rendering */
8-
export type HeaderRef = MarkdownHeaderJsx & {
9-
readonly width: string;
10-
readonly indent: string;
11-
readonly opacity: string;
8+
export type SerialHeader = MarkdownHeaderJsx & {
9+
width: string;
10+
indent: string;
11+
opacity: string;
12+
index: number;
1213
};
14+
export type CascadeHeader = SerialHeader & { children: SerialHeader[] };
1315

1416
const width_preset: string[] = ["50px", "40px", "30px", "20px", "13px"];
15-
const indent_preset: string[] = ["0rem", "1rem", "1.7rem", "2.3rem", "2.8rem"];
16-
const opacity_preset: string[] = ["1", "0.7", "0.7", "0.7", "0.7"];
17+
const indent_preset: string[] = [
18+
"0rem",
19+
"1.3rem",
20+
"1.7rem",
21+
"2.3rem",
22+
"2.8rem",
23+
];
24+
const opacity_preset: string[] = ["1", "0.8", "0.7", "0.7", "0.7"];
1725

1826
/**
1927
* Determine rightbar status (i.e. whether to display or not).
@@ -32,20 +40,41 @@ export const get_rightbar_status = (): RIGHTBAR_STATUS =>
3240
* @param toc - Raw TOC data imported from json
3341
* @returns Normalized TOC data
3442
*/
35-
export const normalize_toc = (toc: MarkdownHeaderJsx[]): HeaderRef[] => {
36-
const levels: number[] = toc.map((item) => item.level);
43+
export const serial_toc = (toc: MarkdownHeaderJsx[]): SerialHeader[] => {
44+
const levels = toc.map((item) => item.level);
45+
const minLevel = Math.min(...levels);
46+
const maxLevel = Math.max(...levels);
3747

38-
const maxLevel: number = Math.max(...levels);
39-
const minLevel: number = Math.min(...levels);
40-
41-
return toc.map((item) => ({
48+
return toc.map((item, i) => ({
4249
...item,
4350
width: width_preset[4 + item.level - maxLevel],
4451
indent: indent_preset[item.level - minLevel],
4552
opacity: opacity_preset[item.level - minLevel],
53+
level: item.level - minLevel,
54+
index: i,
4655
}));
4756
};
4857

58+
export const cascade_toc = (s_toc: SerialHeader[]): CascadeHeader[] => {
59+
let res: CascadeHeader[] = [];
60+
let prev_root = 0;
61+
62+
for (let i = 1; i < s_toc.length; i++) {
63+
if (s_toc[i].level === s_toc[prev_root].level) {
64+
const children = s_toc.slice(prev_root + 1, i);
65+
res.push({ ...s_toc[prev_root], children });
66+
prev_root = i;
67+
}
68+
}
69+
70+
if (prev_root < s_toc.length) {
71+
const children = s_toc.slice(prev_root + 1);
72+
res.push({ ...s_toc[prev_root], children });
73+
}
74+
75+
return res;
76+
};
77+
4978
/**
5079
* Scroll listener class for rightbar.
5180
*/

src/assets/ts/utils.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@ export const sleep = (ms: number) =>
5858
*
5959
* @param id - ID of the element to navigate to
6060
* @param smooth - Whether to scroll smoothly or not
61+
* @param pushState - Whether to push state to history or not
6162
*/
62-
export const navigate = (id: string, smooth: boolean = true) => {
63+
export const navigate = (
64+
id: string,
65+
smooth: boolean = true,
66+
pushState: boolean = true
67+
) => {
6368
const OFFSET = 4 * 16;
6469
let el = document.getElementById(id);
6570
if (el) {
6671
const y = el.getBoundingClientRect().top + window.scrollY - OFFSET;
6772

6873
window.scrollTo({ top: y, behavior: smooth ? "smooth" : "auto" });
69-
history.pushState(null, "", `#${id}`);
74+
if (pushState) history.pushState(null, "", `#${id}`);
7075
}
7176
};
7277

src/components/LeftBar.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,14 @@ $width = $toc-offset-left + $toc-width;
235235
dual(--offset-top, 28px, 32px);
236236
dual(--offset-left, 35px, 27px);
237237
dual(--height, calc(100vh - var(--offset-top) * 2), unset);
238+
dual(--z-index, 100, 1001);
238239
239240
position: fixed;
240241
left: var(--offset-left);
241242
top: var(--offset-top);
242243
width: $width;
243244
height: var(--height);
244-
z-index: 100;
245+
z-index: var(--z-index);
245246
246247
.nav
247248
display: flex;

src/components/Logo.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ onMounted(async () => {
3939
</script>
4040

4141
<template>
42-
<a
43-
id="logo"
44-
href="https://xecades.xyz/"
45-
target="_blank"
46-
title="点击跳转主页"
47-
>
42+
<RouterLink id="logo" to="/">
4843
<svg
4944
id="logo-svg"
5045
xmlns="http://www.w3.org/2000/svg"
@@ -57,7 +52,7 @@ onMounted(async () => {
5752
v-for="svg in svgs"
5853
/>
5954
</svg>
60-
</a>
55+
</RouterLink>
6156
</template>
6257

6358
<style scoped lang="stylus">

0 commit comments

Comments
 (0)