diff --git a/pages/contents.tsx b/pages/contents/[node].tsx similarity index 76% rename from pages/contents.tsx rename to pages/contents/[node].tsx index 14fb7c7..cbf4fc3 100644 --- a/pages/contents.tsx +++ b/pages/contents/[node].tsx @@ -1,49 +1,28 @@ import type { GetServerSideProps } from 'next'; import Link from 'next/link'; -import Layout from '../components/Layout'; -import { getContent } from '../lib/content'; -import { CONTENT_TREE, ContentNode, findNode } from '../lib/content-tree'; -import { typeSlug } from '../lib/slug'; +import Layout from '../../components/Layout'; +import { getContent } from '../../lib/content'; +import { findNode } from '../../lib/content-tree'; +import { typeSlug } from '../../lib/slug'; type Content = Awaited>; interface Props { node: { id: string; title: string; blurb: string; areas: string[]; taxonomy: string[] }; content: Content } -export const getServerSideProps: GetServerSideProps = async ({ query }) => { - const want = String(query.node ?? CONTENT_TREE.children[0].id); - const node = findNode(want); +export const getServerSideProps: GetServerSideProps = async ({ params }) => { + const node = findNode(String(params?.node)); if (!node || node.id === 'root') return { notFound: true }; const { children: _c, ...plain } = node; return { props: { node: plain, content: await getContent(node) } }; }; -function Tree({ node, selected }: { node: ContentNode; selected: string }) { - return ( -
    - {node.children.map((c) => ( -
  • - {c.title} - {c.children.length > 0 && } -
  • - ))} -
- ); -} - export default function Contents({ node, content }: Props) { const area = content.areas[0]; return ( -

Contents

-

The tree of content for the write-up. Each entry draws its numbers from the survey data.

-
- +

← Contents

+

{node.title}

+
-

{node.title}

{node.blurb}

{content.total.toLocaleString()}
papers in this area{area ? ` (${area.label.split(',')[0]})` : ''}
diff --git a/pages/contents/index.tsx b/pages/contents/index.tsx new file mode 100644 index 0000000..be72081 --- /dev/null +++ b/pages/contents/index.tsx @@ -0,0 +1,31 @@ +import Link from 'next/link'; +import Layout from '../../components/Layout'; +import { CONTENT_TREE, ContentNode } from '../../lib/content-tree'; + +function Toc({ nodes, prefix }: { nodes: ContentNode[]; prefix: string }) { + return ( +
    + {nodes.map((n, i) => { + const num = `${prefix}${i + 1}`; + return ( +
  1. + {num} + {n.title} +
    {n.blurb}
    + {n.children.length > 0 && } +
  2. + ); + })} +
+ ); +} + +export default function Contents() { + return ( + +

Contents

+

{CONTENT_TREE.blurb} Each entry opens its own page.

+
+
+ ); +}