This Repo required for Asac labs class 2
npx create-next-app nextjs-blog --use-npm --example "https://github.com/vercel/next-learn-starter/tree/master/dynamic-routes-starter"
public/images/profile.jpg
with your photo (Recommended: 400px width/height).const name = '[Your Name]'
in components/layout.js with your name.<p>[Your Self Introduction]</p>
in pages/index.js with your self introduction.we’ll import the getAllPostIds function and use it inside getStaticPaths.
import { getAllPostIds } from '../../lib/posts'
export async function getStaticPaths() {
const paths = getAllPostIds()
return {
paths,
fallback: false
}
}
To render markdown content, we’ll use the remark library. First, let’s install it:
npm install remark remark-html
Then, open lib/posts.js and add the following imports to the top of the file:
import remark from 'remark'
import html from 'remark-html'
And update the getPostData() function in the same file as follows to use remark:
In pages/posts/[id].js, let’s add the title tag using the post data. You’ll need to add an import for next/head at the top of the file and add the title tag by updating the Post component.
To format the date, we’ll use the date-fns library. First, install it:
npm install date-fns
Finally, let’s add some CSS using the file styles/utils.module.css we added before. Open pages/posts/[id].js, then add an import for the CSS file, and replace the Post component with the following code:
// Add this import at the top of the file
import utilStyles from '../../styles/utils.module.css'
export default function Post({ postData }) {
return (
<Layout>
<Head>
<title>{postData.title}</title>
</Head>
<article>
<h1 className={utilStyles.headingXl}>{postData.title}</h1>
<div className={utilStyles.lightText}>
<Date dateString={postData.date} />
</div>
<div dangerouslySetInnerHTML= />
</article>
</Layout>
)
}
Push to GitHub
git remote add origin https://github.com/<username>/nextjs-blog.git
git push -u origin main
Deploy to Vercel
import your project
Vercel automatically detects that you have a Next.js app and chooses optimal build settings for you.