2021-12-08 03:38:31 +00:00
|
|
|
import React, { ReactElement } from 'react';
|
|
|
|
import Layout from '../components/layout';
|
2022-04-23 23:03:43 +00:00
|
|
|
import pl from '../public/playlists.yaml';
|
2021-12-08 03:38:31 +00:00
|
|
|
|
|
|
|
type listItem = {
|
|
|
|
children?: listItem[];
|
|
|
|
url?: string;
|
|
|
|
title: string;
|
|
|
|
};
|
|
|
|
|
2022-04-24 00:35:53 +00:00
|
|
|
function toListItem(record: Record<string, any>): listItem | null {
|
|
|
|
if (!record.title)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
let children: listItem[]= [];
|
|
|
|
if (record.children)
|
|
|
|
for (const child of record.children) {
|
|
|
|
const lChild = toListItem(child);
|
|
|
|
if (lChild)
|
|
|
|
children.push(lChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
title: record.title,
|
|
|
|
url: record.url,
|
|
|
|
children: children.length? children : undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const list: listItem[] = [];
|
2021-12-08 03:38:31 +00:00
|
|
|
|
|
|
|
function mapChild(obj: listItem, level: number) {
|
|
|
|
if (obj.url)
|
|
|
|
return <li key=''><a href={obj.url}>{obj.title}</a></li>
|
|
|
|
|
|
|
|
if (!obj.children)
|
|
|
|
return <></> // ignore playlists without links
|
|
|
|
|
|
|
|
let title: ReactElement;
|
|
|
|
if (level >= 0 && level <= 3)
|
|
|
|
title = React.createElement(`h${level+3}`, {}, obj.title);
|
|
|
|
else
|
|
|
|
title = React.createElement('strong', {}, obj.title);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{title}
|
|
|
|
<ul>
|
|
|
|
{obj.children.map(l => mapChild(l, level + 1))}
|
|
|
|
</ul>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function Playlists() {
|
|
|
|
return (
|
|
|
|
<Layout name='Playlists'>
|
|
|
|
<section className='block'>
|
|
|
|
<h2>Music</h2>
|
2022-04-24 00:35:53 +00:00
|
|
|
{
|
|
|
|
pl.map((item: Record<string, any>) => {
|
|
|
|
const lItem = toListItem(item)
|
|
|
|
if (lItem)
|
|
|
|
return mapChild(lItem, 0)
|
|
|
|
})
|
|
|
|
}
|
2021-12-08 03:38:31 +00:00
|
|
|
</section>
|
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-25 00:58:01 +00:00
|
|
|
export default Playlists;
|