motto/src/app/[...file]/page.tsx

77 lines
2 KiB
TypeScript
Raw Normal View History

2024-09-16 19:44:19 +00:00
import type { Metadata, ResolvingMetadata } from 'next';
import Image from 'next/image';
import DownloadTTY from './download_tty';
2024-09-16 19:44:19 +00:00
import Content from './content';
2024-09-16 20:02:13 +00:00
import * as style from './page.css';
import download_image_dark from './download_dark.svg';
import download_image_light from './download_light.svg';
2024-09-16 19:44:19 +00:00
type SearchParams = { [key: string]: string | string[] | undefined };
type Props = {
params: { file: string },
searchParams: SearchParams,
};
2024-09-16 19:57:33 +00:00
function get_path(file: string[]) {
return file.join("/");
}
2024-09-16 19:44:19 +00:00
function get_root(search_params: SearchParams) {
return search_params['root'] ?? 'raw.monodon.me';
}
export async function generateMetadata(
{ params, searchParams }: Props,
parent: ResolvingMetadata,
): Promise<Metadata> {
return {
2024-09-16 19:57:33 +00:00
title: `${get_path(params.file)} | ${get_root(searchParams)}`,
2024-09-16 19:44:19 +00:00
};
}
export default async function Page({
params, searchParams
}: Props) {
2024-09-16 20:02:13 +00:00
const path = get_path(params.file);
const root = `https://${get_root(searchParams)}/`;
const full = `${root}${path}`;
const download_ttys = [
`curl -O ${root}${path}`,
`wget ${root}${path}`,
];
2024-09-16 19:44:19 +00:00
return (
2024-09-16 20:02:13 +00:00
<div className={style.root}>
<div className={style.center}>
<div className={style.title_group}>
<div className={style.title_text_group}>
<p className={style.supertitle}>{root}</p>
<p className={style.title}>{path}</p>
2024-09-16 19:44:19 +00:00
</div>
2024-09-16 20:02:13 +00:00
<button className={style.download_button}>
<a className={style.download_link} href={full} download>
<Image
className={style.download_button_image_dark}
src={download_image_dark}
alt="Download Button"
/>
<Image
className={style.download_button_image_light}
src={download_image_light}
alt="Download Button"
/>
</a>
2024-09-16 19:44:19 +00:00
</button>
</div>
<div className={style.download_tty_group}>
{download_ttys.map((text, index) => <DownloadTTY key={index} text={text} />)}
</div>
2024-09-16 20:02:13 +00:00
<Content src={`${root}${path}`} />
2024-09-16 19:44:19 +00:00
</div>
</div>
);
}