Update Next.js example to latest create-next-app format (#3881)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Tim Neutkens
2020-03-06 12:46:29 +01:00
committed by GitHub
parent 1bcb95a9f0
commit cc58af74d6
8 changed files with 234 additions and 283 deletions

View File

@@ -1,24 +1,25 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.
# 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
/dist
/.next
# misc
.DS_Store
.env*
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Environment Variables
.env
.env.build
.now

View File

@@ -1,2 +0,0 @@
README.md
yarn.lock

View File

@@ -1,29 +1,30 @@
![Next.js Logo](https://github.com/zeit/now/blob/master/packages/frameworks/logos/next.svg)
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app).
# Next.js Example
## Getting Started
This directory is a brief example of a [Next.js](https://nextjs.org) app that can be deployed with ZEIT Now and zero configuration.
First, run the development server:
## Deploy Your Own
Deploy your own Next.js project with ZEIT Now.
[![Deploy with ZEIT Now](https://zeit.co/button)](https://zeit.co/import/project?template=https://github.com/zeit/now/tree/master/examples/nextjs)
_Live Example: https://nextjs.now-examples.now.sh_
### How We Created This Example
To get started with Next.js deployed with ZEIT Now, you can use [npm create](https://www.npmjs.com/package/create-next-app) to initialize the project:
```shell
$ npm create next-app my-app
```bash
npm run dev
# or
yarn dev
```
### Deploying From Your Terminal
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can deploy your new Next.js project with a single command from your terminal using [Now CLI](https://zeit.co/download):
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
```shell
$ now
```
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/zeit/next.js/) - your feedback and contributions are welcome!
## Deploy on ZEIT Now
The easiest way to deploy your Next.js app is to use the [ZEIT Now Platform](https://zeit.co/import?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

View File

@@ -1,41 +0,0 @@
import React from 'react';
import NextHead from 'next/head';
import { string } from 'prop-types';
const defaultDescription = '';
const defaultOGURL = '';
const defaultOGImage = '';
const Head = props => (
<NextHead>
<meta charSet="UTF-8" />
<title>{props.title || ''}</title>
<meta
name="description"
content={props.description || defaultDescription}
/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
<meta property="og:url" content={props.url || defaultOGURL} />
<meta property="og:title" content={props.title || ''} />
<meta
property="og:description"
content={props.description || defaultDescription}
/>
<meta name="twitter:site" content={props.url || defaultOGURL} />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content={props.ogImage || defaultOGImage} />
<meta property="og:image" content={props.ogImage || defaultOGImage} />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
</NextHead>
);
Head.propTypes = {
title: string,
description: string,
url: string,
ogImage: string,
};
export default Head;

View File

@@ -1,56 +0,0 @@
import React from 'react';
import Link from 'next/link';
const links = [
{ href: 'https://zeit.co/now', label: 'ZEIT' },
{ href: 'https://github.com/zeit/next.js', label: 'GitHub' },
].map(link => {
link.key = `nav-link-${link.href}-${link.label}`;
return link;
});
const Nav = () => (
<nav>
<ul>
<li>
<Link href="/">
<a>Home</a>
</Link>
</li>
{links.map(({ key, href, label }) => (
<li key={key}>
<a href={href}>{label}</a>
</li>
))}
</ul>
<style jsx>{`
:global(body) {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Avenir Next, Avenir,
Helvetica, sans-serif;
}
nav {
text-align: center;
}
ul {
display: flex;
justify-content: space-between;
}
nav > ul {
padding: 4px 16px;
}
li {
display: flex;
padding: 6px 8px;
}
a {
color: #067df7;
text-decoration: none;
font-size: 13px;
}
`}</style>
</nav>
);
export default Nav;

View File

@@ -1,19 +1,15 @@
{
"name": "create-next-example-app",
"description": "A Next.js starter app.",
"repository": {
"type": "git",
"url": "https://github.com/zeit/now/tree/master/examples/nextjs"
},
"license": "MIT",
"name": "nextjs",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next",
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "^9.1.6",
"react": "^16.12.0",
"react-dom": "^16.12.0"
"next": "9.2.2",
"react": "16.13.0",
"react-dom": "16.13.0"
}
}

View File

@@ -1,8 +0,0 @@
export default (req, res) => {
const date = new Date()
.toISOString()
.replace(/T/, ' ')
.replace(/\..+/, '');
res.json({ date });
};

View File

@@ -1,143 +1,203 @@
import React, { useEffect, useState } from 'react';
import Link from 'next/link';
import Head from '../components/head';
import Nav from '../components/nav';
import Head from 'next/head'
const Home = () => {
const [date, setDate] = useState(null);
const Home = () => (
<div className="container">
<Head>
<title>Create Next App</title>
<link rel="icon" href="/favicon.ico" />
</Head>
useEffect(() => {
async function getDate() {
const res = await fetch('/api/date');
const newDate = await res.json();
setDate(newDate);
}
getDate();
}, []);
<main>
<h1 className="title">
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>
return (
<div>
<Head title="Home" />
<Nav />
<p className="description">
Get started by editing <code>pages/index.js</code>
</p>
<div className="hero">
<h1 className="title">Welcome to Next!</h1>
<p className="description">
To get started, edit the <code>pages/index.js</code> or{' '}
<code>pages/api/date.js</code> files, then save to reload.
</p>
<div className="grid">
<a href="https://nextjs.org/docs" className="card">
<h3>Documentation &rarr;</h3>
<p>Find in-depth information about Next.js features and API.</p>
</a>
<p className="row date">
The date is:&nbsp;{' '}
{date ? (
<span>
<b>{date.date}</b>
</span>
) : (
<span className="loading"></span>
)}
</p>
<a href="https://nextjs.org/learn" className="card">
<h3>Learn &rarr;</h3>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>
<div className="row">
<Link href="https://github.com/zeit/next.js#setup">
<a className="card">
<h3>Getting Started &rarr;</h3>
<p>Learn more about Next.js on GitHub and in their examples.</p>
</a>
</Link>
<Link href="https://github.com/zeit/next.js/tree/master/examples">
<a className="card">
<h3>Examples &rarr;</h3>
<p>Find other example boilerplates on the Next.js GitHub.</p>
</a>
</Link>
<Link href="https://github.com/zeit/next.js">
<a className="card">
<h3>Create Next App &rarr;</h3>
<p>Was this tool helpful? Let us know how we can improve it!</p>
</a>
</Link>
</div>
<a
href="https://github.com/zeit/next.js/tree/master/examples"
className="card"
>
<h3>Examples &rarr;</h3>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>
<a
href="https://zeit.co/new?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className="card"
>
<h3>Deploy &rarr;</h3>
<p>
Instantly deploy your Next.js site to a public URL with ZEIT Now.
</p>
</a>
</div>
</main>
<style jsx>{`
.hero {
width: 100%;
color: #333;
}
.title {
margin: 0;
width: 100%;
padding-top: 80px;
line-height: 1.15;
font-size: 48px;
}
.title,
.description {
text-align: center;
}
.row {
max-width: 880px;
margin: 80px auto 40px;
display: flex;
flex-direction: row;
justify-content: space-around;
}
.date {
height: 24px;
max-width: calc(100% - 32px)
text-align: center;
display: flex;
align-items: center;
justify-content: center;
padding: 0 16px;
}
.date p {
text-align: center;
}
.date span {
width: 176px;
text-align: center;
}
@keyframes Loading {
0%{background-position:0% 50%}
50%{background-position:100% 50%}
100%{background-position:0% 50%}
}
.date .loading {
max-width: 100%;
height: 24px;
border-radius: 4px;
display: inline-block;
background: linear-gradient(270deg, #D1D1D1, #EAEAEA);
background-size: 200% 200%;
animation: Loading 2s ease infinite;
}
.card {
padding: 18px 18px 24px;
width: 220px;
text-align: left;
text-decoration: none;
color: #434343;
border: 1px solid #9b9b9b;
}
.card:hover {
border-color: #067df7;
}
.card h3 {
margin: 0;
color: #067df7;
font-size: 18px;
}
.card p {
margin: 0;
padding: 12px 0 0;
font-size: 13px;
color: #333;
}
`}</style>
</div>
);
};
<footer>
<a
href="https://zeit.co?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by <img src="/zeit.svg" alt="ZEIT Logo" />
</a>
</footer>
export default Home;
<style jsx>{`
.container {
min-height: 100vh;
padding: 0 0.5rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
main {
padding: 5rem 0;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
footer {
width: 100%;
height: 100px;
border-top: 1px solid #eaeaea;
display: flex;
justify-content: center;
align-items: center;
}
footer img {
margin-left: 0.5rem;
}
footer a {
display: flex;
justify-content: center;
align-items: center;
}
a {
color: inherit;
text-decoration: none;
}
.title a {
color: #0070f3;
text-decoration: none;
}
.title a:hover,
.title a:focus,
.title a:active {
text-decoration: underline;
}
.title {
margin: 0;
line-height: 1.15;
font-size: 4rem;
}
.title,
.description {
text-align: center;
}
.description {
line-height: 1.5;
font-size: 1.5rem;
}
code {
background: #fafafa;
border-radius: 5px;
padding: 0.75rem;
font-size: 1.1rem;
font-family: Menlo, Monaco, Lucida Console, Liberation Mono,
DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace;
}
.grid {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
max-width: 800px;
margin-top: 3rem;
}
.card {
margin: 1rem;
flex-basis: 45%;
padding: 1.5rem;
text-align: left;
color: inherit;
text-decoration: none;
border: 1px solid #eaeaea;
border-radius: 10px;
transition: color 0.15s ease, border-color 0.15s ease;
}
.card:hover,
.card:focus,
.card:active {
color: #0070f3;
border-color: #0070f3;
}
.card h3 {
margin: 0 0 1rem 0;
font-size: 1.5rem;
}
.card p {
margin: 0;
font-size: 1.25rem;
line-height: 1.5;
}
@media (max-width: 600px) {
.grid {
width: 100%;
flex-direction: column;
}
}
`}</style>
<style jsx global>{`
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;
}
* {
box-sizing: border-box;
}
`}</style>
</div>
)
export default Home