import React, { ReactElement } from 'react'; import Layout from '../components/layout'; import pl from '../public/playlists.yaml'; type listItem = { children?: listItem[]; url?: string; title: string; }; function toListItem(record: Record): 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[] = []; function mapChild(obj: listItem, level: number) { if (obj.url) return
  • {obj.title}
  • 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} ); } function Playlists() { return (

    Music

    { pl.map((item: Record) => { const lItem = toListItem(item) if (lItem) return mapChild(lItem, 0) }) }
    ); } export default Playlists;