Skip to content

Commit d7fa122

Browse files
committed
Added lesson 12
1 parent a44d2fe commit d7fa122

35 files changed

+10877
-1
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# "Next.js 13 for Beginners"
22

3-
### Full Course - ?? Chapters
3+
### Full Course - 12 Chapters
44

55
---
66

@@ -68,6 +68,18 @@
6868
- 🔗 [remark-html](https://www.npmjs.com/package/remark-html)
6969
- 🔗 [limiter](https://www.npmjs.com/package/limiter)
7070

71+
72+
### 🚀 Final Project Dependencies
73+
- 🔗 [react-icons](https://www.npmjs.com/package/react-icons)
74+
- 🔗 [next-mdx-remote](https://www.npmjs.com/package/next-mdx-remote)
75+
- 🔗 [highlight.js](https://www.npmjs.com/package/highlight.js)
76+
- 🔗 [rehype-highlight](https://www.npmjs.com/package/rehype-highlight)
77+
- 🔗 [rehype-slug](https://www.npmjs.com/package/rehype-slug)
78+
- 🔗 [rehype-autolink-headings](https://www.npmjs.com/package/rehype-autolink-headings)
79+
- 🔗 [sharp](https://www.npmjs.com/package/sharp)
80+
- 🔗 [next-sitemap](https://www.npmjs.com/package/next-sitemap)
81+
82+
7183
---
7284

7385
### 💻 Source Code
@@ -83,5 +95,6 @@
8395
- 🔗 [Chapter 9 - Middleware](https://github.com/gitdagray/next-js-course/tree/main/next09)
8496
- 🔗 [Chapter 10 - Background & On-Demand Revalidation](https://github.com/gitdagray/next-js-course/tree/main/next10)
8597
- 🔗 [Chapter 11 - Mutating Data](https://github.com/gitdagray/next-js-course/tree/main/next11)
98+
- 🔗 [Chapter 12 - Build and Deploy a Blog with Remote MDX Content](https://github.com/gitdagray/next-js-course/tree/main/next12)
8699

87100

next12/.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "next/core-web-vitals",
3+
"rules": {
4+
"react/no-unescaped-entities": "off"
5+
}
6+
}

next12/.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
.vscode
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
.pnpm-debug.log*
28+
29+
# local env files
30+
.env*.local
31+
32+
# vercel
33+
.vercel
34+
35+
# typescript
36+
*.tsbuildinfo
37+
next-env.d.ts

next12/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
```
14+
15+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
16+
17+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
18+
19+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
20+
21+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
22+
23+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
24+
25+
## Learn More
26+
27+
To learn more about Next.js, take a look at the following resources:
28+
29+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
30+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
31+
32+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
33+
34+
## Deploy on Vercel
35+
36+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
37+
38+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

next12/app/api/revalidate/route.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { NextRequest, NextResponse } from 'next/server'
2+
import { revalidatePath } from 'next/cache'
3+
4+
export async function GET(request: NextRequest) {
5+
const secret = request.nextUrl.searchParams.get('secret')
6+
7+
if (secret !== process.env.MY_SECRET_TOKEN) {
8+
return new NextResponse(JSON.stringify({ message: 'Invalid Token' }), {
9+
status: 401,
10+
statusText: 'Unauthorized',
11+
headers: {
12+
'Content-Type': 'application/json'
13+
}
14+
})
15+
}
16+
17+
const path = request.nextUrl.searchParams.get('path') || '/'
18+
19+
revalidatePath(path)
20+
21+
return NextResponse.json({ revalidated: true })
22+
}

next12/app/components/CustomImage.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Image from "next/image"
2+
3+
type Props = {
4+
src: string,
5+
alt: string,
6+
priority?: string,
7+
}
8+
9+
export default function CustomImage({ src, alt, priority }: Props) {
10+
11+
const prty = priority ? true : false
12+
13+
return (
14+
15+
<div className="w-full h-full">
16+
<Image
17+
className="rounded-lg mx-auto"
18+
src={src}
19+
alt={alt}
20+
width={650}
21+
height={650}
22+
priority={prty}
23+
/>
24+
</div>
25+
)
26+
}

next12/app/components/ListItem.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Link from "next/link"
2+
import getFormattedDate from "@/lib/getFormattedDate"
3+
4+
type Props = {
5+
post: Meta
6+
}
7+
8+
export default function ListItem({ post }: Props) {
9+
const { id, title, date } = post
10+
const formattedDate = getFormattedDate(date)
11+
12+
return (
13+
<li className="mt-4 text-2xl dark:text-white/90">
14+
<Link className="underline hover:text-black/70 dark:hover:text-white" href={`/posts/${id}`}>{title}</Link>
15+
<br />
16+
<p className="text-sm mt-1">{formattedDate}</p>
17+
</li>
18+
)
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Image from "next/image"
2+
3+
export default function MyProfilePic() {
4+
return (
5+
<section className="w-full mx-auto">
6+
<Image
7+
className="border-4 border-black dark:border-slate-500 drop-shadow-xl shadow-black rounded-full mx-auto mt-8"
8+
src="/images/profile-photo-600x600.png"
9+
width={200}
10+
height={200}
11+
alt="Dave Gray"
12+
priority={true}
13+
/>
14+
</section>
15+
)
16+
}

next12/app/components/Navbar.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Link from "next/link"
2+
import { FaYoutube, FaTwitter, FaGithub, FaLaptop } from "react-icons/fa"
3+
4+
export default function Navbar() {
5+
return (
6+
<nav className="bg-slate-600 p-4 sticky top-0 drop-shadow-xl z-10">
7+
<div className="md:px-6 prose prose-xl mx-auto flex justify-between flex-col sm:flex-row">
8+
<h1 className="text-3xl font-bold text-white grid place-content-center mb-2 md:mb-0">
9+
<Link href="/" className="text-white/90 no-underline hover:text-white">Dave Gray</Link>
10+
</h1>
11+
<div className="flex flex-row justify-center sm:justify-evenly align-middle gap-4 text-white text-4xl lg:text-5xl">
12+
<Link className="text-white/90 hover:text-white" href="https://www.youtube.com/@DaveGrayTeachesCode">
13+
<FaYoutube />
14+
</Link>
15+
<Link className="text-white/90 hover:text-white" href="https://courses.davegray.codes/">
16+
<FaLaptop />
17+
</Link>
18+
<Link className="text-white/90 hover:text-white" href="https://github.com/gitdagray">
19+
<FaGithub />
20+
</Link>
21+
<Link className="text-white/90 hover:text-white" href="https://twitter.com/yesdavidgray">
22+
<FaTwitter />
23+
</Link>
24+
</div>
25+
</div>
26+
</nav>
27+
)
28+
}

next12/app/components/Posts.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { getPostsMeta } from "@/lib/posts"
2+
import ListItem from "./ListItem"
3+
4+
export default async function Posts() {
5+
const posts = await getPostsMeta()
6+
7+
if (!posts) {
8+
return <p className="mt-10 text-center">Sorry, no posts available.</p>
9+
}
10+
11+
return (
12+
<section className="mt-6 mx-auto max-w-2xl">
13+
<h2 className="text-4xl font-bold dark:text-white/90">Blog</h2>
14+
<ul className="w-full list-none p-0">
15+
{posts.map(post => (
16+
<ListItem key={post.id} post={post} />
17+
))}
18+
</ul>
19+
</section>
20+
)
21+
}

0 commit comments

Comments
 (0)