chore: final layout

This commit is contained in:
Andrea 2023-03-07 12:10:29 +01:00
parent 0fc8c40fed
commit a844ec9845
No known key found for this signature in database
GPG Key ID: 4594610B9C8F91C5
11 changed files with 61 additions and 33 deletions

View File

@ -1,11 +0,0 @@
import { Link as RemixLink } from "@remix-run/react";
type LinkProps = React.PropsWithChildren<{ to: string }>;
export function Link({ to, children }: LinkProps) {
return (
<RemixLink to={to} className="mt-5 hover:text-[#e6c2bf] text-xl font-bold">
{children}
</RemixLink>
);
}

View File

@ -13,7 +13,7 @@ export function Post({ title, description, id, createdAt }: PostProps) {
<div className="p-5 border-gray-600 border-2 rounded-lg"> <div className="p-5 border-gray-600 border-2 rounded-lg">
<Link to={id}> <Link to={id}>
<div className="text-center font-bold"> <div className="text-center font-bold">
<span className="text-[#ffff00] hover:text-[#e6c2bf] text-2xl"> <span className="text-[#ffff00] hover:text-[#e6c2bf] md:text-2xl">
{title} {title}
</span> </span>
<span className="ml-2">{`(${new Date( <span className="ml-2">{`(${new Date(
@ -21,7 +21,7 @@ export function Post({ title, description, id, createdAt }: PostProps) {
).toLocaleDateString()})`}</span> ).toLocaleDateString()})`}</span>
</div> </div>
{description && ( {description && (
<div className="mt-5 italic text-xl max-w-3xl text-center"> <div className="mt-5 italic md:text-xl max-w-3xl text-center">
{description} {description}
</div> </div>
)} )}

7
app/components/Title.tsx Normal file
View File

@ -0,0 +1,7 @@
export function Title({ children }: React.PropsWithChildren) {
return (
<div className="mt-5 mx-5 lg:mx-0 text-xl sm:text-3xl text-[#ffff00] font-bold">
<span>{children}</span>
</div>
);
}

6
app/hooks/useMatch.ts Normal file
View File

@ -0,0 +1,6 @@
import { useMatches } from "@remix-run/react";
export function useMatch() {
const matches = useMatches();
return matches[matches.length - 1];
}

View File

@ -2,10 +2,15 @@ import type { LoaderArgs } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react"; import { useLoaderData } from "@remix-run/react";
import { getMDXComponent } from "mdx-bundler/client"; import { getMDXComponent } from "mdx-bundler/client";
import React from "react"; import React from "react";
import { Link } from "~/components/Link"; import { Title } from "~/components/Title";
import { findPost } from "~/models/posts.server"; import { findPost } from "~/models/posts.server";
import { getMdxFile } from "~/utils/posts.server"; import { getMdxFile } from "~/utils/posts.server";
export const handle = {
to: "/blog",
text: "Go Back",
};
export const loader = async ({ params }: LoaderArgs) => { export const loader = async ({ params }: LoaderArgs) => {
const id = params.id; const id = params.id;
if (id == null) { if (id == null) {
@ -17,20 +22,20 @@ export const loader = async ({ params }: LoaderArgs) => {
throw new Response(null, { status: 404 }); throw new Response(null, { status: 404 });
} }
const { code } = await getMdxFile(post.path); const { code } = await getMdxFile(post.fileName);
return { post, code }; return { post, code };
}; };
export default function () { export default function () {
const { post, code } = useLoaderData<typeof loader>(); const { post, code } = useLoaderData<typeof loader>();
const MdxComponent = React.useMemo(() => getMDXComponent(code), [code]); const MdxComponent = React.useMemo(() => getMDXComponent(code), [code]);
return ( return (
<div className="h-fit mb-5 w-full flex flex-col items-center"> <>
<Link to="/blog">Go Back</Link> <Title>{post.title}</Title>
<div className="mt-5 text-[#ffff00] text-3xl font-bold">{post.title}</div> <div className="m-3 mt-10 xl:w-1/2 prose dark:prose-invert prose-a:no-underline prose-a:font-bold">
<div className="m-3 xl:w-1/2 prose dark:prose-invert prose-a:no-underline prose-a:font-bold">
<MdxComponent /> <MdxComponent />
</div> </div>
</div> </>
); );
} }

View File

@ -1,8 +1,13 @@
import { useLoaderData } from "@remix-run/react"; import { useLoaderData } from "@remix-run/react";
import { Link } from "~/components/Link"; import { Title } from "~/components/Title";
import { findPosts } from "~/models/posts.server"; import { findPosts } from "~/models/posts.server";
import { EmptyState } from "./EmptyState"; import { EmptyState } from "../components/EmptyState";
import { Post } from "./Post"; import { Post } from "../components/Post";
export const handle = {
to: "/",
text: "Home",
};
export const loader = async () => { export const loader = async () => {
return findPosts(); return findPosts();
@ -11,11 +16,8 @@ export const loader = async () => {
export default function () { export default function () {
const posts = useLoaderData<typeof loader>(); const posts = useLoaderData<typeof loader>();
return ( return (
<div className="h-fit w-full flex flex-col items-center"> <>
<Link to="/">Home</Link> <Title>Here I blog about whatever get my attention</Title>
<div className="mt-5 mx-5 sm:mx-0 md:text-3xl text-[#ffff00] font-bold">
<span>Here I blog about whatever get my attention</span>
</div>
{posts.length > 0 ? ( {posts.length > 0 ? (
<div className="mt-10 w-full flex flex-col items-center space-y-5"> <div className="mt-10 w-full flex flex-col items-center space-y-5">
{posts.map((post, i) => ( {posts.map((post, i) => (
@ -25,6 +27,6 @@ export default function () {
) : ( ) : (
<EmptyState /> <EmptyState />
)} )}
</div> </>
); );
} }

19
app/routes/blog.tsx Normal file
View File

@ -0,0 +1,19 @@
import { Link, Outlet } from "@remix-run/react";
import { useMatch } from "~/hooks/useMatch";
export default function () {
const { handle } = useMatch();
return (
<div className="h-fit w-full flex flex-col items-center">
{handle && (
<Link
className="mt-5 hover:text-[#e6c2bf] text-xl font-bold"
to={handle.to}
>
{handle.text}
</Link>
)}
<Outlet />
</div>
);
}

View File

@ -3,8 +3,8 @@ import { readFile } from "fs/promises";
import { bundleMDX } from "mdx-bundler"; import { bundleMDX } from "mdx-bundler";
import codeHikeTheme from "shiki/themes/one-dark-pro.json"; import codeHikeTheme from "shiki/themes/one-dark-pro.json";
export const getMdxFile = async (path: string) => { export const getMdxFile = async (fileName: string) => {
const source = await readFile(path); const source = await readFile(`posts/${fileName}`);
return bundleMDX({ return bundleMDX({
source: source.toString(), source: source.toString(),
mdxOptions() { mdxOptions() {

View File

@ -11,7 +11,7 @@ model Post {
id String @id @default(cuid()) id String @id @default(cuid())
title String title String
description String? description String?
path String fileName String
isPublic Boolean @default(false) isPublic Boolean @default(false)
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt

View File

@ -3,7 +3,7 @@
"remix.env.d.ts", "remix.env.d.ts",
"**/*.ts", "**/*.ts",
"**/*.tsx", "**/*.tsx",
"app/routes/blog_.$id.tsx" "app/routes/blog.$id.tsx"
], ],
"compilerOptions": { "compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2019"], "lib": ["DOM", "DOM.Iterable", "ES2019"],