Stock/routes/pages/[name].tsx

39 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

2023-10-26 22:09:44 +09:00
import { PageProps, Handlers } from "$fresh/server.ts";
2023-07-23 00:32:54 +09:00
import { Head } from "$fresh/runtime.ts";
2023-10-26 22:09:44 +09:00
import { get_pages_meta, PageDescription } from "../../pages.ts";
2023-07-23 00:32:54 +09:00
import StockList from "../../islands/StockList.tsx";
2023-10-26 22:09:44 +09:00
export const handler: Handlers = {
async GET(_req, ctx) {
const [pages, _] = await get_pages_meta();
const name = ctx.params.name;
const page = pages.filter(x=> x.name === name);
if (page.length === 0) {
return await ctx.renderNotFound();
}
return await ctx.render(page[0]);
},
};
2023-07-23 00:32:54 +09:00
2023-10-26 22:09:44 +09:00
export default function Pages(props: PageProps<PageDescription>) {
2023-07-23 00:32:54 +09:00
return <>
<Head>
<title>Stock: {props.params.name}</title>
</Head>
2023-10-26 22:09:44 +09:00
<div class="px-4 py-8 mx-auto bg-[#86efac] min-h-screen">
2023-07-23 00:32:54 +09:00
<div class="max-w-screen-md mx-auto flex flex-col items-center justify-center">
<img
class="my-6"
src="/stockgraph.svg"
width="128"
height="128"
alt="stock graph"
/>
2023-07-24 09:10:32 +09:00
<h1 class="text-4xl">{props.params.name}</h1>
2023-10-26 22:09:44 +09:00
<p>{props.data.description}</p>
2023-07-23 00:32:54 +09:00
<StockList pageName={props.params.name}></StockList>
</div>
</div>
</>
}