Skip to content

Commit ea7b585

Browse files
author
vhtmui_5600g
committed
ZSidebar - fix url error.
Docs - load all markdown file.
1 parent 0c2bcca commit ea7b585

File tree

11 files changed

+42
-28
lines changed

11 files changed

+42
-28
lines changed

src/lib/ZSibar/ZSidebar.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,16 @@
116116
117117
// Set hightlight item
118118
$effect(() => {
119-
if (nowLink === $page.route.id) {
119+
const url = new URL($page.url);
120+
if (nowLink === url.pathname) {
120121
selected_item = true;
121122
} else if ($page.route.id.match(new RegExp(`^${nowLink}.+`, 'i')) && expand === false) {
122123
selected_item = true;
123124
} else {
124125
selected_item = false;
125126
}
126127
});
128+
$inspect($page);
127129
//#endregion
128130
</script>
129131

src/routes/+layout.server.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@ export async function load() {
1010
.filter((d) => d.isDirectory())
1111
.map((d) => path.join(d.parentPath, d.name).replaceAll('\\', '/').replaceAll(baseDir, ''));
1212

13-
const mdContent = await readFile('docs/PowerShell.md', 'utf-8');
14-
1513
const docDir = 'docs/';
1614
const docItems = await readdir(docDir, { recursive: true, withFileTypes: true });
17-
const docDirectory = docItems.map((d) => path.join(d.parentPath, d.name).replaceAll('\\', '/').replaceAll(docDir, '/docs/'));
15+
const docDirectory = docItems.map((d) => path.join(d.parentPath, d.name).replaceAll('\\', '/').replaceAll(docDir, '/docs/').replace('.md', ''));
1816

1917
directory = [...directory, ...docDirectory];
2018

19+
// get markdown.
20+
21+
// let mdContent = await readFile('docs/PowerShell.md', 'utf-8');
22+
23+
let mdContent = new Map();
24+
25+
for (const docItem of docItems) {
26+
const name = docItem.name.replace('.md', '');
27+
const docPath = path.join(docItem.parentPath, docItem.name);
28+
const content = await readFile(docPath, 'utf-8');
29+
mdContent.set(name, content);
30+
}
31+
2132
return { directory, mdContent };
2233
}

src/routes/+layout.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@
9999
let lastY = $state();
100100
function scrollHeader() {
101101
let gap = Y - lastY;
102-
if (top - gap < 0 && top - gap > -96) top = top - gap;
102+
console.log(gap);
103+
if (top - gap < 0 && top - gap > -96) {
104+
top = top - gap;
105+
} else if (top - gap >= 0) top = 0;
106+
else if (top - gap <= -96) top = -96;
103107
lastY = Y;
104108
}
105109
// Timer for header.

src/routes/docs/+layout.svelte

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
let { data, ...props } = $props();
99
</script>
1010

11-
<div class="header">Sticky Header</div>
12-
<div class="content">Scroll down to see the sticky header in action.</div>
13-
1411
{@render props.children?.()}
1512

1613
<style>

src/routes/docs/+page.server.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/** @type {import('./$types').PageServerLoad} */
22
export async function load({parent}) {
3-
const {dir}= await parent();
43
return {};
54
};

src/routes/docs/+page.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@
1212
<title>Docs</title>
1313
</svelte:head>
1414

15-
{#each data.dir as dir }
16-
<p>{dir}</p>
17-
{/each}
15+
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { readFile } from 'node:fs/promises';
22
/** @type {import('./$types').PageServerLoad} */
3-
export async function load({ parent, cookies }) {
3+
export async function load({ parent, params }) {
44
// get content
55
const { mdContent } = await parent();
66

7-
const h1 = await readFile('./src/routes/docs/doc/a.txt','utf8');
7+
const content = mdContent.get(params.doc);
88

9-
return { mdContent ,h1};
9+
return { content };
1010
}

src/routes/docs/doc/+page.svelte renamed to src/routes/docs/[doc]/+page.svelte

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22
import Markdown from 'svelte-exmarkdown';
33
import { gfmPlugin } from 'svelte-exmarkdown/gfm';
44
import rehypeSlug from 'rehype-slug';
5-
import H1 from './H1.svelte';
6-
import ZIcon from '$lib/ZIcon/ZIcon.svelte';
75
86
/** @type {import('./$types').PageData} */
97
let { data } = $props();
108
11-
129
const headingIdPlugin = {
1310
rehypePlugin: [rehypeSlug]
1411
};
1512
1613
let md = $state('# hello world');
1714
const plugins = [gfmPlugin(), headingIdPlugin];
15+
1816
</script>
1917

20-
<Markdown md={data.mdContent} {plugins} />
18+
<Markdown md={data.content} {plugins} />
2119

2220
<style>
2321

src/routes/docs/doc/H1.svelte

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/routes/docs/doc/a.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)