Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
distinguish between directories and child items
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Apr 8, 2024
1 parent 230eb0c commit c0bc03e
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions web/src/routes/[...path]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { base } from '$app/paths';
import type { HierarchyEntry } from '$lib/files';
import type { HierarchyEntry, HierarchyItem } from '$lib/files';
import { onMount } from 'svelte';
import GridItem from '../GridItem.svelte';
export let data;
Expand All @@ -14,16 +15,41 @@ function getChilds() {
return childItems;
}
$: current = getChilds().find(child => child.path === data.slug);
function getItems() {
const items = new Array<HierarchyItem>();
const addLevel = ((entry: HierarchyEntry) => {
items.push(...entry.items);
entry.children.forEach(child => addLevel(child));
});
addLevel(data.posts);
return items;
}
onMount(() => {
dirs = getChilds();
items = getItems();
});
let dirs: HierarchyEntry[];
let items: HierarchyItem[];
$: currentDir = dirs?.find(child => child.path === "/" + data.slug);
$: currentItem = items?.find(item => item.path === "/" + data.slug);
</script>

<div>
<a href={base}>See all assets</a>
<p>{data.slug} --- {currentDir?.path}</p>

{#if current}
{#if currentDir}
<article>
<GridItem child={currentDir} />
</article>
{:else if currentItem}
<article>
<GridItem child={current} />
<p>{JSON.stringify(currentItem, null, 2)}</p>
<a href={base}{currentItem.path}>Download</a>
</article>
{:else}
<code><pre>
Expand Down

0 comments on commit c0bc03e

Please sign in to comment.