Skip to content

Commit

Permalink
ZSidebar - fix url error.
Browse files Browse the repository at this point in the history
Docs - load all markdown file.
  • Loading branch information
vhtmui_5600g committed Nov 20, 2024
1 parent 0c2bcca commit ea7b585
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 28 deletions.
4 changes: 3 additions & 1 deletion src/lib/ZSibar/ZSidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@
// Set hightlight item
$effect(() => {
if (nowLink === $page.route.id) {
const url = new URL($page.url);
if (nowLink === url.pathname) {
selected_item = true;
} else if ($page.route.id.match(new RegExp(`^${nowLink}.+`, 'i')) && expand === false) {
selected_item = true;
} else {
selected_item = false;
}
});
$inspect($page);
//#endregion
</script>

Expand Down
17 changes: 14 additions & 3 deletions src/routes/+layout.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@ export async function load() {
.filter((d) => d.isDirectory())
.map((d) => path.join(d.parentPath, d.name).replaceAll('\\', '/').replaceAll(baseDir, ''));

const mdContent = await readFile('docs/PowerShell.md', 'utf-8');

const docDir = 'docs/';
const docItems = await readdir(docDir, { recursive: true, withFileTypes: true });
const docDirectory = docItems.map((d) => path.join(d.parentPath, d.name).replaceAll('\\', '/').replaceAll(docDir, '/docs/'));
const docDirectory = docItems.map((d) => path.join(d.parentPath, d.name).replaceAll('\\', '/').replaceAll(docDir, '/docs/').replace('.md', ''));

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

// get markdown.

// let mdContent = await readFile('docs/PowerShell.md', 'utf-8');

let mdContent = new Map();

for (const docItem of docItems) {
const name = docItem.name.replace('.md', '');
const docPath = path.join(docItem.parentPath, docItem.name);
const content = await readFile(docPath, 'utf-8');
mdContent.set(name, content);
}

return { directory, mdContent };
}
6 changes: 5 additions & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@
let lastY = $state();
function scrollHeader() {
let gap = Y - lastY;
if (top - gap < 0 && top - gap > -96) top = top - gap;
console.log(gap);
if (top - gap < 0 && top - gap > -96) {
top = top - gap;
} else if (top - gap >= 0) top = 0;
else if (top - gap <= -96) top = -96;
lastY = Y;
}
// Timer for header.
Expand Down
3 changes: 0 additions & 3 deletions src/routes/docs/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
let { data, ...props } = $props();
</script>

<div class="header">Sticky Header</div>
<div class="content">Scroll down to see the sticky header in action.</div>

{@render props.children?.()}

<style>
Expand Down
1 change: 0 additions & 1 deletion src/routes/docs/+page.server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @type {import('./$types').PageServerLoad} */
export async function load({parent}) {
const {dir}= await parent();
return {};
};
4 changes: 1 addition & 3 deletions src/routes/docs/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@
<title>Docs</title>
</svelte:head>

{#each data.dir as dir }
<p>{dir}</p>
{/each}

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { readFile } from 'node:fs/promises';
/** @type {import('./$types').PageServerLoad} */
export async function load({ parent, cookies }) {
export async function load({ parent, params }) {
// get content
const { mdContent } = await parent();

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

return { mdContent ,h1};
return { content };
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
import Markdown from 'svelte-exmarkdown';
import { gfmPlugin } from 'svelte-exmarkdown/gfm';
import rehypeSlug from 'rehype-slug';
import H1 from './H1.svelte';
import ZIcon from '$lib/ZIcon/ZIcon.svelte';
/** @type {import('./$types').PageData} */
let { data } = $props();
const headingIdPlugin = {
rehypePlugin: [rehypeSlug]
};
let md = $state('# hello world');
const plugins = [gfmPlugin(), headingIdPlugin];
</script>

<Markdown md={data.mdContent} {plugins} />
<Markdown md={data.content} {plugins} />

<style>
Expand Down
5 changes: 0 additions & 5 deletions src/routes/docs/doc/H1.svelte

This file was deleted.

1 change: 0 additions & 1 deletion src/routes/docs/doc/a.txt

This file was deleted.

17 changes: 14 additions & 3 deletions src/routes/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ let directory = items
.filter((d) => d.isDirectory())
.map((d) => path.join(d.parentPath, d.name).replaceAll('\\', '/').replaceAll(baseDir, ''));

const mdContent = await readFile('docs/PowerShell.md', 'utf-8');

const docDir = 'docs/';
const docItems = await readdir(docDir, { recursive: true, withFileTypes: true });
const docDirectory = docItems.map((d) => path.join(d.parentPath, d.name).replaceAll('\\', '/').replaceAll(docDir, '/docs/'));
const docDirectory = docItems.map((d) => path.join(d.parentPath, d.name).replaceAll('\\', '/').replaceAll(docDir, '/docs/').replace('.md', ''));

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

// get markdown.

// let mdContent = await readFile('docs/PowerShell.md', 'utf-8');

let mdContent = new Map();

for (const docItem of docItems) {
const name = docItem.name.replace('.md', '');
const docPath = path.join(docItem.parentPath, docItem.name);
const content = await readFile(docPath, 'utf-8');
mdContent.set(name, content);
}

console.log({ directory });
debugger

0 comments on commit ea7b585

Please sign in to comment.