refactor: code refactor
This commit is contained in:
11
app/components/BlogWrapper.tsx
Normal file
11
app/components/BlogWrapper.tsx
Normal 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
9
app/components/Body.tsx
Normal 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>
|
||||
);
|
||||
}
|
11
app/components/LinkWrapper.tsx
Normal file
11
app/components/LinkWrapper.tsx
Normal 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>
|
||||
);
|
||||
}
|
9
app/components/Notbyai.tsx
Normal file
9
app/components/Notbyai.tsx
Normal 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>
|
||||
);
|
||||
}
|
@@ -1,7 +1,9 @@
|
||||
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">
|
||||
<div className="mt-5 mx-3 w-full flex flex-col items-center">
|
||||
<div className="text-[#ffff00] font-bold text-2xl">
|
||||
<span>{children}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { PassThrough } from "stream";
|
||||
import type { EntryContext } from "@remix-run/node";
|
||||
import { Response } from "@remix-run/node";
|
||||
import { RemixServer } from "@remix-run/react";
|
||||
import isbot from "isbot";
|
||||
import { renderToPipeableStream } from "react-dom/server";
|
||||
import { PassThrough } from "stream";
|
||||
|
||||
const ABORT_DELAY = 5000;
|
||||
|
||||
@@ -11,20 +11,20 @@ export default function handleRequest(
|
||||
request: Request,
|
||||
responseStatusCode: number,
|
||||
responseHeaders: Headers,
|
||||
remixContext: EntryContext
|
||||
remixContext: EntryContext,
|
||||
) {
|
||||
return isbot(request.headers.get("user-agent"))
|
||||
? handleBotRequest(
|
||||
request,
|
||||
responseStatusCode,
|
||||
responseHeaders,
|
||||
remixContext
|
||||
remixContext,
|
||||
)
|
||||
: handleBrowserRequest(
|
||||
request,
|
||||
responseStatusCode,
|
||||
responseHeaders,
|
||||
remixContext
|
||||
remixContext,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ function handleBotRequest(
|
||||
request: Request,
|
||||
responseStatusCode: number,
|
||||
responseHeaders: Headers,
|
||||
remixContext: EntryContext
|
||||
remixContext: EntryContext,
|
||||
) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let didError = false;
|
||||
@@ -49,7 +49,7 @@ function handleBotRequest(
|
||||
new Response(body, {
|
||||
headers: responseHeaders,
|
||||
status: didError ? 500 : responseStatusCode,
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
pipe(body);
|
||||
@@ -62,7 +62,7 @@ function handleBotRequest(
|
||||
|
||||
console.error(error);
|
||||
},
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
setTimeout(abort, ABORT_DELAY);
|
||||
@@ -73,7 +73,7 @@ function handleBrowserRequest(
|
||||
request: Request,
|
||||
responseStatusCode: number,
|
||||
responseHeaders: Headers,
|
||||
remixContext: EntryContext
|
||||
remixContext: EntryContext,
|
||||
) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let didError = false;
|
||||
@@ -90,7 +90,7 @@ function handleBrowserRequest(
|
||||
new Response(body, {
|
||||
headers: responseHeaders,
|
||||
status: didError ? 500 : responseStatusCode,
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
pipe(body);
|
||||
@@ -103,7 +103,7 @@ function handleBrowserRequest(
|
||||
|
||||
console.error(error);
|
||||
},
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
setTimeout(abort, ABORT_DELAY);
|
||||
|
58
app/root.tsx
58
app/root.tsx
@@ -1,5 +1,5 @@
|
||||
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 {
|
||||
Link,
|
||||
Links,
|
||||
@@ -8,19 +8,31 @@ import {
|
||||
Outlet,
|
||||
Scripts,
|
||||
ScrollRestoration,
|
||||
isRouteErrorResponse,
|
||||
useRouteError,
|
||||
} from "@remix-run/react";
|
||||
import stylesheet from "~/tailwind.css";
|
||||
import { Body } from "./components/Body";
|
||||
import { LinkWrapper } from "./components/LinkWrapper";
|
||||
import { Notbyai } from "./components/Notbyai";
|
||||
|
||||
export const links: LinksFunction = () => [
|
||||
{ rel: "stylesheet", href: stylesheet },
|
||||
{ rel: "stylesheet", href: codeHikeStyle },
|
||||
];
|
||||
|
||||
export const meta: MetaFunction = () => ({
|
||||
charset: "utf-8",
|
||||
export const meta: V2_MetaFunction = () => [
|
||||
{
|
||||
charSet: "utf-8",
|
||||
},
|
||||
{
|
||||
title: "nullndr",
|
||||
viewport: "width=device-width,initial-scale=1",
|
||||
});
|
||||
},
|
||||
{
|
||||
property: "viewport",
|
||||
content: "width=device-width,initial-scale=1",
|
||||
},
|
||||
];
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
@@ -29,31 +41,30 @@ export default function App() {
|
||||
<Meta />
|
||||
<Links />
|
||||
</head>
|
||||
<body className="bg-[#202020] text-[#d6d6d6] font-['monospace']">
|
||||
<div className="static sm:relative">
|
||||
<Body>
|
||||
<div className="relative">
|
||||
<Outlet />
|
||||
<div className="fixed m-3 bottom-0 right-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>
|
||||
<Notbyai />
|
||||
</div>
|
||||
<ScrollRestoration />
|
||||
<Scripts />
|
||||
<LiveReload />
|
||||
</body>
|
||||
</Body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
export function CatchBoundary() {
|
||||
export function ErrorBoundary() {
|
||||
const error = useRouteError();
|
||||
|
||||
if (isRouteErrorResponse(error)) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<Meta />
|
||||
<Links />
|
||||
</head>
|
||||
<body className="bg-[#202020] text-[#d6d6d6] font-['monospace']">
|
||||
<Body>
|
||||
<div className="flex flex-col items-center justify-around h-[100vh]">
|
||||
<div>
|
||||
<div className="text-center text-[#ffff00] text-[10vw] font-bold">
|
||||
@@ -61,38 +72,37 @@ export function CatchBoundary() {
|
||||
</div>
|
||||
<div className="font-bold">Where do you think you are going?</div>
|
||||
<div className="text-center">
|
||||
<div className="mt-5 hover:text-[#e6c2bf] lg:text-xl font-bold">
|
||||
<LinkWrapper>
|
||||
<Link to="/">Home</Link>
|
||||
</LinkWrapper>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</Body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function ErrorBoundary() {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<Meta />
|
||||
<Links />
|
||||
</head>
|
||||
<body className="bg-[#202020] text-[#d6d6d6] font-['monospace']">
|
||||
<Body>
|
||||
<div className="flex flex-col items-center justify-around h-[100vh]">
|
||||
<div>
|
||||
<div className="text-center text-[#ffff00] text-[6vw] font-bold">
|
||||
Something bad happened
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="mt-5 hover:text-[#e6c2bf] lg:text-xl font-bold">
|
||||
<LinkWrapper>
|
||||
<Link to="/">Home</Link>
|
||||
</LinkWrapper>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</Body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
@@ -5,11 +5,13 @@ import {
|
||||
FaKey,
|
||||
FaLinkedin,
|
||||
FaMastodon,
|
||||
FaStackOverflow,
|
||||
FaTelegramPlane,
|
||||
FaTwitter,
|
||||
} from "react-icons/fa";
|
||||
import { IconContext } from "react-icons/lib";
|
||||
import { MdEmail } from "react-icons/md";
|
||||
import { LinkWrapper } from "~/components/LinkWrapper";
|
||||
|
||||
export default function Index() {
|
||||
return (
|
||||
@@ -21,38 +23,41 @@ export default function Index() {
|
||||
<span className="animate-blink">|</span>
|
||||
</div>
|
||||
<nav className="pt-5 flex justify-center flex-wrap">
|
||||
<IconContext.Provider value={{ color: "yellow", size: "2em" }}>
|
||||
<a rel="me" href="https://mastodon.uno/@nullndr" className="p-2">
|
||||
<IconContext.Provider
|
||||
value={{ color: "yellow", className: "p-2", size: "3em" }}
|
||||
>
|
||||
<a rel="me" href="https://mastodon.uno/@nullndr">
|
||||
<FaMastodon />
|
||||
</a>
|
||||
<a href="https://t.me/nullndr" className="p-2">
|
||||
<a href="https://t.me/nullndr">
|
||||
<FaTelegramPlane />
|
||||
</a>
|
||||
<a href="https://gitlab.com/nullndr" className="p-2">
|
||||
<a href="https://gitlab.com/nullndr">
|
||||
<FaGitlab />
|
||||
</a>
|
||||
<a href="https://github.com/nullndr" className="p-2">
|
||||
<a href="https://github.com/nullndr">
|
||||
<FaGithub />
|
||||
</a>
|
||||
<a href="https://twitter.com/nullndr" className="p-2">
|
||||
<a href="https://twitter.com/nullndr">
|
||||
<FaTwitter />
|
||||
</a>
|
||||
<a href="mailto: nullndr@duck.com" className="p-2">
|
||||
<a href="mailto: nullndr@duck.com">
|
||||
<MdEmail />
|
||||
</a>
|
||||
<a href="https://linkedin.com/in/nullndr" className="p-2">
|
||||
<a href="https://linkedin.com/in/nullndr">
|
||||
<FaLinkedin />
|
||||
</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 />
|
||||
</a>
|
||||
</IconContext.Provider>
|
||||
</nav>
|
||||
<div className="pt-5 flex flex-col items-center text-xl">
|
||||
<Link to="/blog" className="hover:text-[#e6c2bf] font-bold">
|
||||
Blog
|
||||
</Link>
|
||||
</div>
|
||||
<LinkWrapper>
|
||||
<Link to="/blog">Blog</Link>
|
||||
</LinkWrapper>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -2,6 +2,7 @@ import type { LoaderArgs } from "@remix-run/node";
|
||||
import { useLoaderData } from "@remix-run/react";
|
||||
import { getMDXComponent } from "mdx-bundler/client";
|
||||
import React from "react";
|
||||
import { BlogWrapper } from "~/components/BlogWrapper";
|
||||
import { Title } from "~/components/Title";
|
||||
import { getMdxFile } from "~/utils/posts.server";
|
||||
|
||||
@@ -29,9 +30,11 @@ export default function () {
|
||||
return (
|
||||
<>
|
||||
<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 />
|
||||
</div>
|
||||
</BlogWrapper>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { Link } from "@remix-run/react";
|
||||
import { BlogWrapper } from "~/components/BlogWrapper";
|
||||
|
||||
type PostProps = {
|
||||
filename: string;
|
||||
@@ -9,24 +10,18 @@ type PostProps = {
|
||||
|
||||
export function Post({ title, description, filename, published }: PostProps) {
|
||||
return (
|
||||
<div className="mx-5 md:mx-0 md:w-1/2 lg:w-1/3">
|
||||
<div className="p-5 border-gray-600 border-2 rounded-lg">
|
||||
<BlogWrapper>
|
||||
<div className="p-5 text-center font-bold border-gray-600 border-2 rounded-lg">
|
||||
<Link to={filename}>
|
||||
<div className="text-center font-bold">
|
||||
<span className="text-[#ffff00] hover:text-[#e6c2bf] md:text-2xl">
|
||||
<span className="text-[#ffff00] hover:text-[#e6c2bf] text-2xl">
|
||||
{title}
|
||||
</span>
|
||||
<span className="ml-2">{`(${new Date(
|
||||
published
|
||||
published,
|
||||
).toLocaleDateString()})`}</span>
|
||||
</div>
|
||||
{description && (
|
||||
<div className="mt-5 italic md:text-xl max-w-3xl text-center">
|
||||
{description}
|
||||
</div>
|
||||
)}
|
||||
{description && <div className="mt-5 text-xl">{description}</div>}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</BlogWrapper>
|
||||
);
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ export const handle = {
|
||||
text: "Home",
|
||||
};
|
||||
|
||||
export const loader = async () => {
|
||||
export const loader = () => {
|
||||
return findPosts();
|
||||
};
|
||||
|
||||
@@ -19,11 +19,7 @@ export default function () {
|
||||
<>
|
||||
<Title>Here I blog about whatever get my attention</Title>
|
||||
{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} />
|
||||
))}
|
||||
</div>
|
||||
posts.map((post, i) => <Post {...post} key={i} />)
|
||||
) : (
|
||||
<EmptyState />
|
||||
)}
|
||||
|
@@ -1,18 +1,14 @@
|
||||
import { Link, Outlet } from "@remix-run/react";
|
||||
import { LinkWrapper } from "~/components/LinkWrapper";
|
||||
import { useMatch } from "./useMatch";
|
||||
|
||||
export default function () {
|
||||
const { handle } = useMatch();
|
||||
return (
|
||||
<div className="flex h-screen min-h-full flex-col items-center">
|
||||
{handle && (
|
||||
<Link
|
||||
className="mt-5 hover:text-[#e6c2bf] text-xl font-bold"
|
||||
to={handle.to}
|
||||
>
|
||||
{handle.text}
|
||||
</Link>
|
||||
)}
|
||||
<div>
|
||||
<LinkWrapper>
|
||||
<Link to={handle.to}>{handle.text}</Link>
|
||||
</LinkWrapper>
|
||||
<Outlet />
|
||||
</div>
|
||||
);
|
||||
|
@@ -2,5 +2,11 @@ import { useMatches } from "@remix-run/react";
|
||||
|
||||
export function useMatch() {
|
||||
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
2723
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@@ -8,30 +8,26 @@
|
||||
"typecheck": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@code-hike/mdx": "^0.8.1-next.0",
|
||||
"@prisma/client": "^4.11.0",
|
||||
"@remix-run/node": "^1.14.0",
|
||||
"@remix-run/react": "^1.14.0",
|
||||
"@remix-run/serve": "^1.14.0",
|
||||
"@code-hike/mdx": "^0.8.3",
|
||||
"@remix-run/node": "^1.16.0",
|
||||
"@remix-run/react": "^1.16.0",
|
||||
"@remix-run/serve": "^1.16.0",
|
||||
"esbuild": "^0.17.11",
|
||||
"isbot": "^3.6.5",
|
||||
"mdx-bundler": "^9.2.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"shiki": "^0.14.1"
|
||||
"shiki": "^0.14.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@remix-run/dev": "^1.14.0",
|
||||
"@remix-run/eslint-config": "^1.14.0",
|
||||
"@remix-run/dev": "^1.16.0",
|
||||
"@remix-run/eslint-config": "^1.16.0",
|
||||
"@tailwindcss/typography": "^0.5.9",
|
||||
"@types/react": "^18.0.25",
|
||||
"@types/react-dom": "^18.0.8",
|
||||
"eslint": "^8.27.0",
|
||||
"react-icons": "^4.7.1",
|
||||
"tailwindcss": "^3.2.7",
|
||||
"typescript": "^4.8.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
"tailwindcss": "^3.3.2",
|
||||
"typescript": "^5.0.4"
|
||||
}
|
||||
}
|
||||
|
@@ -2,8 +2,12 @@
|
||||
module.exports = {
|
||||
ignoredRouteFiles: ["**/.*"],
|
||||
serverDependenciesToBundle: ["mdx-bundler"],
|
||||
tailwind: true,
|
||||
serverModuleFormat: "cjs",
|
||||
future: {
|
||||
unstable_tailwind: true,
|
||||
v2_routeConvention: true,
|
||||
v2_errorBoundary: true,
|
||||
v2_normalizeFormMethod: true,
|
||||
v2_meta: true,
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user