Render index page for wiki

This commit is contained in:
Maciej Jur 2023-06-06 19:28:01 +02:00
parent 1b5b644356
commit 6c89435b7a
3 changed files with 21 additions and 5 deletions

View file

@ -1,6 +1,6 @@
--- ---
import { Tree, pathify } from "@utils/tree"; import { Tree, pathify } from "@utils/tree";
import { Maybe } from "purify-ts"; import type { Maybe } from "purify-ts";
interface Props { interface Props {
@ -18,9 +18,8 @@ const { tree, prefix } = Astro.props;
<ul> <ul>
{pages.map(page => {pages.map(page =>
<li> <li>
{Maybe.of(Maybe.catMaybes([prefix, page.slug])) {page.slug
.filter(xs => xs.length > 0) .chain(slug => prefix.map(prefix => pathify(prefix, slug)))
.map(xs => pathify(...xs))
.mapOrDefault(href => .mapOrDefault(href =>
<a href={href}>{page.title}</a>, <a href={href}>{page.title}</a>,
<span>{page.title}</span> <span>{page.title}</span>

View file

@ -20,8 +20,8 @@ const { Content } = await entry.render();
--- ---
<Base> <Base>
<Tree tree={tree} prefix={Maybe.of("/wiki/")}/>
<main> <main>
<Tree tree={tree} prefix={Maybe.of("/wiki/")}/>
<Content /> <Content />
</main> </main>
</Base> </Base>

View file

@ -0,0 +1,17 @@
---
import Base from "@layouts/Base.astro";
import Tree from "@components/tree/Tree.astro";
import { collapse } from "@utils/tree";
import { getCollection } from "astro:content";
import { Maybe } from "purify-ts";
const tree = collapse(await getCollection('wiki'));
---
<Base>
<main>
<Tree tree={tree} prefix={Maybe.of("wiki")}/>
siema
</main>
</Base>