finally fixed the fucking table of contents

This commit is contained in:
2025-04-03 22:33:47 +02:00
parent 60901a398e
commit b99e185446
5 changed files with 78 additions and 61 deletions

View File

@@ -1,16 +1,23 @@
<script lang="ts"> <script lang="ts">
let { import {onMount} from 'svelte';
document,
querySelector = "h2, h3, h4, h5",
}: {
document: Document;
querySelector?: string;
} = $props();
var idCounter: number = 0; let idCounter: number = 0;
let container: HTMLElement;
onMount(() => {
let headers = getHeaders();
headers.forEach(header => {
let headerId = getHeaderId(header);
var element = document.createElement("li");
element.classList += "toc-level-" + getHeaderLevel(header);
element.innerHTML = `<a href="#${headerId}">${(header as HTMLElement).innerHTML}</a>`;
container.appendChild(element);
});
});
let getHeaders = function(): NodeList { let getHeaders = function(): NodeList {
return document.querySelectorAll(querySelector); return document.querySelectorAll("h2, h3, h4, h5");
} }
let getHeaderId = function(header: Node): string { let getHeaderId = function(header: Node): string {
@@ -40,14 +47,15 @@
</script> </script>
<div class="toc-container"> <div class="toc-container">
<ul class="toc-list"> <ul class="toc-list" bind:this={container}>
{#each getHeaders() as header} <!-- {#each getHeaders() as header}
<li class="toc-level-{getHeaderLevel(header)}"><a href="#{getHeaderId(header)}">{(header as HTMLElement).innerText}</a></li> <li class="toc-level-{getHeaderLevel(header)}"><a href="#{getHeaderId(header)}">{(header as HTMLElement).innerText}</a></li>
{/each} {/each} -->
</ul> </ul>
</div> </div>
<style> <style>
:global {
.toc-container { .toc-container {
width: 80%; width: 80%;
margin-left: auto; margin-left: auto;
@@ -97,4 +105,5 @@
.toc-level-1 a::before, .toc-level-2 a::before, .toc-level-3 a::before { .toc-level-1 a::before, .toc-level-2 a::before, .toc-level-3 a::before {
content: "↳ "; content: "↳ ";
} }
}
</style> </style>

View File

@@ -2,6 +2,8 @@
import Header from "$lib/header.svelte"; import Header from "$lib/header.svelte";
import Footer from "$lib/footer.svelte"; import Footer from "$lib/footer.svelte";
export const prerender = true;
let { children } = $props(); let { children } = $props();
</script> </script>
@@ -54,7 +56,7 @@
height: 100%; height: 100%;
width: 100%; width: 100%;
background-color: var(--color-waters); background-color: var(--color-waters);
mask-image: url('bremen-waters-white.svg'); mask-image: url('/bremen-waters-white.svg');
mask-position: center; mask-position: center;
background-position: center; background-position: center;
background-attachment: fixed; background-attachment: fixed;

View File

@@ -21,7 +21,7 @@
<p>This is a listing of some of my more noteworthy projects that can be found on the web.</p> <p>This is a listing of some of my more noteworthy projects that can be found on the web.</p>
{#if browser} {#if browser}
<TableOfContents {document}/> <TableOfContents />
{/if} {/if}
<h2>Active Projects</h2> <h2>Active Projects</h2>

View File

@@ -6,7 +6,7 @@
<BannerTitle title="Project N5 Progress Update: 2025-03-16" subtitle="Refactoring" banner="/projects/projectn5/devlog/20250316/fishmonger.webp" /> <BannerTitle title="Project N5 Progress Update: 2025-03-16" subtitle="Refactoring" banner="/projects/projectn5/devlog/20250316/fishmonger.webp" />
<TableOfContents document={document}/> <TableOfContents />
<p>I've been making a lot of progress in a lot of different areas, so I won't be able to elaborate on every little detail, but I'll focus on more major things. Excited to share what I've been working on!</p> <p>I've been making a lot of progress in a lot of different areas, so I won't be able to elaborate on every little detail, but I'll focus on more major things. Excited to share what I've been working on!</p>

View File

@@ -3,9 +3,15 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */ /** @type {import('@sveltejs/kit').Config} */
const config = { const config = {
preprocess: vitePreprocess(), // preprocess: vitePreprocess(),
kit: { kit: {
adapter: adapter(), adapter: adapter({
pages: 'build',
assets: 'build',
fallback: undefined,
preprocess: false,
strict: true,
}),
}, },
}; };