69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
import Link from "next/link";
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
import { PageHeader } from "@/components/page-header";
|
|
|
|
function formatTitle(filename: string) {
|
|
return filename
|
|
.replace(/\.RTF$/i, "")
|
|
.replace(/-/g, " ")
|
|
.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
}
|
|
|
|
function formatSize(bytes: number) {
|
|
if (bytes < 1024) return `${bytes} B`;
|
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
}
|
|
|
|
export default function Home() {
|
|
const rtfDir = path.join(process.cwd(), "public/rtfs");
|
|
const files = fs.readdirSync(rtfDir).filter((f) => /\.rtf$/i.test(f));
|
|
|
|
const fileList = files.map((f) => {
|
|
const stat = fs.statSync(path.join(rtfDir, f));
|
|
return {
|
|
filename: f,
|
|
slug: f.replace(/\.RTF$/i, ""),
|
|
title: formatTitle(f),
|
|
size: stat.size,
|
|
};
|
|
});
|
|
|
|
fileList.sort((a, b) => a.title.localeCompare(b.title));
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background">
|
|
<PageHeader>
|
|
<h1 className="text-2xl font-bold text-foreground">
|
|
RTF Document Viewer
|
|
</h1>
|
|
<p className="mt-1 text-muted-foreground">
|
|
{files.length} documents available
|
|
</p>
|
|
</PageHeader>
|
|
<main className="max-w-3xl mx-auto px-6 py-8">
|
|
<Card className="py-0">
|
|
<CardContent className="p-0 divide-y divide-border">
|
|
{fileList.map((file) => (
|
|
<Link
|
|
key={file.slug}
|
|
href={`/view/${file.slug}`}
|
|
className="flex items-center justify-between px-5 py-4 hover:bg-muted transition-colors first:rounded-t-xl last:rounded-b-xl"
|
|
>
|
|
<span className="font-medium text-foreground">
|
|
{file.title}
|
|
</span>
|
|
<span className="text-sm text-muted-foreground shrink-0 ml-4">
|
|
{formatSize(file.size)}
|
|
</span>
|
|
</Link>
|
|
))}
|
|
</CardContent>
|
|
</Card>
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|