refactor: code refactor

This commit is contained in:
Andrea
2023-05-17 14:31:02 +02:00
parent 0df503c3f5
commit 8222a4dfb2
16 changed files with 1738 additions and 1282 deletions

View File

@@ -0,0 +1,11 @@
export function BlogWrapper({ children }: React.PropsWithChildren) {
return (
<div className="mx-3 mt-5">
<div className="w-full">
<div className="flex flex-col items-center">
<div className="w-5/6 xl:w-1/2 2xl:w-1/3">{children}</div>
</div>
</div>
</div>
);
}

9
app/components/Body.tsx Normal file
View File

@@ -0,0 +1,9 @@
import React from "react";
export function Body({ children }: React.PropsWithChildren) {
return (
<body className="bg-[#202020] text-[#d6d6d6] font-['monospace']">
{children}
</body>
);
}

View File

@@ -0,0 +1,11 @@
import type React from "react";
export function LinkWrapper({ children }: React.PropsWithChildren) {
return (
<div className="flex flex-col items-center">
<div className="mt-5 mx-3 hover:text-[#e6c2bf] font-bold text-2xl">
{children}
</div>
</div>
);
}

View File

@@ -0,0 +1,9 @@
export function Notbyai() {
return (
<div className="fixed m-3 bottom-0 left-0">
<a href="https://notbyai.fyi/" target="_blank">
<img src="https://user-images.githubusercontent.com/62137266/225653923-a69103f5-b318-4e52-9ea1-95b61d388366.svg" />
</a>
</div>
);
}

View File

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

View File

@@ -1,9 +1,9 @@
import { PassThrough } from "stream";
import type { EntryContext } from "@remix-run/node"; import type { EntryContext } from "@remix-run/node";
import { Response } from "@remix-run/node"; import { Response } from "@remix-run/node";
import { RemixServer } from "@remix-run/react"; import { RemixServer } from "@remix-run/react";
import isbot from "isbot"; import isbot from "isbot";
import { renderToPipeableStream } from "react-dom/server"; import { renderToPipeableStream } from "react-dom/server";
import { PassThrough } from "stream";
const ABORT_DELAY = 5000; const ABORT_DELAY = 5000;
@@ -11,20 +11,20 @@ export default function handleRequest(
request: Request, request: Request,
responseStatusCode: number, responseStatusCode: number,
responseHeaders: Headers, responseHeaders: Headers,
remixContext: EntryContext remixContext: EntryContext,
) { ) {
return isbot(request.headers.get("user-agent")) return isbot(request.headers.get("user-agent"))
? handleBotRequest( ? handleBotRequest(
request, request,
responseStatusCode, responseStatusCode,
responseHeaders, responseHeaders,
remixContext remixContext,
) )
: handleBrowserRequest( : handleBrowserRequest(
request, request,
responseStatusCode, responseStatusCode,
responseHeaders, responseHeaders,
remixContext remixContext,
); );
} }
@@ -32,7 +32,7 @@ function handleBotRequest(
request: Request, request: Request,
responseStatusCode: number, responseStatusCode: number,
responseHeaders: Headers, responseHeaders: Headers,
remixContext: EntryContext remixContext: EntryContext,
) { ) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let didError = false; let didError = false;
@@ -49,7 +49,7 @@ function handleBotRequest(
new Response(body, { new Response(body, {
headers: responseHeaders, headers: responseHeaders,
status: didError ? 500 : responseStatusCode, status: didError ? 500 : responseStatusCode,
}) }),
); );
pipe(body); pipe(body);
@@ -62,7 +62,7 @@ function handleBotRequest(
console.error(error); console.error(error);
}, },
} },
); );
setTimeout(abort, ABORT_DELAY); setTimeout(abort, ABORT_DELAY);
@@ -73,7 +73,7 @@ function handleBrowserRequest(
request: Request, request: Request,
responseStatusCode: number, responseStatusCode: number,
responseHeaders: Headers, responseHeaders: Headers,
remixContext: EntryContext remixContext: EntryContext,
) { ) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let didError = false; let didError = false;
@@ -90,7 +90,7 @@ function handleBrowserRequest(
new Response(body, { new Response(body, {
headers: responseHeaders, headers: responseHeaders,
status: didError ? 500 : responseStatusCode, status: didError ? 500 : responseStatusCode,
}) }),
); );
pipe(body); pipe(body);
@@ -103,7 +103,7 @@ function handleBrowserRequest(
console.error(error); console.error(error);
}, },
} },
); );
setTimeout(abort, ABORT_DELAY); setTimeout(abort, ABORT_DELAY);

