Actually fix broken nextjs

This commit is contained in:
Timothy Pidashev
2024-06-05 18:09:14 -07:00
parent ef9522cf3e
commit 4c97f4f52d
21 changed files with 226 additions and 4065 deletions

View File

@@ -1,28 +0,0 @@
# Use an official Node.js runtime as a base image
FROM node:20.10-alpine
# Set working directory
WORKDIR /app
# Copy "package.json" and "package-lock.json" before other files
# Utilise Docker cache to save re-installing dependencies if unchanged
COPY ./package*.json .
# Install dependencies
RUN npm install
# Change ownership to the non-root user
RUN chown -R node:node /app
# Copy all files
COPY . .
# Expose the listening port
EXPOSE 3000
# Run container as non-root (unprivileged) user
# The "node" user is provided in the Node.js Alpine base image
USER node
# Launch app with PM2
CMD [ "npm", "run", "dev" ]

View File

@@ -1,18 +0,0 @@
import { getBlogBySlug, getAllBlogSlug } from "../fetchers"
export async function generateStaticParams() {
return getAllBlogSlug()
}
export default async function BlogPage({
params,
}: {
params: { slug: string }
}) {
const blog = await getBlogBySlug(params.slug)
return (
<main className="prose">
<article>{blog.content}</article>
</main>
)
}

View File

@@ -1,74 +0,0 @@
---
title: 'When to Use Static Generation v.s. Server-side Rendering'
author: "Timothy Pidashev"
date: '2020-01-02'
---
We recommend using **Static Generation** (with and without data) whenever possible because your page can be built once and served by CDN, which makes it much faster than having a server render the page on every request.
You can use Static Generation for many types of pages, including:
- Marketing pages
- Blog posts
- E-commerce product listings
- Help and documentation
```jsx
import React, { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
const increment = () => {
setCount(count + 1);
};
const decrement = () => {
setCount(count - 1);
};
return (
<div>
<h1>Count: {count}</h1>
<button onClick={increment}>Increment</button>
<button onClick={decrement}>Decrement</button>
</div>
);
}
export default Counter;
```
You should ask yourself: "Can I pre-render this page **ahead** of a user's request?" If the answer is yes, then you should choose Static Generation.
On the other hand, Static Generation is **not** a good idea if you cannot pre-render a page ahead of a user's request. Maybe your page shows frequently updated data, and the page content changes on every request.
In that case, you can use **Server-Side Rendering**. It will be slower, but the pre-rendered page will always be up-to-date. Or you can skip pre-rendering and use client-side JavaScript to populate data.
```jsx
const [count, setCount] = useState(0);
const increment = () => {
setCount(count + 1);
};
const decrement = () => {
setCount(count - 1);
};
return (
<div>
<h1>Count: {count}</h1>
<button onClick={increment}>Increment</button>
<button onClick={decrement}>Decrement</button>
</div>
);
}
export default Counter;
```
You should ask yourself: "Can I pre-render this page **ahead** of a user's request?" If the answer is yes, then you should choose Static Generation.
On the other hand, Static Generation is **not** a good idea if you cannot pre-render a page ahead of a user's request. Maybe your page shows frequently updated data, and the page content changes on every request.
In that case, you can use **Server-Side Rendering**. It will be slower, but the pre-rendered page will always be up-to-date. Or you can skip pre-rendering and use client-side JavaScript to populate data.

View File

@@ -1,39 +0,0 @@
import fs from "fs";
import path from "path";
import rehypeHighlight from 'rehype-highlight'
import { compileMDX } from "next-mdx-remote/rsc";
const contentDir = path.join(process.cwd(), "app/blog/_mdx-content")
export async function getBlogBySlug(slug: string) {
const fileName = slug + ".mdx"
const filePath = path.join(contentDir, fileName)
const fileContent = fs.readFileSync(filePath, "utf8")
const { frontmatter, content } = await compileMDX<{
title: string
author: string
publishDate: string
}>({
source: fileContent,
options: { parseFrontmatter: true },
})
return {
frontmatter,
content,
slug: path.parse(fileName).name,
}
}
export async function getBlogs() {
const files = fs.readdirSync(contentDir)
const blogs = await Promise.all(
files.map(async (file) => await getBlogBySlug(path.parse(file).name))
)
return blogs
}
export function getAllBlogSlug() {
const files = fs.readdirSync(contentDir)
const slugs = files.map((file) => ({ slug: path.parse(file).name }))
return slugs
}

