www/pages/recommended.tsx

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-12-08 03:38:31 +00:00
import React, { ReactElement } from 'react';
import Layout from '../components/layout';
import style from '../styles/lists.module.css';
2022-04-23 23:03:43 +00:00
import rec from '../public/recommended.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[] = rec // todo: validate this
2021-12-08 03:38:31 +00:00
function mapChild(obj: listItem | string, level: number) {
2022-04-23 23:03:43 +00:00
console.log(list)
if (typeof obj === 'string') {
2021-12-08 03:38:31 +00:00
if (obj === '')
return <></>
return <span className={style.listItem}>{obj}</span>
}
if (obj.title === '')
return <></>
if (obj.url)
return <span className={style.listItem}><a href={obj.url}>{obj.title}</a></span>
if (!obj.children)
return <span className={style.listItem}>{obj.title}</span>
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> : <></>}
<div>
{obj.children.map(l => mapChild(l, level + 1))}
</div>
</>
);
}
function Recommended() {
return (
<Layout name='Recommended' title='My Recommendations'>
<section className='block'>
<p>This page is really for me to not forget/revisit the good things I have read, seen, heard, and/or experienced. This list may change, just as my opinions.</p>
2021-12-08 08:54:18 +00:00
<p>If the one you are looking for is not on this list, it is most likely I have not had the chance to read/listen to/watch it yet.</p>
2021-12-08 03:38:31 +00:00
{list.map(l => mapChild(l, 0))}
</section>
</Layout>
);
}
2022-04-20 20:12:27 +00:00
export default Recommended;