import useSWR from "swr";
import { HTTPError } from "../document";
import { WRITER_MODE } from "../env";
import { Route, Routes } from "react-router-dom";
import { HydrationData } from "../../../libs/types/hydration";
import { BlogPost, AuthorDateReadTime } from "./post";
import { BlogImage, BlogPostMetadata } from "../../../libs/types/blog.js";
import "./index.scss";
import { Button } from "../ui/atoms/button";
interface BlogIndexData {
posts: BlogPostMetadata[];
}
export function Blog(appProps: HydrationData) {
return (
} />
} />
);
}
export function BlogIndexImageFigure({
image,
slug,
width,
height,
}: {
image: BlogImage;
slug: string;
width?: number;
height?: number;
}) {
const src = `./${slug}/${image.file}`;
return (
);
}
function PostPreview({ fm }: { fm: BlogPostMetadata }) {
return (
{fm.description}
);
}
function BlogIndex(props: HydrationData) {
const dataURL = `./index.json`;
const { data } = useSWR(
dataURL,
async (url) => {
const response = await fetch(url);
if (!response.ok) {
if (response.status === 404) {
throw new HTTPError(response.status, url, "Page not found");
}
const text = await response.text();
throw new HTTPError(response.status, url, text);
}
return (await response.json()).hyData;
},
{
fallbackData: props.hyData,
revalidateOnFocus: WRITER_MODE,
revalidateOnMount: !props.hyData,
}
);
return (
<>
{data?.posts.map((fm) => {
return ;
})}
>
);
}