View File

@@ -1,18 +0,0 @@
import Link from "next/link"
import { getBlogs } from "./fetchers"
export default async function BlogsPage() {
const blogs = await getBlogs()
return (
<main>
{blogs.map((blog, i) => (
<article key={i} className="grid grid-cols-4 text-3xl">
<h1>{blog.frontmatter.title}</h1>
<p>{blog.frontmatter.author}</p>
<p>{blog.frontmatter.publishDate}</p>
<Link href={`/blogs/${blog.slug}`}>Read More</Link>
</article>
))}
</main>
)
}

BIN
src/app/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

113
src/app/page.js Normal file
View File

@@ -0,0 +1,113 @@
import Image from "next/image";
export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
Get started by editing&nbsp;
<code className="font-mono font-bold">app/page.js</code>
</p>
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
<a
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{" "}
<Image
src="/vercel.svg"
alt="Vercel Logo"
className="dark:invert"
width={100}
height={24}
priority
/>
</a>
</div>
</div>
<div className="relative flex place-items-center before:absolute before:h-[300px] before:w-full sm:before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-full sm:after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700 before:dark:opacity-10 after:dark:from-sky-900 after:dark:via-[#0141ff] after:dark:opacity-40 before:lg:h-[360px] z-[-1]">
<Image
className="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert"
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>
<div className="mb-32 grid text-center lg:max-w-5xl lg:w-full lg:mb-0 lg:grid-cols-4 lg:text-left">
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Docs{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Find in-depth information about Next.js features and API.
</p>
</a>
<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800 hover:dark:bg-opacity-30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Learn{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Learn about Next.js in an interactive course with&nbsp;quizzes!
</p>
</a>
<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Templates{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Explore starter templates for Next.js.
</p>
</a>
<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Deploy{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50 text-balance`}>
Instantly deploy your Next.js site to a shareable URL with Vercel.
</p>
</a>
</div>
</main>
);
}

View File

@@ -1,9 +1,6 @@
// Imports
import Container from "@/components/ui/container";
import Hero from "@/components/hero";
// Metadata
// Exports
export default function Index() {
return (

View File

@@ -1,12 +0,0 @@
// Imports
// Metadata
// Exports
export default function Projects() {
return (
<div>
projects
</div>
);
}

View File

@@ -1,11 +0,0 @@
// Imports
// Metadata
// Exports
export default function Resume() {
return (
<div>
</div>
);
}

View File

@@ -1,11 +0,0 @@
// Imports
// Medatada
// Exports
export default function Shop() {
return (
<div>
</div>
);
}

View File

@@ -5,37 +5,20 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start --hostname 0.0.0.0",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@mdx-js/loader": "^3.0.1",
"@mdx-js/react": "^3.0.1",
"@next/mdx": "^14.2.3",
"@react-three/drei": "^9.102.6",
"@react-three/fiber": "^8.15.19",
"@types/mdx": "^2.0.13",
"framer-motion": "^11.0.14",
"gray-matter": "^4.0.3",
"mdx": "^0.3.1",
"next": "14.1.3",
"next-mdx-remote": "^5.0.0",
"framer-motion": "^11.2.10",
"next": "14.2.3",
"next-themes": "^0.3.0",
"react": "^18",
"react-dom": "^18",
"react-icons": "^5.0.1",
"react-intersection-observer": "^9.8.1",
"rehype-highlight": "^7.0.0",
"three": "^0.162.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.2.1",
"typewriter-effect": "^2.21.0"
},
"devDependencies": {
"@types/node": "20.14.1",
"autoprefixer": "^10.4.18",
"eslint": "^8",
"eslint-config-next": "14.1.3",
"postcss": "^8.4.36",
"tailwindcss": "^3.4.1",
"typescript": "5.4.5"
"postcss": "^8",
"tailwindcss": "^3.4.1"
}
}

View File

@@ -1,6 +0,0 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};

8
src/postcss.config.mjs Normal file
View File

@@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};
export default config;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 304 KiB

View File

@@ -1,7 +1,9 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./**/*.{js,ts,jsx,tsx,mdx}"
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./app/**/*.{js,ts,jsx,tsx,mdx}",
],
darkMode: "class",
theme: {

View File

@@ -1,34 +0,0 @@
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
]
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}

File diff suppressed because it is too large Load Diff