Extract wiki page layout
This commit is contained in:
parent
dd70c2bc38
commit
ad9efaccd7
|
@ -1,11 +1,11 @@
|
||||||
---
|
---
|
||||||
import { Tree, pathify } from "@utils/tree";
|
import { PageTree, pathify } from "@utils/tree";
|
||||||
import type { Maybe } from "purify-ts";
|
import { Maybe } from "purify-ts";
|
||||||
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
tree: Tree;
|
tree: PageTree;
|
||||||
slug: string;
|
slug: Maybe<string>;
|
||||||
prefix: Maybe<string>;
|
prefix: Maybe<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,12 @@ function compare(a: {title: string}, b: {title: string}) {
|
||||||
sensitivity: "base",
|
sensitivity: "base",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkCurrent(checked: Maybe<string>) {
|
||||||
|
return Maybe
|
||||||
|
.sequence([checked, slug])
|
||||||
|
.mapOrDefault(([a, b]) => a == pathify(b), false)
|
||||||
|
}
|
||||||
---
|
---
|
||||||
|
|
||||||
{tree.children
|
{tree.children
|
||||||
|
@ -26,7 +32,7 @@ function compare(a: {title: string}, b: {title: string}) {
|
||||||
<ul class="link-tree__nav-list">
|
<ul class="link-tree__nav-list">
|
||||||
{pages
|
{pages
|
||||||
.sort(compare)
|
.sort(compare)
|
||||||
.map(page => ({...page, current: page.slug.mapOrDefault(other => other === pathify(slug), false)}))
|
.map(page => ({...page, current: checkCurrent(page.slug) }))
|
||||||
.map(page =>
|
.map(page =>
|
||||||
<li class="link-tree__nav-list-item">
|
<li class="link-tree__nav-list-item">
|
||||||
{page.slug
|
{page.slug
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
---
|
---
|
||||||
import List from "./List.astro";
|
import List from "./List.astro";
|
||||||
import { Tree, pathify } from "@utils/tree";
|
import { PageTree, pathify } from "@utils/tree";
|
||||||
import type { Maybe } from "purify-ts";
|
import type { Maybe } from "purify-ts";
|
||||||
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
heading: string;
|
heading: string;
|
||||||
tree: Tree;
|
tree: PageTree;
|
||||||
slug: string;
|
slug: Maybe<string>;
|
||||||
prefix: Maybe<string>;
|
prefix: Maybe<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
48
src/layouts/Wiki.astro
Normal file
48
src/layouts/Wiki.astro
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
---
|
||||||
|
import Base from "@layouts/Base.astro";
|
||||||
|
import Tree from "@components/tree/Tree.astro";
|
||||||
|
import { getCollection } from "astro:content";
|
||||||
|
import { Maybe, MaybeAsync } from "purify-ts";
|
||||||
|
import { collapse, type PageTree } from "@utils/tree";
|
||||||
|
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
frontmatter: {
|
||||||
|
title: string;
|
||||||
|
};
|
||||||
|
slug?: string;
|
||||||
|
tree?: PageTree;
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
frontmatter,
|
||||||
|
slug,
|
||||||
|
tree,
|
||||||
|
} = Astro.props;
|
||||||
|
|
||||||
|
|
||||||
|
function constructTree(tree?: PageTree) {
|
||||||
|
return MaybeAsync
|
||||||
|
.liftMaybe(Maybe.fromNullable(tree))
|
||||||
|
.alt(
|
||||||
|
MaybeAsync(async () => await getCollection('wiki'))
|
||||||
|
.map(collapse));
|
||||||
|
}
|
||||||
|
|
||||||
|
const pageTree = (await constructTree(tree))
|
||||||
|
.orDefaultLazy(() => { throw new Error("Couldn't load page tree") });
|
||||||
|
---
|
||||||
|
|
||||||
|
<Base>
|
||||||
|
<main class="wiki-main">
|
||||||
|
<Tree heading="Personal Wiki"
|
||||||
|
tree={pageTree}
|
||||||
|
slug={Maybe.fromNullable(slug)}
|
||||||
|
prefix={Maybe.of("/wiki/")}
|
||||||
|
/>
|
||||||
|
<article class="wiki-article markdown">
|
||||||
|
<h1>{frontmatter.title}</h1>
|
||||||
|
<slot />
|
||||||
|
</article>
|
||||||
|
</main>
|
||||||
|
</Base>
|
|
@ -1,10 +1,8 @@
|
||||||
---
|
---
|
||||||
import Tree from '@components/tree/Tree.astro';
|
|
||||||
import Base from '@layouts/Base.astro';
|
|
||||||
import type { InferGetStaticPropsType } from 'astro';
|
import type { InferGetStaticPropsType } from 'astro';
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
import { Maybe } from 'purify-ts';
|
|
||||||
import { collapse } from '@utils/tree';
|
import { collapse } from '@utils/tree';
|
||||||
|
import Wiki from '@layouts/Wiki.astro';
|
||||||
|
|
||||||
|
|
||||||
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
|
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
|
||||||
|
@ -19,12 +17,6 @@ const { tree, entry } = Astro.props;
|
||||||
const { Content } = await entry.render();
|
const { Content } = await entry.render();
|
||||||
---
|
---
|
||||||
|
|
||||||
<Base>
|
<Wiki slug={entry.slug} frontmatter={entry.data} tree={tree}>
|
||||||
<main class="wiki-main">
|
|
||||||
<Tree heading="Personal Wiki" tree={tree} slug={entry.slug} prefix={Maybe.of("/wiki/")}/>
|
|
||||||
<article class="wiki-article markdown">
|
|
||||||
<h1>{entry.data.title}</h1>
|
|
||||||
<Content />
|
<Content />
|
||||||
</article>
|
</Wiki>
|
||||||
</main>
|
|
||||||
</Base>
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
---
|
|
||||||
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 class="wiki-main">
|
|
||||||
<Tree heading="Personal Wiki" tree={tree} slug="wiki" prefix={Maybe.of("wiki")} />
|
|
||||||
<article class="wiki-article">
|
|
||||||
siema
|
|
||||||
</article>
|
|
||||||
</main>
|
|
||||||
</Base>
|
|
6
src/pages/wiki/index.md
Normal file
6
src/pages/wiki/index.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
layout: ../../layouts/Wiki.astro
|
||||||
|
title: Wiki home page
|
||||||
|
---
|
||||||
|
|
||||||
|
Hello
|
0
src/schema.d.ts → src/types.d.ts
vendored
0
src/schema.d.ts → src/types.d.ts
vendored
|
@ -6,14 +6,14 @@ interface Page {
|
||||||
data: { title: string };
|
data: { title: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Tree {
|
export interface PageTree {
|
||||||
title: string;
|
title: string;
|
||||||
slug: Maybe<string>;
|
slug: Maybe<string>;
|
||||||
children: Maybe<{ [key: string]: Tree }>;
|
children: Maybe<{ [key: string]: PageTree }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function collapse(pages: Page[]): Tree {
|
export function collapse(pages: Page[]): PageTree {
|
||||||
const root: Tree = { title: '', slug: Maybe.empty(), children: Maybe.empty() };
|
const root: PageTree = { title: '', slug: Maybe.empty(), children: Maybe.empty() };
|
||||||
|
|
||||||
for (const page of pages) {
|
for (const page of pages) {
|
||||||
const ptr = page.slug.split('/')
|
const ptr = page.slug.split('/')
|
||||||
|
|
Loading…
Reference in a new issue