-
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.
- Loading branch information
0 parents
commit 76edacc
Showing
18 changed files
with
2,892 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env* | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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 @@ | ||
This is a starter template for [Learn Next.js](https://nextjs.org/learn). |
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,6 @@ | ||
import { parseISO, format } from 'date-fns' | ||
|
||
export default function Date({ dateString }) { | ||
const date = parseISO(dateString) | ||
return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time> | ||
} |
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,73 @@ | ||
import Head from 'next/head' | ||
import Image from 'next/image' | ||
import styles from './layout.module.css' | ||
import utilStyles from '../styles/utils.module.css' | ||
import Link from 'next/link' | ||
|
||
const name = '[Your Name]' | ||
export const siteTitle = 'Next.js Sample Website' | ||
|
||
export default function Layout({ children, home }) { | ||
return ( | ||
<div className={styles.container}> | ||
<Head> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<meta | ||
name="description" | ||
content="Learn how to build a personal website using Next.js" | ||
/> | ||
<meta | ||
property="og:image" | ||
content={`https://og-image.vercel.app/${encodeURI( | ||
siteTitle | ||
)}.png?theme=light&md=0&fontSize=75px&images=https%3A%2F%2Fassets.zeit.co%2Fimage%2Fupload%2Ffront%2Fassets%2Fdesign%2Fnextjs-black-logo.svg`} | ||
/> | ||
<meta name="og:title" content={siteTitle} /> | ||
<meta name="twitter:card" content="summary_large_image" /> | ||
</Head> | ||
<header className={styles.header}> | ||
{home ? ( | ||
<> | ||
<Image | ||
priority | ||
src="/images/profile.jpg" | ||
className={utilStyles.borderCircle} | ||
height={144} | ||
width={144} | ||
alt={name} | ||
/> | ||
<h1 className={utilStyles.heading2Xl}>{name}</h1> | ||
</> | ||
) : ( | ||
<> | ||
<Link href="/"> | ||
<a> | ||
<Image | ||
priority | ||
src="/images/profile.jpg" | ||
className={utilStyles.borderCircle} | ||
height={108} | ||
width={108} | ||
alt={name} | ||
/> | ||
</a> | ||
</Link> | ||
<h2 className={utilStyles.headingLg}> | ||
<Link href="/"> | ||
<a className={utilStyles.colorInherit}>{name}</a> | ||
</Link> | ||
</h2> | ||
</> | ||
)} | ||
</header> | ||
<main>{children}</main> | ||
{!home && ( | ||
<div className={styles.backToHome}> | ||
<Link href="/"> | ||
<a>← Back to home</a> | ||
</Link> | ||
</div> | ||
)} | ||
</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,15 @@ | ||
.container { | ||
max-width: 36rem; | ||
padding: 0 1rem; | ||
margin: 3rem auto 6rem; | ||
} | ||
|
||
.header { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.backToHome { | ||
margin: 3rem 0 0; | ||
} |
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,69 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import matter from 'gray-matter' | ||
import { remark } from 'remark' | ||
import html from 'remark-html' | ||
|
||
const postsDirectory = path.join(process.cwd(), 'posts') | ||
|
||
export function getSortedPostsData() { | ||
// Get file names under /posts | ||
const fileNames = fs.readdirSync(postsDirectory) | ||
const allPostsData = fileNames.map(fileName => { | ||
// Remove ".md" from file name to get id | ||
const id = fileName.replace(/\.md$/, '') | ||
|
||
// Read markdown file as string | ||
const fullPath = path.join(postsDirectory, fileName) | ||
const fileContents = fs.readFileSync(fullPath, 'utf8') | ||
|
||
// Use gray-matter to parse the post metadata section | ||
const matterResult = matter(fileContents) | ||
|
||
// Combine the data with the id | ||
return { | ||
id, | ||
...matterResult.data | ||
} | ||
}) | ||
// Sort posts by date | ||
return allPostsData.sort((a, b) => { | ||
if (a.date < b.date) { | ||
return 1 | ||
} else { | ||
return -1 | ||
} | ||
}) | ||
} | ||
|
||
export function getAllPostIds() { | ||
const fileNames = fs.readdirSync(postsDirectory) | ||
return fileNames.map(fileName => { | ||
return { | ||
params: { | ||
id: fileName.replace(/\.md$/, '') | ||
} | ||
} | ||
}) | ||
} | ||
|
||
export async function getPostData(id) { | ||
const fullPath = path.join(postsDirectory, `${id}.md`) | ||
const fileContents = fs.readFileSync(fullPath, 'utf8') | ||
|
||
// Use gray-matter to parse the post metadata section | ||
const matterResult = matter(fileContents) | ||
|
||
// Use remark to convert markdown into HTML string | ||
const processedContent = await remark() | ||
.use(html) | ||
.process(matterResult.content) | ||
const contentHtml = processedContent.toString() | ||
|
||
// Combine the data with the id and contentHtml | ||
return { | ||
id, | ||
contentHtml, | ||
...matterResult.data | ||
} | ||
} |
Oops, something went wrong.