feat: ✨ add "carnet" and "portfolio" support
This commit is contained in:
parent
812da2a857
commit
2b66f76966
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
: <h3>Membre inconnu, peut être serai vous le prochain</h3>
|
||||
)
|
||||
}
|
66
routes/membres/[id]/index.tsx
Normal file
66
routes/membres/[id]/index.tsx
Normal file
|
@ -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 (
|
||||
<>
|
||||
<style dangerouslySetInnerHTML={{ __html: CSS }}></style>
|
||||
<div
|
||||
class='markdown-body'
|
||||
dangerouslySetInnerHTML={{ __html: renderMd(children) }}
|
||||
>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const db = [
|
||||
'julien.oculi',
|
||||
]
|
||||
|
||||
async function getCarnet(user: string): Promise<string> {
|
||||
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 <h3>Membre inconnu, peut être serai vous le prochain</h3>
|
||||
}
|
||||
|
||||
const carnet = await getCarnet(db.at(id)!)
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'auto 1fr',
|
||||
gap: 'var(--_gap)',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
{MemberCard(Member)}
|
||||
<br/>
|
||||
<a
|
||||
href={`/membres/${id}/portfolio/index.html`}
|
||||
class='cta'
|
||||
target='_blank'
|
||||
>
|
||||
Portfolio
|
||||
</a>
|
||||
</div>
|
||||
<Markdown>{carnet}</Markdown>
|
||||
</div>
|
||||
)
|
||||
}
|
50
routes/membres/[id]/portfolio/[...path].tsx
Normal file
50
routes/membres/[id]/portfolio/[...path].tsx
Normal file
|
@ -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<Response> {
|
||||
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)
|
||||
},
|
||||
}
|
Loading…
Reference in a new issue