diff --git a/fresh.gen.ts b/fresh.gen.ts index b2df20c..281d1c6 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -9,7 +9,8 @@ import * as $blog_index from './routes/blog/index.tsx' import * as $index from './routes/index.tsx' import * as $machines_id_ from './routes/machines/[id].tsx' import * as $machines_index from './routes/machines/index.tsx' -import * as $membres_id_ from './routes/membres/[id].tsx' +import * as $membres_id_index from './routes/membres/[id]/index.tsx' +import * as $membres_id_portfolio_path_ from './routes/membres/[id]/portfolio/[...path].tsx' import * as $membres_index from './routes/membres/index.tsx' import * as $profil_admin from './routes/profil/admin.tsx' import * as $profil_index from './routes/profil/index.tsx' @@ -30,7 +31,9 @@ const manifest = { './routes/index.tsx': $index, './routes/machines/[id].tsx': $machines_id_, './routes/machines/index.tsx': $machines_index, - './routes/membres/[id].tsx': $membres_id_, + './routes/membres/[id]/index.tsx': $membres_id_index, + './routes/membres/[id]/portfolio/[...path].tsx': + $membres_id_portfolio_path_, './routes/membres/index.tsx': $membres_index, './routes/profil/admin.tsx': $profil_admin, './routes/profil/index.tsx': $profil_index, diff --git a/routes/membres/[id].tsx b/routes/membres/[id].tsx deleted file mode 100644 index 293bac5..0000000 --- a/routes/membres/[id].tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { PageProps } from '$fresh/server.ts' -import { MemberCard, memberMock } from '../../components/MemberCard.tsx' - -export default function Member({ params }: PageProps) { - const Member = memberMock.at(Number(params.id)) - - return ( - Member - ? MemberCard(Member) - :

Membre inconnu, peut ĂȘtre serai vous le prochain

- ) -} diff --git a/routes/membres/[id]/index.tsx b/routes/membres/[id]/index.tsx new file mode 100644 index 0000000..1286b76 --- /dev/null +++ b/routes/membres/[id]/index.tsx @@ -0,0 +1,66 @@ +import { PageProps } from '$fresh/server.ts' +import { MemberCard, memberMock } from '../../../components/MemberCard.tsx' +import { CSS, render as renderMd } from 'gfm' + +function Markdown({ children }: { children: string }) { + return ( + <> + +
+
+ + ) +} + +const db = [ + 'julien.oculi', +] + +async function getCarnet(user: string): Promise { + try { + const response = await fetch( + `https://git.cohabit.fr/${user}/.carnet/raw/branch/main/index.md`, + ) + return response.text() + } catch (error) { + return 'Carnet introuvable\n```js\nString(error)\n```' + } +} + +export default async function Member(_: Request, { params }: PageProps) { + const id = Number(params.id) + const Member = memberMock.at(id) + + if (!Member) { + return

Membre inconnu, peut ĂȘtre serai vous le prochain

+ } + + const carnet = await getCarnet(db.at(id)!) + + return ( +
+
+ {MemberCard(Member)} +
+ + Portfolio + +
+ {carnet} +
+ ) +} diff --git a/routes/membres/[id]/portfolio/[...path].tsx b/routes/membres/[id]/portfolio/[...path].tsx new file mode 100644 index 0000000..4e6a7d6 --- /dev/null +++ b/routes/membres/[id]/portfolio/[...path].tsx @@ -0,0 +1,50 @@ +import { Handlers, RouteConfig } from '$fresh/server.ts' + +import { contentType } from '$std/media_types/mod.ts' +import { parse } from '$std/path/mod.ts' + +const db = [ + 'julien.oculi', +] + +async function getPortfolio( + user: string, + pathname: string, +): Promise { + const url = new URL( + pathname, + `https://git.cohabit.fr/${user}/.portfolio/raw/branch/main/`, + ) + + const { ext } = parse(pathname) + + try { + const response = await fetch(url) + if (response.ok) { + return new Response(response.body, { + headers: { + 'Content-Type': contentType(ext) ?? 'text/plain; charset=utf-8', + }, + }) + } + throw new Error(response.statusText) + } catch (error) { + return new Response( + 'Portfolio introuvable\n```js\n' + String(error) + '\n```', + ) + } +} + +export const config: RouteConfig = { + skipAppWrapper: true, +} + +export const handler: Handlers = { + GET(req, _ctx) { + const url = new URL(req.url) + const id = Number(url.pathname.split('/')[2]) + const user = db[id] + const query = url.pathname.split('/').slice(4).join('/') + return getPortfolio(user, query === '' ? 'index.html' : query) + }, +}