View File

@@ -1,5 +1,5 @@
import codeHikeStyle from "@code-hike/mdx/dist/index.css"; import codeHikeStyle from "@code-hike/mdx/dist/index.css";
import type { LinksFunction, MetaFunction } from "@remix-run/node"; import type { LinksFunction, V2_MetaFunction } from "@remix-run/node";
import { import {
Link, Link,
Links, Links,
@@ -8,19 +8,31 @@ import {
Outlet, Outlet,
Scripts, Scripts,
ScrollRestoration, ScrollRestoration,
isRouteErrorResponse,
useRouteError,
} from "@remix-run/react"; } from "@remix-run/react";
import stylesheet from "~/tailwind.css"; import stylesheet from "~/tailwind.css";
import { Body } from "./components/Body";
import { LinkWrapper } from "./components/LinkWrapper";
import { Notbyai } from "./components/Notbyai";
export const links: LinksFunction = () => [ export const links: LinksFunction = () => [
{ rel: "stylesheet", href: stylesheet }, { rel: "stylesheet", href: stylesheet },
{ rel: "stylesheet", href: codeHikeStyle }, { rel: "stylesheet", href: codeHikeStyle },
]; ];
export const meta: MetaFunction = () => ({ export const meta: V2_MetaFunction = () => [
charset: "utf-8", {
charSet: "utf-8",
},
{
title: "nullndr", title: "nullndr",
viewport: "width=device-width,initial-scale=1", },
}); {
property: "viewport",
content: "width=device-width,initial-scale=1",
},
];
export default function App() { export default function App() {
return ( return (
@@ -29,31 +41,30 @@ export default function App() {
<Meta /> <Meta />
<Links /> <Links />
</head> </head>
<body className="bg-[#202020] text-[#d6d6d6] font-['monospace']"> <Body>
<div className="static sm:relative"> <div className="relative">
<Outlet /> <Outlet />
<div className="fixed m-3 bottom-0 right-0"> <Notbyai />
<a href="https://notbyai.fyi/" target="_blank">
<img src="https://user-images.githubusercontent.com/62137266/225653923-a69103f5-b318-4e52-9ea1-95b61d388366.svg" />
</a>
</div>
</div> </div>
<ScrollRestoration /> <ScrollRestoration />
<Scripts /> <Scripts />
<LiveReload /> <LiveReload />
</body> </Body>
</html> </html>
); );
} }
export function CatchBoundary() { export function ErrorBoundary() {
const error = useRouteError();
if (isRouteErrorResponse(error)) {
return ( return (
<html lang="en"> <html lang="en">
<head> <head>
<Meta /> <Meta />
<Links /> <Links />
</head> </head>
<body className="bg-[#202020] text-[#d6d6d6] font-['monospace']"> <Body>
<div className="flex flex-col items-center justify-around h-[100vh]"> <div className="flex flex-col items-center justify-around h-[100vh]">
<div> <div>
<div className="text-center text-[#ffff00] text-[10vw] font-bold"> <div className="text-center text-[#ffff00] text-[10vw] font-bold">
@@ -61,38 +72,37 @@ export function CatchBoundary() {
</div> </div>
<div className="font-bold">Where do you think you are going?</div> <div className="font-bold">Where do you think you are going?</div>
<div className="text-center"> <div className="text-center">
<div className="mt-5 hover:text-[#e6c2bf] lg:text-xl font-bold"> <LinkWrapper>
<Link to="/">Home</Link> <Link to="/">Home</Link>
</LinkWrapper>
</div> </div>
</div> </div>
</div> </div>
</div> </Body>
</body>
</html> </html>
); );
} }
export function ErrorBoundary() {
return ( return (
<html lang="en"> <html lang="en">
<head> <head>
<Meta /> <Meta />
<Links /> <Links />
</head> </head>
<body className="bg-[#202020] text-[#d6d6d6] font-['monospace']"> <Body>
<div className="flex flex-col items-center justify-around h-[100vh]"> <div className="flex flex-col items-center justify-around h-[100vh]">
<div> <div>
<div className="text-center text-[#ffff00] text-[6vw] font-bold"> <div className="text-center text-[#ffff00] text-[6vw] font-bold">
Something bad happened Something bad happened
</div> </div>
<div className="text-center"> <div className="text-center">
<div className="mt-5 hover:text-[#e6c2bf] lg:text-xl font-bold"> <LinkWrapper>
<Link to="/">Home</Link> <Link to="/">Home</Link>
</LinkWrapper>
</div> </div>
</div> </div>
</div> </div>
</div> </Body>
</body>
</html> </html>
); );
} }

View File

@@ -5,11 +5,13 @@ import {
FaKey, FaKey,
FaLinkedin, FaLinkedin,
FaMastodon, FaMastodon,
FaStackOverflow,
FaTelegramPlane, FaTelegramPlane,
FaTwitter, FaTwitter,
} from "react-icons/fa"; } from "react-icons/fa";
import { IconContext } from "react-icons/lib"; import { IconContext } from "react-icons/lib";
import { MdEmail } from "react-icons/md"; import { MdEmail } from "react-icons/md";
import { LinkWrapper } from "~/components/LinkWrapper";
export default function Index() { export default function Index() {
return ( return (
@@ -21,38 +23,41 @@ export default function Index() {
<span className="animate-blink">|</span> <span className="animate-blink">|</span>
</div> </div>
<nav className="pt-5 flex justify-center flex-wrap"> <nav className="pt-5 flex justify-center flex-wrap">
<IconContext.Provider value={{ color: "yellow", size: "2em" }}> <IconContext.Provider
<a rel="me" href="https://mastodon.uno/@nullndr" className="p-2"> value={{ color: "yellow", className: "p-2", size: "3em" }}
>
<a rel="me" href="https://mastodon.uno/@nullndr">
<FaMastodon /> <FaMastodon />
</a> </a>
<a href="https://t.me/nullndr" className="p-2"> <a href="https://t.me/nullndr">
<FaTelegramPlane /> <FaTelegramPlane />
</a> </a>
<a href="https://gitlab.com/nullndr" className="p-2"> <a href="https://gitlab.com/nullndr">
<FaGitlab /> <FaGitlab />
</a> </a>
<a href="https://github.com/nullndr" className="p-2"> <a href="https://github.com/nullndr">
<FaGithub /> <FaGithub />
</a> </a>
<a href="https://twitter.com/nullndr" className="p-2"> <a href="https://twitter.com/nullndr">
<FaTwitter /> <FaTwitter />
</a> </a>
<a href="mailto: nullndr@duck.com" className="p-2"> <a href="mailto: nullndr@duck.com">
<MdEmail /> <MdEmail />
</a> </a>
<a href="https://linkedin.com/in/nullndr" className="p-2"> <a href="https://linkedin.com/in/nullndr">
<FaLinkedin /> <FaLinkedin />
</a> </a>
<a href="/key.pub" download={true} className="p-2"> <a href="https://stackoverflow.com/users/10503039/nullndr">
<FaStackOverflow />
</a>
<a href="/key.pub" download={true}>
<FaKey /> <FaKey />
</a> </a>
</IconContext.Provider> </IconContext.Provider>
</nav> </nav>
<div className="pt-5 flex flex-col items-center text-xl"> <LinkWrapper>
<Link to="/blog" className="hover:text-[#e6c2bf] font-bold"> <Link to="/blog">Blog</Link>
Blog </LinkWrapper>
</Link>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -2,6 +2,7 @@ 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 { BlogWrapper } from "~/components/BlogWrapper";
import { Title } from "~/components/Title"; import { Title } from "~/components/Title";
import { getMdxFile } from "~/utils/posts.server"; import { getMdxFile } from "~/utils/posts.server";
@@ -29,9 +30,11 @@ export default function () {
return ( return (
<> <>
<Title>{title}</Title> <Title>{title}</Title>
<div className="mx-3 py-10 sm:mx-0 xl:w-1/2 prose dark:prose-invert prose-a:no-underline prose-a:font-bold"> <BlogWrapper>
<div className="dark:prose-invert prose-a:no-underline prose-a:font-bold prose-a:text-[#ffff00] prose-p:text-[#d6d6d6]">
<MdxComponent /> <MdxComponent />
</div> </div>
</BlogWrapper>
</> </>
); );
} }

View File

@@ -1,4 +1,5 @@
import { Link } from "@remix-run/react"; import { Link } from "@remix-run/react";
import { BlogWrapper } from "~/components/BlogWrapper";
type PostProps = { type PostProps = {
filename: string; filename: string;
@@ -9,24 +10,18 @@ type PostProps = {
export function Post({ title, description, filename, published }: PostProps) { export function Post({ title, description, filename, published }: PostProps) {
return ( return (
<div className="mx-5 md:mx-0 md:w-1/2 lg:w-1/3"> <BlogWrapper>
<div className="p-5 border-gray-600 border-2 rounded-lg"> <div className="p-5 text-center font-bold border-gray-600 border-2 rounded-lg">
<Link to={filename}> <Link to={filename}>
<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(
published published,
).toLocaleDateString()})`}</span> ).toLocaleDateString()})`}</span>
</div> {description && <div className="mt-5 text-xl">{description}</div>}
{description && (
<div className="mt-5 italic md:text-xl max-w-3xl text-center">
{description}
</div>
)}
</Link> </Link>
</div> </div>
</div> </BlogWrapper>
); );
} }

View File

@@ -9,7 +9,7 @@ export const handle = {
text: "Home", text: "Home",
}; };
export const loader = async () => { export const loader = () => {
return findPosts(); return findPosts();
}; };
@@ -19,11 +19,7 @@ export default function () {
<> <>
<Title>Here I blog about whatever get my attention</Title> <Title>Here I blog about whatever get my attention</Title>
{posts.length > 0 ? ( {posts.length > 0 ? (
<div className="py-10 w-full sm:flex sm:flex-col sm:items-center space-y-5"> posts.map((post, i) => <Post {...post} key={i} />)
{posts.map((post, i) => (
<Post {...post} key={i} />
))}
</div>
) : ( ) : (
<EmptyState /> <EmptyState />
)} )}

View File

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

View File

@@ -2,5 +2,11 @@ import { useMatches } from "@remix-run/react";
export function useMatch() { export function useMatch() {
const matches = useMatches(); const matches = useMatches();
return matches[matches.length - 1]; const { handle, ...rest } = matches[matches.length - 1];
if (handle == null) {
throw new Error("Bruh");
}
return { handle, ...rest};
} }

2723
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -8,30 +8,26 @@
"typecheck": "tsc" "typecheck": "tsc"
}, },
"dependencies": { "dependencies": {
"@code-hike/mdx": "^0.8.1-next.0", "@code-hike/mdx": "^0.8.3",
"@prisma/client": "^4.11.0", "@remix-run/node": "^1.16.0",
"@remix-run/node": "^1.14.0", "@remix-run/react": "^1.16.0",
"@remix-run/react": "^1.14.0", "@remix-run/serve": "^1.16.0",
"@remix-run/serve": "^1.14.0",
"esbuild": "^0.17.11", "esbuild": "^0.17.11",
"isbot": "^3.6.5", "isbot": "^3.6.5",
"mdx-bundler": "^9.2.1", "mdx-bundler": "^9.2.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"shiki": "^0.14.1" "shiki": "^0.14.2"
}, },
"devDependencies": { "devDependencies": {
"@remix-run/dev": "^1.14.0", "@remix-run/dev": "^1.16.0",
"@remix-run/eslint-config": "^1.14.0", "@remix-run/eslint-config": "^1.16.0",
"@tailwindcss/typography": "^0.5.9", "@tailwindcss/typography": "^0.5.9",
"@types/react": "^18.0.25", "@types/react": "^18.0.25",
"@types/react-dom": "^18.0.8", "@types/react-dom": "^18.0.8",
"eslint": "^8.27.0", "eslint": "^8.27.0",
"react-icons": "^4.7.1", "react-icons": "^4.7.1",
"tailwindcss": "^3.2.7", "tailwindcss": "^3.3.2",
"typescript": "^4.8.4" "typescript": "^5.0.4"
},
"engines": {
"node": ">=14"
} }
} }

View File

@@ -2,8 +2,12 @@
module.exports = { module.exports = {
ignoredRouteFiles: ["**/.*"], ignoredRouteFiles: ["**/.*"],
serverDependenciesToBundle: ["mdx-bundler"], serverDependenciesToBundle: ["mdx-bundler"],
tailwind: true,
serverModuleFormat: "cjs",
future: { future: {
unstable_tailwind: true,
v2_routeConvention: true, v2_routeConvention: true,
v2_errorBoundary: true,
v2_normalizeFormMethod: true,
v2_meta: true,
}, },
}; };