www/pages/resources.tsx

58 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-12-08 03:38:31 +00:00
import React, { ReactElement } from 'react';
import Layout from '../components/layout';
2021-12-08 04:30:34 +00:00
import style from '../styles/lists.module.css';
2022-04-23 23:03:43 +00:00
import res from '../public/resources.yaml';
2021-12-08 03:38:31 +00:00
type listItem = {
children?: listItem[] | string[];
url?: string;
title: string;
description?: string
};
2022-04-23 23:03:43 +00:00
const list: listItem[] = res;
2021-12-08 03:38:31 +00:00
function mapChild(obj: listItem | string, level: number) {
if (typeof obj === 'string') {
if (obj === '')
return <></>
2021-12-08 04:30:34 +00:00
return <span className={style.listItem}>{obj}</span>
2021-12-08 03:38:31 +00:00
}
if (obj.title === '')
return <></>
if (obj.url)
2021-12-08 04:30:34 +00:00
return <span className={style.listItem}><a href={obj.url}>{obj.title}</a></span>
2021-12-08 03:38:31 +00:00
if (!obj.children)
2021-12-08 04:30:34 +00:00
return <span className={style.listItem}>{obj.title}</span>
2021-12-08 03:38:31 +00:00
let title: ReactElement;
if (level >= 0 && level <= 4)
title = React.createElement(`h${level + 2}`, {}, obj.title);
else
title = React.createElement('strong', {}, obj.title);
return (
<>
{title}
{obj.description ? <p>{obj.description}</p> : <></>}
2021-12-08 04:30:34 +00:00
<div>
2021-12-08 03:38:31 +00:00
{obj.children.map(l => mapChild(l, level + 1))}
2021-12-08 04:30:34 +00:00
</div>
2021-12-08 03:38:31 +00:00
</>
);
}
function Resources() {
return (
<Layout name='Resources' title='Some Useful Resources'>
<section className='block'>
2021-12-08 04:30:34 +00:00
{list.map(l => mapChild(l, 0))}
2021-12-08 03:38:31 +00:00
</section>
</Layout>);
}
export default Resources;