diff --git a/.prettierrc b/.prettierrc index fd496a8..dcaa31d 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,4 +1,7 @@ { "singleQuote": true, - "semi": false + "semi": false, + "trailingComma": "none", + "arrowParens": "avoid", + "endOfLine": "auto" } diff --git a/api-routes-starter/pages/index.js b/api-routes-starter/pages/index.js index db94ca6..6a9b7ab 100644 --- a/api-routes-starter/pages/index.js +++ b/api-routes-starter/pages/index.js @@ -11,13 +11,7 @@ const Home = ({ allPostsData }) => ( {siteTitle}
-

- Hello, I’m Shu. I write code at{' '} - ZEIT, the team behind{' '} - Next.js. You can contact me via{' '} - Twitter or{' '} - email. -

+

[Your Self Introduction]

(This is a sample website - you’ll be building a site like this on{' '} our Next.js tutorial.) diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..922d92a --- /dev/null +++ b/example/.gitignore @@ -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* diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..02695bc --- /dev/null +++ b/example/README.md @@ -0,0 +1 @@ +This is a starter template for [Learn Next.js](https://nextjs.org/learn). \ No newline at end of file diff --git a/example/components/Date.js b/example/components/Date.js new file mode 100644 index 0000000..0ec71d3 --- /dev/null +++ b/example/components/Date.js @@ -0,0 +1,6 @@ +import { parseISO, format } from 'date-fns' + +export default function Date({ dateString }) { + const date = parseISO(dateString) + return +} diff --git a/example/components/Layout.js b/example/components/Layout.js new file mode 100644 index 0000000..ab023c3 --- /dev/null +++ b/example/components/Layout.js @@ -0,0 +1,64 @@ +import Head from 'next/head' +import styles from './Layout.module.css' +import utilStyles from '../styles/utils.module.css' +import Link from 'next/link' + +const name = 'Shu Uesugi' +export const siteTitle = 'Next.js Sample Website' + +const Page = ({ children, home }) => ( +

+ + + + + +
+ {home ? ( + <> + {name} +

{name}

+ + ) : ( + <> + + + {name} + + +

+ + {name} + +

+ + )} +
+
{children}
+ {!home && ( +
+ + ← Back to home + +
+ )} +
+) + +export default Page diff --git a/example/components/Layout.module.css b/example/components/Layout.module.css new file mode 100644 index 0000000..d0e3a8f --- /dev/null +++ b/example/components/Layout.module.css @@ -0,0 +1,25 @@ +.container { + max-width: 36rem; + padding: 0 1rem; + margin: 3rem auto 6rem; +} + +.header { + display: flex; + flex-direction: column; + align-items: center; +} + +.headerImage { + width: 6rem; + height: 6rem; +} + +.headerHomeImage { + width: 8rem; + height: 8rem; +} + +.backToHome { + margin: 3rem 0 0; +} diff --git a/example/lib/posts.js b/example/lib/posts.js new file mode 100644 index 0000000..db08438 --- /dev/null +++ b/example/lib/posts.js @@ -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 { data } = matter(fileContents) + + // Combine the data with the id + return { + id, + ...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 { data, content } = matter(fileContents) + + // Use remark to convert markdown into HTML string + const processedContent = await remark() + .use(html) + .process(content) + const contentHtml = processedContent.toString() + + // Combine the data with the id and contentHtml + return { + id, + contentHtml, + ...data + } +} diff --git a/example/package.json b/example/package.json new file mode 100644 index 0000000..8cd5529 --- /dev/null +++ b/example/package.json @@ -0,0 +1,19 @@ +{ + "name": "my-app", + "version": "0.1.0", + "private": true, + "scripts": { + "dev": "next dev", + "build": "next build", + "start": "next start" + }, + "dependencies": { + "date-fns": "^2.11.1", + "gray-matter": "^4.0.2", + "next": "9.3.1", + "react": "16.13.1", + "react-dom": "16.13.1", + "remark": "^12.0.0", + "remark-html": "^11.0.1" + } +} diff --git a/example/pages/_app.js b/example/pages/_app.js new file mode 100644 index 0000000..4fd261f --- /dev/null +++ b/example/pages/_app.js @@ -0,0 +1,5 @@ +import '../styles/global.css' + +const App = ({ Component, pageProps }) => + +export default App diff --git a/example/pages/api/hello.js b/example/pages/api/hello.js new file mode 100644 index 0000000..2e22ab3 --- /dev/null +++ b/example/pages/api/hello.js @@ -0,0 +1,3 @@ +export default (req, res) => { + res.status(200).json({ text: 'Hello' }) +} diff --git a/example/pages/index.js b/example/pages/index.js new file mode 100644 index 0000000..db94ca6 --- /dev/null +++ b/example/pages/index.js @@ -0,0 +1,54 @@ +import Head from 'next/head' +import Layout, { siteTitle } from '../components/Layout' +import utilStyles from '../styles/utils.module.css' +import { getSortedPostsData } from '../lib/posts' +import Link from 'next/link' +import Date from '../components/Date' + +const Home = ({ allPostsData }) => ( + + + {siteTitle} + +
+

+ Hello, I’m Shu. I write code at{' '} + ZEIT, the team behind{' '} + Next.js. You can contact me via{' '} + Twitter or{' '} + email. +

+

+ (This is a sample website - you’ll be building a site like this on{' '} + our Next.js tutorial.) +

+
+
+

Blog

+
    + {allPostsData.map(({ id, date, title }) => ( +
  • + + {title} + +
    + + + +
  • + ))} +
+
+
+) + +export async function getStaticProps() { + const allPostsData = getSortedPostsData() + return { + props: { + allPostsData + } + } +} + +export default Home diff --git a/example/pages/posts/[id].js b/example/pages/posts/[id].js new file mode 100644 index 0000000..cafc88f --- /dev/null +++ b/example/pages/posts/[id].js @@ -0,0 +1,39 @@ +import Layout from '../../components/Layout' +import { getAllPostIds, getPostData } from '../../lib/posts' +import Head from 'next/head' +import Date from '../../components/Date' +import utilStyles from '../../styles/utils.module.css' + +const Post = ({ postData }) => ( + + + {postData.title} + +
+

{postData.title}

+
+ +
+
+
+
+) + +export async function getStaticPaths() { + const paths = getAllPostIds() + return { + paths, + fallback: false + } +} + +export async function getStaticProps({ params }) { + const postData = await getPostData(params.id) + return { + props: { + postData + } + } +} + +export default Post diff --git a/example/posts/dps.md b/example/posts/dps.md new file mode 100644 index 0000000..878a33d --- /dev/null +++ b/example/posts/dps.md @@ -0,0 +1,12 @@ +--- +title: "DPS: Develop, Preview, Ship" +date: "2020-01-02" +--- + +[ZEIT Now](https://zeit.co/) supports the **DPS** workflow: **D**evelop, **P**review, and **S**hip: + +- **Develop**: Write code in Next.js. Keep the development server running and take advantage of its hot code reloading feature. +- **Preview**: Every time you push changes to a branch on GitHub / GitLab / BitBucket, ZEIT Now automatically creates a new deployment with a unique URL. +- **Ship**: When you’re ready to ship, merge the pull request to your default branch (e.g. `master`). ZEIT Now will automatically create a production deployment. + +By using the DPS workflow, in addition to doing code reviews, you can do *deployment previews*. Each deployment creates a unique URL that can be shared or used for integration tests. \ No newline at end of file diff --git a/example/posts/pre-rendering.md b/example/posts/pre-rendering.md new file mode 100644 index 0000000..78cc081 --- /dev/null +++ b/example/posts/pre-rendering.md @@ -0,0 +1,11 @@ +--- +title: "Two Forms of Pre-rendering" +date: "2020-01-01" +--- + +[Next.js](https://nextjs.org/) has two forms of pre-rendering: **Static Generation** and **Server-side Rendering**. The difference is in **when** it generates the HTML for a page. + +- **Static Generation (Recommended)**: The HTML is generated at **build time** and will be reused on each request. +- **Server-side Rendering**: The HTML is generated on **each request**. + +Importantly, Next.js lets you **choose** which pre-rendering form you'd like to use for each page. You can create a "hybrid" Next.js app by using Static Generation for most pages and using Server-side Rendering for others. \ No newline at end of file diff --git a/example/public/favicon.ico b/example/public/favicon.ico new file mode 100644 index 0000000..4965832 Binary files /dev/null and b/example/public/favicon.ico differ diff --git a/example/public/images/profile.jpg b/example/public/images/profile.jpg new file mode 100644 index 0000000..928d903 Binary files /dev/null and b/example/public/images/profile.jpg differ diff --git a/example/styles/global.css b/example/styles/global.css new file mode 100644 index 0000000..9e1b0fb --- /dev/null +++ b/example/styles/global.css @@ -0,0 +1,27 @@ +html, +body { + padding: 0; + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, + Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; + line-height: 1.6; + font-size: 18px; +} + +* { + box-sizing: border-box; +} + +a { + color: #0070f3; + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + +img { + max-width: 100%; + display: block; +} diff --git a/example/styles/utils.module.css b/example/styles/utils.module.css new file mode 100644 index 0000000..46a77f3 --- /dev/null +++ b/example/styles/utils.module.css @@ -0,0 +1,52 @@ +.heading2Xl { + font-size: 2.5rem; + line-height: 1.2; + font-weight: 800; + letter-spacing: -0.05rem; + margin: 1rem 0; +} + +.headingXl { + font-size: 2rem; + line-height: 1.3; + font-weight: 800; + letter-spacing: -0.05rem; + margin: 1rem 0; +} + +.headingLg { + font-size: 1.5rem; + line-height: 1.4; + margin: 1rem 0; +} + +.headingMd { + font-size: 1.2rem; + line-height: 1.5; +} + +.borderCircle { + border-radius: 9999px; +} + +.colorInherit { + color: inherit; +} + +.padding1px { + padding-top: 1px; +} + +.list { + list-style: none; + padding: 0; + margin: 0; +} + +.listItem { + margin: 0 0 1.25rem; +} + +.lightText { + color: #999; +}