forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: update
with-mdx-remote
example to utilize the App Router (v…
…ercel#74067) ## Description This PR updates the [`with-mdx-remote`](https://github.com/vercel/next.js/tree/canary/examples/with-mdx-remote) example to use the App Router and TypeScript. Here are the changes that have been made: 1. Renamed the `pages` folder to the `app` folder. 2. Converted JavaScript to TypeScript files and created `tsconfig.json`. 3. Created a new `global.css` and `layout.tsx` files in the app directory. 4. Used [CSS module](https://github.com/css-modules/css-modules) instead of [styled-jsx](https://github.com/vercel/styled-jsx). 5. Removed [`next-remote-watch`](https://github.com/hashicorp/next-remote-watch) due to incompatibility and no maintenance. 6. Removed [`gray-matter`](https://github.com/jonschlinkert/gray-matter) and implement front-matter parser as well. 7. Updated the `.gitignore`, `package.json` and README.md files. The new app looks and works much the same as the old one. ### Adding or Updating Examples - [x] The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - [x] Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md --------- Co-authored-by: Sam Ko <[email protected]>
- Loading branch information
1 parent
d31b8b8
commit 9332370
Showing
24 changed files
with
360 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.description { | ||
opacity: 0.6; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { notFound } from "next/navigation"; | ||
import { CustomMDX } from "@/components/mdx"; | ||
import { getPosts } from "@/lib/utils"; | ||
import styles from "./page.module.css"; | ||
import Link from "next/link"; | ||
|
||
export function generateStaticParams() { | ||
const posts = getPosts(); | ||
|
||
return posts.map((post) => ({ | ||
slug: post.slug, | ||
})); | ||
} | ||
|
||
export default async function Blog({ | ||
params, | ||
}: { | ||
params: Promise<{ slug: string }>; | ||
}) { | ||
const slug = (await params).slug; | ||
const post = getPosts().find((post) => post.slug === slug); | ||
|
||
if (!post) { | ||
notFound(); | ||
} | ||
|
||
return ( | ||
<> | ||
<header> | ||
<nav> | ||
<Link href="/">👈 Go back home</Link> | ||
</nav> | ||
</header> | ||
<main> | ||
<h1 className={styles.postHeader}>{post.metadata.title}</h1> | ||
{post.metadata.description && ( | ||
<p className={styles.description}>{post.metadata.description}</p> | ||
)} | ||
<article> | ||
<CustomMDX source={post.content} /> | ||
</article> | ||
</main> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
:root { | ||
--background: #ffffff; | ||
--foreground: #171717; | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
:root { | ||
--background: #0a0a0a; | ||
--foreground: #ededed; | ||
} | ||
} | ||
|
||
html, | ||
body { | ||
font: 100%/1.5 system-ui; | ||
max-width: 100vw; | ||
overflow-x: hidden; | ||
} | ||
|
||
body { | ||
color: var(--foreground); | ||
background: var(--background); | ||
font-family: Arial, Helvetica, sans-serif; | ||
max-width: 36rem; | ||
margin: 0 auto; | ||
padding: 1.5rem; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
* { | ||
box-sizing: border-box; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
a { | ||
color: inherit; | ||
text-decoration-thickness: 2px; | ||
} | ||
|
||
a:hover { | ||
color: royalblue; | ||
text-decoration-color: currentcolor; | ||
} | ||
|
||
p { | ||
margin-bottom: 1.5rem; | ||
} | ||
|
||
code { | ||
font-family: Menlo; | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
html { | ||
color-scheme: dark; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Metadata } from "next"; | ||
import { Geist, Geist_Mono } from "next/font/google"; | ||
import "./globals.css"; | ||
|
||
const geistSans = Geist({ | ||
variable: "--font-geist-sans", | ||
subsets: ["latin"], | ||
}); | ||
|
||
const geistMono = Geist_Mono({ | ||
variable: "--font-geist-mono", | ||
subsets: ["latin"], | ||
}); | ||
|
||
export const metadata: Metadata = { | ||
title: "MDX Remote App", | ||
description: "Generated by create next app", | ||
}; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: Readonly<{ | ||
children: React.ReactNode; | ||
}>) { | ||
return ( | ||
<html lang="en"> | ||
<body className={`${geistSans.variable} ${geistMono.variable}`}> | ||
{children} | ||
</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Link from "next/link"; | ||
import { getPosts } from "@/lib/utils"; | ||
|
||
export default function Home() { | ||
const posts = getPosts(); | ||
|
||
return ( | ||
<main> | ||
<h1>Home Page</h1> | ||
<p> | ||
Click the link below to navigate to a page generated by{" "} | ||
<code>next-mdx-remote</code>. | ||
</p> | ||
<ul> | ||
{posts.map((post) => ( | ||
<li key={post.slug}> | ||
<Link href={`/${post.slug}`}>{post.metadata.title}</Link> | ||
</li> | ||
))} | ||
</ul> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
title: Example Post | ||
description: This frontmatter description will appear below the title | ||
--- | ||
|
||
This is an example post, with with a [link](https://nextjs.org) and a React component: | ||
|
||
<Greet name="next-mdx-remote" /> | ||
|
||
Links are rendered using a custom component passed to `next-mdx-remote`. | ||
|
||
Go back [home](/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Hello World | ||
--- | ||
|
||
This is an example post. There's another one [here](/example-post). |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.div { | ||
background-color: #111; | ||
border-radius: 0.5em; | ||
color: #fff; | ||
margin-bottom: 1.5em; | ||
padding: 0.5em 0.75em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import styles from "./greet.module.css"; | ||
|
||
export function Greet({ name = "world" }: { name: string }) { | ||
return <div className={styles.div}>Hello, {name}!</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.a { | ||
color: tomato; | ||
text-decoration-color: rgba(0, 0, 0, 0.4); | ||
} |
Oops, something went wrong.