|
|
|
|
@ -1,11 +1,10 @@
@@ -1,11 +1,10 @@
|
|
|
|
|
<script lang="ts"> |
|
|
|
|
import { ndk } from '$lib/ndk'; |
|
|
|
|
import { idList } from '$lib/stores'; |
|
|
|
|
import { idList, isLeftHamburgerMenuInUse, leftHamburgerMenuHrefs, leftHamburgerMenuItems } from '$lib/stores'; |
|
|
|
|
import type { NDKEvent } from '@nostr-dev-kit/ndk'; |
|
|
|
|
import { page } from '$app/stores'; |
|
|
|
|
import { Heading, Sidebar, SidebarGroup, SidebarItem, SidebarWrapper, Skeleton, TextPlaceholder } from 'flowbite-svelte'; |
|
|
|
|
import showdown from 'showdown'; |
|
|
|
|
import { sineIn } from 'svelte/easing'; |
|
|
|
|
import { onMount } from 'svelte'; |
|
|
|
|
|
|
|
|
|
$: activeHash = $page.url.hash; |
|
|
|
|
@ -13,7 +12,25 @@
@@ -13,7 +12,25 @@
|
|
|
|
|
async function getEvents(): Promise<NDKEvent[]> { |
|
|
|
|
const eventPromises = $idList.map(async (id) => await $ndk.fetchEvent(id)); |
|
|
|
|
const events = await Promise.all(eventPromises); |
|
|
|
|
return events.filter((event) => event != null); |
|
|
|
|
|
|
|
|
|
const filteredEvents = events.filter((event) => event != null); |
|
|
|
|
|
|
|
|
|
const eventNames: string[] = []; |
|
|
|
|
const eventHrefs = new Map<string, string>(); |
|
|
|
|
|
|
|
|
|
filteredEvents.forEach(event => { |
|
|
|
|
const title = event.getMatchingTags('title')[0][1]; |
|
|
|
|
|
|
|
|
|
eventNames.push(title); |
|
|
|
|
|
|
|
|
|
const normalizedTitle = normalizeHashPath(title); |
|
|
|
|
eventHrefs.set(title, `${$page.url.pathname}#${normalizedTitle}`); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
leftHamburgerMenuItems.set(eventNames); |
|
|
|
|
leftHamburgerMenuHrefs.set(eventHrefs); |
|
|
|
|
|
|
|
|
|
return filteredEvents; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function normalizeHashPath(str: string): string { |
|
|
|
|
@ -40,13 +57,21 @@
@@ -40,13 +57,21 @@
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const sidebarBreakpointWidth = 1140; |
|
|
|
|
const setLeftHamburgerMenuInUse = () => { |
|
|
|
|
isLeftHamburgerMenuInUse.set(window.innerWidth < sidebarBreakpointWidth ? true : false); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
onMount(() => { |
|
|
|
|
window.addEventListener('hashchange', scrollToElementWithOffset); |
|
|
|
|
// Also handle the case where the user lands on the page with a hash in the URL |
|
|
|
|
scrollToElementWithOffset(); |
|
|
|
|
|
|
|
|
|
window.addEventListener('resize', setLeftHamburgerMenuInUse); |
|
|
|
|
|
|
|
|
|
return () => { |
|
|
|
|
window.removeEventListener('hashchange', scrollToElementWithOffset); |
|
|
|
|
window.removeEventListener('resize', setLeftHamburgerMenuInUse); |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
@ -54,15 +79,16 @@
@@ -54,15 +79,16 @@
|
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
{#await getEvents()} |
|
|
|
|
{#if !$isLeftHamburgerMenuInUse} |
|
|
|
|
<Sidebar class='sidebar-leather fixed top-20 left-0 px-4 w-60'> |
|
|
|
|
<SidebarWrapper> |
|
|
|
|
<Skeleton/> |
|
|
|
|
</SidebarWrapper> |
|
|
|
|
</Sidebar> |
|
|
|
|
<TextPlaceholder class='max-w-2xl'/> |
|
|
|
|
{/if} |
|
|
|
|
{:then events} |
|
|
|
|
<!-- TODO: Collapse the sidebar when the page gets below a certain width. --> |
|
|
|
|
<!-- TODO: Handle hash paths for navigation within the article. --> |
|
|
|
|
{#if !$isLeftHamburgerMenuInUse} |
|
|
|
|
<Sidebar class='sidebar-leather fixed top-20 left-0 px-4 w-60' {activeHash}> |
|
|
|
|
<SidebarWrapper> |
|
|
|
|
<SidebarGroup class='sidebar-group-leather overflow-y-scroll'> |
|
|
|
|
@ -76,6 +102,7 @@
@@ -76,6 +102,7 @@
|
|
|
|
|
</SidebarGroup> |
|
|
|
|
</SidebarWrapper> |
|
|
|
|
</Sidebar> |
|
|
|
|
{/if} |
|
|
|
|
<div class='flex flex-col space-y-4 max-w-2xl'> |
|
|
|
|
{#each events as event} |
|
|
|
|
<div class='note-leather flex flex-col space-y-2'> |
|
|
|
|
|