diff --git a/pages/playlists.tsx b/pages/playlists.tsx index 8d1141c..ae58cc2 100644 --- a/pages/playlists.tsx +++ b/pages/playlists.tsx @@ -8,7 +8,26 @@ type listItem = { title: string; }; -const list: listItem[] = pl; +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) @@ -38,7 +57,13 @@ function Playlists() {

Music

- {list.map(l => mapChild(l, 0))} + { + pl.map((item: Record) => { + const lItem = toListItem(item) + if (lItem) + return mapChild(lItem, 0) + }) + }
); diff --git a/pages/posts/[page].tsx b/pages/posts/[page].tsx index aff903a..888e8db 100644 --- a/pages/posts/[page].tsx +++ b/pages/posts/[page].tsx @@ -9,7 +9,10 @@ function Post({post} : any) { // eh return (
- {post.cover ? {`${post.title} : ''} +
+ {post.cover ? {`${post.title} : ''} + +
{post.content}
diff --git a/pages/recommended.tsx b/pages/recommended.tsx index 6b624f2..c602460 100644 --- a/pages/recommended.tsx +++ b/pages/recommended.tsx @@ -1,51 +1,6 @@ -import React, { ReactElement } from 'react'; import Layout from '../components/layout'; -import style from '../styles/lists.module.css'; import rec from '../public/recommended.yaml'; - -type listItem = { - children?: listItem[] | string[]; - url?: string; - title: string; - description?: string -}; - -const list: listItem[] = rec // todo: validate this - -function mapChild(obj: listItem | string, level: number) { -console.log(list) -if (typeof obj === 'string') { - if (obj === '') - return <> - return {obj} - } - - if (obj.title === '') - return <> - - if (obj.url) - return {obj.title} - - if (!obj.children) - return {obj.title} - - 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 ?

{obj.description}

: <>} -
- {obj.children.map(l => mapChild(l, level + 1))} -
- - ); -} +import {toListItem, mapChild} from '../util/resrec'; function Recommended() { return ( @@ -53,7 +8,13 @@ function Recommended() {

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.

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.

- {list.map(l => mapChild(l, 0))} + { + rec.map((item: Record) => { + const lItem = toListItem(item) + if (lItem) + return mapChild(lItem, 0) + }) + }
); diff --git a/pages/resources.tsx b/pages/resources.tsx index ee01824..3b46a4f 100644 --- a/pages/resources.tsx +++ b/pages/resources.tsx @@ -1,56 +1,18 @@ -import React, { ReactElement } from 'react'; import Layout from '../components/layout'; -import style from '../styles/lists.module.css'; import res from '../public/resources.yaml'; - -type listItem = { - children?: listItem[] | string[]; - url?: string; - title: string; - description?: string -}; - -const list: listItem[] = res; - -function mapChild(obj: listItem | string, level: number) { - if (typeof obj === 'string') { - if (obj === '') - return <> - return {obj} - } - - if (obj.title === '') - return <> - - if (obj.url) - return {obj.title} - - if (!obj.children) - return {obj.title} - - 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 ?

{obj.description}

: <>} -
- {obj.children.map(l => mapChild(l, level + 1))} -
- - ); -} +import {toListItem, mapChild} from '../util/resrec'; function Resources() { return (
- {list.map(l => mapChild(l, 0))} + { + res.map((item: Record) => { + const lItem = toListItem(item) + if (lItem) + return mapChild(lItem, 0) + }) + }
); } diff --git a/shims.d.ts b/shims.d.ts new file mode 100644 index 0000000..12a48ce --- /dev/null +++ b/shims.d.ts @@ -0,0 +1,4 @@ +declare module '*.yaml' { + const record: Record; + export default record; +} \ No newline at end of file diff --git a/styles/global.css b/styles/global.css index 450d942..2cf2ed3 100644 --- a/styles/global.css +++ b/styles/global.css @@ -140,6 +140,11 @@ section { margin: 0.5rem; } +img { + border: 1px solid #FFFFFF; + border-radius: 1rem; +} + .lambda-logo { width: 256px; height: 256px; @@ -150,9 +155,9 @@ section { } .block { - margin: 0 2rem; + max-width: 1018px; + margin: 0 auto; padding: 2rem; - /* box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); */ border: 1px solid #ffffff; border-bottom: none; } diff --git a/tsconfig.json b/tsconfig.json index bf71934..7d8da63 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,6 +15,6 @@ "jsx": "preserve", "importHelpers": true }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], + "include": ["next-env.d.ts", "shims.d.ts", "**/*.ts", "**/*.tsx"], "exclude": ["node_modules"] } diff --git a/util/resrec.tsx b/util/resrec.tsx new file mode 100644 index 0000000..7e66832 --- /dev/null +++ b/util/resrec.tsx @@ -0,0 +1,80 @@ +import style from '../styles/lists.module.css'; +import React, { ReactElement } from 'react'; + +interface listItem { + children?: listItem[] | string[]; + url?: string; + title: string; + description?: string; +}; + +export function toListItem(record: Record): listItem | null { + if (!record.title) + return null; + + let children: listItem[] | string[] = []; + if (Array.isArray(record.children) && record.children.length) { + + let lchildren: listItem[] = []; + let schildren: string[] = []; + for (const child of record.children) { + if (typeof child === 'string') { + schildren.push(child); + continue; + } + const lChild = toListItem(child); + if (lChild) + lchildren.push(lChild); + } + + if (!lchildren.length) { + children = schildren; + } + else { + children = [...lchildren, ... schildren.map((s: string): listItem => { + return { title: s }; + }) ]; + } + } + + return { + title: record.title, + url: record.url, + children: children.length? children : undefined, + description: record.description, + }; +} + +export function mapChild(obj: listItem | string, level: number) { + if (typeof obj === 'string') { + if (obj === '') + return <> + return {obj} + } + + if (obj.title === '') + return <> + + if (obj.url) + return {obj.title} + + if (!obj.children) + return {obj.title} + + 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 ?

{obj.description}

: <>} +
+ {obj.children.map(l => mapChild(l, level + 1))} +
+ + ); +} \ No newline at end of file