This commit is contained in:
Andrea 2024-10-29 19:32:47 +02:00
parent b299731fcc
commit c31770a9df
Signed by: nullndr
GPG Key ID: 8DA8996EF89F33BB
9 changed files with 29 additions and 49 deletions

View File

@ -1,6 +1,6 @@
export function LinkWrapper({ children }: React.PropsWithChildren) { export function LinkWrapper({ children }: React.PropsWithChildren) {
return ( return (
<div className="flex flex-col items-center"> <div className="">
<div className="mt-5 hover:text-[#e6c2bf] font-bold">{children}</div> <div className="mt-5 hover:text-[#e6c2bf] font-bold">{children}</div>
</div> </div>
); );

View File

@ -11,14 +11,12 @@ export function PostPreview({
}: SerializeFrom<Post>) { }: SerializeFrom<Post>) {
const formattedDate = useFormattedDate(published); const formattedDate = useFormattedDate(published);
return ( return (
<div className="w-full sm:w-4/5 md:w-3/4 lg:w-2/3 xl:w-1/3"> <div className="">
<Link to={filename}> <Link to={filename}>
<div className="space-y-4 py-3 text-center font-bold border-gray-600 border-2 rounded-lg"> <div className="py-3 font-bold">
<div className="text-[#ffff00]">{title}</div> <div className="text-[#ffff00]">{title}</div>
<div>{description}</div> <div>{description}</div>
<div> <time className="text-sm">{formattedDate}</time>
<time>{formattedDate}</time>
</div>
</div> </div>
</Link> </Link>
</div> </div>

View File

@ -1,9 +1,7 @@
export function Title({ children }: React.PropsWithChildren) { export function Title({ children }: React.PropsWithChildren) {
return ( return (
<div className="mt-5 flex flex-col items-center"> <div className="mt-5">
<div className="text-[#ffff00] font-bold"> <h1 className="text-[#ffff00] text-2xl font-bold">{children}</h1>
<span>{children}</span>
</div>
</div> </div>
); );
} }

View File

@ -2,5 +2,5 @@ export function useFormattedDate(_date: string) {
const date = new Date(_date); const date = new Date(_date);
const month = date.getUTCMonth().toString().padStart(2, "0"); const month = date.getUTCMonth().toString().padStart(2, "0");
const monthDate = date.getUTCDate().toString().padStart(2, "0"); const monthDate = date.getUTCDate().toString().padStart(2, "0");
return `${date.getUTCFullYear()}/${month}/${monthDate}`; return `${date.getUTCFullYear()}-${month}-${monthDate}`;
} }

View File

@ -1,14 +0,0 @@
import { useMatches } from "@remix-run/react";
export function useMatch() {
const matches = useMatches();
const { handle, ...rest } = matches[matches.length - 1];
if (handle == null) {
throw new Error(`handle is missing for ${rest.pathname}`);
}
return { handle, ...rest } as unknown as typeof rest & {
handle: { to: string; text: string };
};
}

View File

@ -57,12 +57,18 @@ export default function Post() {
return ( return (
<> <>
<Title>{title}</Title> <header>
<div className="text-center"> <Title>{title}</Title>
<time>{formattedDate}</time> <span>
</div> <time>{formattedDate}</time>·
<div className="flex flex-col items-center"> <Link to="/blog" className="hover:text-[#ffff00]">
<div className="space-y-5 sm:w-full sm:px-5 lg:w-5/6 xl:w-2/3"> Go Back
</Link>
</span>
</header>
<main>
<div className="space-y-5">
<div className=" prose-blockquote:bg-[#282c34] prose-blockquote:border-l-4 prose-blockquote:border-[#21252b] prose-blockquote:px-2 prose-blockquote:py-2 prose-blockquote:rounded-r"> <div className=" prose-blockquote:bg-[#282c34] prose-blockquote:border-l-4 prose-blockquote:border-[#21252b] prose-blockquote:px-2 prose-blockquote:py-2 prose-blockquote:rounded-r">
<div className="prose-h2:text-[#ffff00] prose-h2:font-bold prose-h2:text-2xl"> <div className="prose-h2:text-[#ffff00] prose-h2:font-bold prose-h2:text-2xl">
<div className="prose-code:px-1 prose-code:py-0.5 prose-code:bg-[#282c34] prose-code:text-[#d6d6d6] prose-code:rounded prose-code:font-mono"> <div className="prose-code:px-1 prose-code:py-0.5 prose-code:bg-[#282c34] prose-code:text-[#d6d6d6] prose-code:rounded prose-code:font-mono">
@ -85,7 +91,7 @@ export default function Post() {
</Link> </Link>
</div> </div>
</div> </div>
</div> </main>
</> </>
); );
} }

View File

@ -1,13 +1,9 @@
import { useLoaderData } from "@remix-run/react"; import { Link, useLoaderData } from "@remix-run/react";
import { LinkWrapper } from "~/components/LinkWrapper";
import { PostPreview } from "~/components/PostPreview"; import { PostPreview } from "~/components/PostPreview";
import { Title } from "~/components/Title"; import { Title } from "~/components/Title";
import { findPosts } from "~/utils/posts.server"; import { findPosts } from "~/utils/posts.server";
export const handle = {
to: "/",
text: "Home",
};
export const loader = () => { export const loader = () => {
return findPosts(); return findPosts();
}; };
@ -17,8 +13,11 @@ export default function Blog() {
return ( return (
<> <>
<LinkWrapper>
<Link to="/">Home</Link>
</LinkWrapper>
<Title>Here I blog about whatever get my attention</Title> <Title>Here I blog about whatever get my attention</Title>
<div className="mt-5 flex flex-col items-center space-y-5"> <div className="mt-5">
{posts.map((post) => ( {posts.map((post) => (
<PostPreview {...post} key={post.title} /> <PostPreview {...post} key={post.title} />
))} ))}

View File

@ -1,8 +1,5 @@
import type { MetaFunction } from "@remix-run/node"; import type { MetaFunction } from "@remix-run/node";
import { Link } from "@remix-run/react";
import { Outlet } from "react-router-dom"; import { Outlet } from "react-router-dom";
import { LinkWrapper } from "~/components/LinkWrapper";
import { useMatch } from "~/hooks/useMatch";
export const meta: MetaFunction = () => { export const meta: MetaFunction = () => {
return [ return [
@ -21,13 +18,8 @@ export const meta: MetaFunction = () => {
}; };
export default function BlogLayout() { export default function BlogLayout() {
const { handle } = useMatch();
return ( return (
<div className="space-y-6 px-2"> <div className="space-y-6 max-w-3xl mx-auto">
<LinkWrapper>
<Link to={handle.to}>{handle.text}</Link>
</LinkWrapper>
<Outlet /> <Outlet />
</div> </div>
); );

View File

@ -8,7 +8,8 @@
"start": "remix-serve ./build/server/index.js", "start": "remix-serve ./build/server/index.js",
"typecheck": "tsc", "typecheck": "tsc",
"lint": "biome lint", "lint": "biome lint",
"format": "biome format --write" "format": "biome format --write",
"routes": "remix routes"
}, },
"dependencies": { "dependencies": {
"@code-hike/mdx": "0.9.0", "@code-hike/mdx": "0.9.0",