Moves prettier and lint to root of the project (#143)

This commit is contained in:
Michael Novotny
2023-09-06 12:57:56 -05:00
committed by GitHub
parent a657dd215b
commit 1725e58866
135 changed files with 6730 additions and 765 deletions

10
.eslintrc.js Normal file
View File

@@ -0,0 +1,10 @@
module.exports = {
extends: ['next/core-web-vitals', 'prettier'],
ignorePatterns: ['**/.next/**', '**/node_modules/**'],
root: true,
settings: {
next: {
rootDir: ['basics/*/', 'dashboard/*/', 'seo/'],
},
},
};

6
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'weekly'

30
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: test
on: pull_request
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Cancel running workflows
uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ github.token }}
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup pnpm
uses: pnpm/action-setup@v2
- name: Set node version
uses: actions/setup-node@v3
with:
cache: 'pnpm'
node-version-file: '.nvmrc'
- name: Cache node_modules
id: node-modules-cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: node-modules-cache-${{ hashFiles('**/pnpm-lock.yaml') }}
- name: Install dependencies
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: pnpm install
- name: Run tests
run: pnpm test

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.log
.DS_Store
node_modules

4
.prettierignore Normal file
View File

@@ -0,0 +1,4 @@
**/.next
**/node_modules
**/package-lock.json
**/pnpm-lock.yaml

5
basics/.gitignore vendored
View File

@@ -1,5 +0,0 @@
.next
node_modules
*.log
yarn.lock
package-lock.json

View File

@@ -1,2 +0,0 @@
.next
node_modules

View File

@@ -1,7 +0,0 @@
{
"singleQuote": true,
"semi": false,
"trailingComma": "none",
"arrowParens": "avoid",
"endOfLine": "auto"
}

View File

@@ -1 +1 @@
This is a starter template for [Learn Next.js](https://nextjs.org/learn). This is a starter template for [Learn Next.js](https://nextjs.org/learn).

View File

@@ -1,6 +1,6 @@
import { parseISO, format } from 'date-fns' import { parseISO, format } from 'date-fns';
export default function Date({ dateString }) { export default function Date({ dateString }) {
const date = parseISO(dateString) const date = parseISO(dateString);
return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time> return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time>;
} }

View File

@@ -1,11 +1,11 @@
import Head from 'next/head' import Head from 'next/head';
import Image from 'next/image' import Image from 'next/image';
import styles from './layout.module.css' import styles from './layout.module.css';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import Link from 'next/link' import Link from 'next/link';
const name = '[Your Name]' const name = '[Your Name]';
export const siteTitle = 'Next.js Sample Website' export const siteTitle = 'Next.js Sample Website';
export default function Layout({ children, home }) { export default function Layout({ children, home }) {
return ( return (
@@ -19,7 +19,7 @@ export default function Layout({ children, home }) {
<meta <meta
property="og:image" property="og:image"
content={`https://og-image.vercel.app/${encodeURI( content={`https://og-image.vercel.app/${encodeURI(
siteTitle siteTitle,
)}.png?theme=light&md=0&fontSize=75px&images=https%3A%2F%2Fassets.zeit.co%2Fimage%2Fupload%2Ffront%2Fassets%2Fdesign%2Fnextjs-black-logo.svg`} )}.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="og:title" content={siteTitle} />
@@ -65,5 +65,5 @@ export default function Layout({ children, home }) {
</div> </div>
)} )}
</div> </div>
) );
} }

View File

@@ -1,69 +1,69 @@
import fs from 'fs' import fs from 'fs';
import path from 'path' import path from 'path';
import matter from 'gray-matter' import matter from 'gray-matter';
import { remark } from 'remark' import { remark } from 'remark';
import html from 'remark-html' import html from 'remark-html';
const postsDirectory = path.join(process.cwd(), 'posts') const postsDirectory = path.join(process.cwd(), 'posts');
export function getSortedPostsData() { export function getSortedPostsData() {
// Get file names under /posts // Get file names under /posts
const fileNames = fs.readdirSync(postsDirectory) const fileNames = fs.readdirSync(postsDirectory);
const allPostsData = fileNames.map(fileName => { const allPostsData = fileNames.map((fileName) => {
// Remove ".md" from file name to get id // Remove ".md" from file name to get id
const id = fileName.replace(/\.md$/, '') const id = fileName.replace(/\.md$/, '');
// Read markdown file as string // Read markdown file as string
const fullPath = path.join(postsDirectory, fileName) const fullPath = path.join(postsDirectory, fileName);
const fileContents = fs.readFileSync(fullPath, 'utf8') const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the post metadata section // Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents) const matterResult = matter(fileContents);
// Combine the data with the id // Combine the data with the id
return { return {
id, id,
...matterResult.data ...matterResult.data,
} };
}) });
// Sort posts by date // Sort posts by date
return allPostsData.sort((a, b) => { return allPostsData.sort((a, b) => {
if (a.date < b.date) { if (a.date < b.date) {
return 1 return 1;
} else { } else {
return -1 return -1;
} }
}) });
} }
export function getAllPostIds() { export function getAllPostIds() {
const fileNames = fs.readdirSync(postsDirectory) const fileNames = fs.readdirSync(postsDirectory);
return fileNames.map(fileName => { return fileNames.map((fileName) => {
return { return {
params: { params: {
id: fileName.replace(/\.md$/, '') id: fileName.replace(/\.md$/, ''),
} },
} };
}) });
} }
export async function getPostData(id) { export async function getPostData(id) {
const fullPath = path.join(postsDirectory, `${id}.md`) const fullPath = path.join(postsDirectory, `${id}.md`);
const fileContents = fs.readFileSync(fullPath, 'utf8') const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the post metadata section // Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents) const matterResult = matter(fileContents);
// Use remark to convert markdown into HTML string // Use remark to convert markdown into HTML string
const processedContent = await remark() const processedContent = await remark()
.use(html) .use(html)
.process(matterResult.content) .process(matterResult.content);
const contentHtml = processedContent.toString() const contentHtml = processedContent.toString();
// Combine the data with the id and contentHtml // Combine the data with the id and contentHtml
return { return {
id, id,
contentHtml, contentHtml,
...matterResult.data ...matterResult.data,
} };
} }

View File

@@ -1,11 +1,8 @@
{ {
"private": true, "private": true,
"engines": {
"node": ">=18"
},
"scripts": { "scripts": {
"dev": "next dev",
"build": "next build", "build": "next build",
"dev": "next dev",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
@@ -16,5 +13,8 @@
"react-dom": "18.2.0", "react-dom": "18.2.0",
"remark": "^14.0.2", "remark": "^14.0.2",
"remark-html": "^15.0.1" "remark-html": "^15.0.1"
},
"engines": {
"node": ">=18"
} }
} }

View File

@@ -1,5 +1,5 @@
import '../styles/global.css' import '../styles/global.css';
export default function App({ Component, pageProps }) { export default function App({ Component, pageProps }) {
return <Component {...pageProps} /> return <Component {...pageProps} />;
} }

View File

@@ -1,9 +1,9 @@
import Head from 'next/head' import Head from 'next/head';
import Layout, { siteTitle } from '../components/layout' import Layout, { siteTitle } from '../components/layout';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import { getSortedPostsData } from '../lib/posts' import { getSortedPostsData } from '../lib/posts';
import Link from 'next/link' import Link from 'next/link';
import Date from '../components/date' import Date from '../components/date';
export default function Home({ allPostsData }) { export default function Home({ allPostsData }) {
return ( return (
@@ -33,14 +33,14 @@ export default function Home({ allPostsData }) {
</ul> </ul>
</section> </section>
</Layout> </Layout>
) );
} }
export async function getStaticProps() { export async function getStaticProps() {
const allPostsData = getSortedPostsData() const allPostsData = getSortedPostsData();
return { return {
props: { props: {
allPostsData allPostsData,
} },
} };
} }

View File

@@ -1,8 +1,8 @@
import Layout from '../../components/layout' import Layout from '../../components/layout';
import { getAllPostIds, getPostData } from '../../lib/posts' import { getAllPostIds, getPostData } from '../../lib/posts';
import Head from 'next/head' import Head from 'next/head';
import Date from '../../components/date' import Date from '../../components/date';
import utilStyles from '../../styles/utils.module.css' import utilStyles from '../../styles/utils.module.css';
export default function Post({ postData }) { export default function Post({ postData }) {
return ( return (
@@ -18,22 +18,22 @@ export default function Post({ postData }) {
<div dangerouslySetInnerHTML={{ __html: postData.contentHtml }} /> <div dangerouslySetInnerHTML={{ __html: postData.contentHtml }} />
</article> </article>
</Layout> </Layout>
) );
} }
export async function getStaticPaths() { export async function getStaticPaths() {
const paths = getAllPostIds() const paths = getAllPostIds();
return { return {
paths, paths,
fallback: false fallback: false,
} };
} }
export async function getStaticProps({ params }) { export async function getStaticProps({ params }) {
const postData = await getPostData(params.id) const postData = await getPostData(params.id);
return { return {
props: { props: {
postData postData,
} },
} };
} }

View File

@@ -2,8 +2,18 @@ html,
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, font-family:
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; -apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif;
line-height: 1.6; line-height: 1.6;
font-size: 18px; font-size: 18px;
} }

View File

@@ -1 +1 @@
This is a starter template for [Learn Next.js](https://nextjs.org/learn). This is a starter template for [Learn Next.js](https://nextjs.org/learn).

View File

@@ -1,16 +1,16 @@
{ {
"private": true, "private": true,
"engines": {
"node": ">=18"
},
"scripts": { "scripts": {
"dev": "next dev",
"build": "next build", "build": "next build",
"dev": "next dev",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"next": "latest", "next": "latest",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0" "react-dom": "18.2.0"
},
"engines": {
"node": ">=18"
} }
} }

View File

@@ -1,5 +1,5 @@
import Link from 'next/link'; import Link from 'next/link';
import Head from 'next/head' import Head from 'next/head';
import styles from '../styles/Home.module.css'; import styles from '../styles/Home.module.css';
export default function Home() { export default function Home() {
@@ -12,7 +12,7 @@ export default function Home() {
<main> <main>
<h1 className={styles.title}> <h1 className={styles.title}>
Read <Link href='/posts/first-post'>this page!</Link> Read <Link href="/posts/first-post">this page!</Link>
</h1> </h1>
<p className={styles.description}> <p className={styles.description}>
@@ -93,8 +93,15 @@ export default function Home() {
border-radius: 5px; border-radius: 5px;
padding: 0.75rem; padding: 0.75rem;
font-size: 1.1rem; font-size: 1.1rem;
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, font-family:
DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace; Menlo,
Monaco,
Lucida Console,
Liberation Mono,
DejaVu Sans Mono,
Bitstream Vera Sans Mono,
Courier New,
monospace;
} }
`}</style> `}</style>
@@ -103,8 +110,17 @@ export default function Home() {
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, font-family:
Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, -apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif; sans-serif;
} }
* { * {
@@ -112,5 +128,5 @@ export default function Home() {
} }
`}</style> `}</style>
</div> </div>
) );
} }

View File

@@ -1,4 +1,4 @@
import Link from 'next/link' import Link from 'next/link';
export default function FirstPost() { export default function FirstPost() {
return ( return (
@@ -8,5 +8,5 @@ export default function FirstPost() {
<Link href="/">Back to home</Link> <Link href="/">Back to home</Link>
</h2> </h2>
</> </>
) );
} }

View File

@@ -33,7 +33,6 @@
text-align: center; text-align: center;
} }
.description { .description {
line-height: 1.5; line-height: 1.5;
font-size: 1.5rem; font-size: 1.5rem;
@@ -58,7 +57,9 @@
text-decoration: none; text-decoration: none;
border: 1px solid #eaeaea; border: 1px solid #eaeaea;
border-radius: 10px; border-radius: 10px;
transition: color 0.15s ease, border-color 0.15s ease; transition:
color 0.15s ease,
border-color 0.15s ease;
} }
.card:hover, .card:hover,

View File

@@ -2,8 +2,19 @@ html,
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: Inter, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, font-family:
Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; Inter,
-apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif;
} }
a { a {

View File

@@ -1 +1 @@
This is a starter template for [Learn Next.js](https://nextjs.org/learn). This is a starter template for [Learn Next.js](https://nextjs.org/learn).

View File

@@ -1,6 +1,6 @@
import { parseISO, format } from 'date-fns' import { parseISO, format } from 'date-fns';
export default function Date({ dateString }) { export default function Date({ dateString }) {
const date = parseISO(dateString) const date = parseISO(dateString);
return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time> return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time>;
} }

View File

@@ -1,13 +1,13 @@
import Head from 'next/head' import Head from 'next/head';
import Image from 'next/image' import Image from 'next/image';
import Script from 'next/script' import Script from 'next/script';
import styles from './layout.module.css' import styles from './layout.module.css';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import Link from 'next/link' import Link from 'next/link';
const name = '[Your Name]' const name = '[Your Name]';
export const siteTitle = 'Next.js Sample Website' export const siteTitle = 'Next.js Sample Website';
export default function Layout({ children, home }) { export default function Layout({ children, home }) {
return ( return (
@@ -21,7 +21,7 @@ export default function Layout({ children, home }) {
<meta <meta
property="og:image" property="og:image"
content={`https://og-image.vercel.app/${encodeURI( content={`https://og-image.vercel.app/${encodeURI(
siteTitle siteTitle,
)}.png?theme=light&md=0&fontSize=75px&images=https%3A%2F%2Fassets.zeit.co%2Fimage%2Fupload%2Ffront%2Fassets%2Fdesign%2Fnextjs-black-logo.svg`} )}.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="og:title" content={siteTitle} />
@@ -74,5 +74,5 @@ export default function Layout({ children, home }) {
</div> </div>
)} )}
</div> </div>
) );
} }

View File

@@ -1,69 +1,69 @@
import fs from 'fs' import fs from 'fs';
import path from 'path' import path from 'path';
import matter from 'gray-matter' import matter from 'gray-matter';
import { remark } from 'remark' import { remark } from 'remark';
import html from 'remark-html' import html from 'remark-html';
const postsDirectory = path.join(process.cwd(), 'posts') const postsDirectory = path.join(process.cwd(), 'posts');
export function getSortedPostsData() { export function getSortedPostsData() {
// Get file names under /posts // Get file names under /posts
const fileNames = fs.readdirSync(postsDirectory) const fileNames = fs.readdirSync(postsDirectory);
const allPostsData = fileNames.map(fileName => { const allPostsData = fileNames.map((fileName) => {
// Remove ".md" from file name to get id // Remove ".md" from file name to get id
const id = fileName.replace(/\.md$/, '') const id = fileName.replace(/\.md$/, '');
// Read markdown file as string // Read markdown file as string
const fullPath = path.join(postsDirectory, fileName) const fullPath = path.join(postsDirectory, fileName);
const fileContents = fs.readFileSync(fullPath, 'utf8') const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the post metadata section // Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents) const matterResult = matter(fileContents);
// Combine the data with the id // Combine the data with the id
return { return {
id, id,
...matterResult.data ...matterResult.data,
} };
}) });
// Sort posts by date // Sort posts by date
return allPostsData.sort((a, b) => { return allPostsData.sort((a, b) => {
if (a.date < b.date) { if (a.date < b.date) {
return 1 return 1;
} else { } else {
return -1 return -1;
} }
}) });
} }
export function getAllPostIds() { export function getAllPostIds() {
const fileNames = fs.readdirSync(postsDirectory) const fileNames = fs.readdirSync(postsDirectory);
return fileNames.map(fileName => { return fileNames.map((fileName) => {
return { return {
params: { params: {
id: fileName.replace(/\.md$/, '') id: fileName.replace(/\.md$/, ''),
} },
} };
}) });
} }
export async function getPostData(id) { export async function getPostData(id) {
const fullPath = path.join(postsDirectory, `${id}.md`) const fullPath = path.join(postsDirectory, `${id}.md`);
const fileContents = fs.readFileSync(fullPath, 'utf8') const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the post metadata section // Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents) const matterResult = matter(fileContents);
// Use remark to convert markdown into HTML string // Use remark to convert markdown into HTML string
const processedContent = await remark() const processedContent = await remark()
.use(html) .use(html)
.process(matterResult.content) .process(matterResult.content);
const contentHtml = processedContent.toString() const contentHtml = processedContent.toString();
// Combine the data with the id and contentHtml // Combine the data with the id and contentHtml
return { return {
id, id,
contentHtml, contentHtml,
...matterResult.data ...matterResult.data,
} };
} }

View File

@@ -1,11 +1,8 @@
{ {
"private": true, "private": true,
"engines": {
"node": ">=18"
},
"scripts": { "scripts": {
"dev": "next dev",
"build": "next build", "build": "next build",
"dev": "next dev",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
@@ -16,5 +13,8 @@
"react-dom": "18.2.0", "react-dom": "18.2.0",
"remark": "^14.0.2", "remark": "^14.0.2",
"remark-html": "^15.0.1" "remark-html": "^15.0.1"
},
"engines": {
"node": ">=18"
} }
} }

View File

@@ -1,5 +1,5 @@
import '../styles/global.css' import '../styles/global.css';
export default function App({ Component, pageProps }) { export default function App({ Component, pageProps }) {
return <Component {...pageProps} /> return <Component {...pageProps} />;
} }

View File

@@ -1,3 +1,3 @@
export default (req, res) => { export default (req, res) => {
res.status(200).json({ text: 'Hello' }) res.status(200).json({ text: 'Hello' });
} };

View File

@@ -1,9 +1,9 @@
import Head from 'next/head' import Head from 'next/head';
import Layout, { siteTitle } from '../components/layout' import Layout, { siteTitle } from '../components/layout';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import { getSortedPostsData } from '../lib/posts' import { getSortedPostsData } from '../lib/posts';
import Link from 'next/link' import Link from 'next/link';
import Date from '../components/date' import Date from '../components/date';
export default function Home({ allPostsData }) { export default function Home({ allPostsData }) {
return ( return (
@@ -33,14 +33,14 @@ export default function Home({ allPostsData }) {
</ul> </ul>
</section> </section>
</Layout> </Layout>
) );
} }
export async function getStaticProps() { export async function getStaticProps() {
const allPostsData = getSortedPostsData() const allPostsData = getSortedPostsData();
return { return {
props: { props: {
allPostsData allPostsData,
} },
} };
} }

View File

@@ -1,8 +1,8 @@
import Layout from '../../components/layout' import Layout from '../../components/layout';
import { getAllPostIds, getPostData } from '../../lib/posts' import { getAllPostIds, getPostData } from '../../lib/posts';
import Head from 'next/head' import Head from 'next/head';
import Date from '../../components/date' import Date from '../../components/date';
import utilStyles from '../../styles/utils.module.css' import utilStyles from '../../styles/utils.module.css';
export default function Post({ postData }) { export default function Post({ postData }) {
return ( return (
@@ -18,22 +18,22 @@ export default function Post({ postData }) {
<div dangerouslySetInnerHTML={{ __html: postData.contentHtml }} /> <div dangerouslySetInnerHTML={{ __html: postData.contentHtml }} />
</article> </article>
</Layout> </Layout>
) );
} }
export async function getStaticPaths() { export async function getStaticPaths() {
const paths = getAllPostIds() const paths = getAllPostIds();
return { return {
paths, paths,
fallback: false fallback: false,
} };
} }
export async function getStaticProps({ params }) { export async function getStaticProps({ params }) {
const postData = await getPostData(params.id) const postData = await getPostData(params.id);
return { return {
props: { props: {
postData postData,
} },
} };
} }

View File

@@ -2,8 +2,18 @@ html,
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, font-family:
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; -apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif;
line-height: 1.6; line-height: 1.6;
font-size: 18px; font-size: 18px;
} }

View File

@@ -1 +1 @@
This is a starter template for [Learn Next.js](https://nextjs.org/learn). This is a starter template for [Learn Next.js](https://nextjs.org/learn).

View File

@@ -1,11 +1,11 @@
import Head from 'next/head' import Head from 'next/head';
import Image from 'next/image' import Image from 'next/image';
import styles from './layout.module.css' import styles from './layout.module.css';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import Link from 'next/link' import Link from 'next/link';
const name = '[Your Name]' const name = '[Your Name]';
export const siteTitle = 'Next.js Sample Website' export const siteTitle = 'Next.js Sample Website';
export default function Layout({ children, home }) { export default function Layout({ children, home }) {
return ( return (
@@ -19,7 +19,7 @@ export default function Layout({ children, home }) {
<meta <meta
property="og:image" property="og:image"
content={`https://og-image.vercel.app/${encodeURI( content={`https://og-image.vercel.app/${encodeURI(
siteTitle siteTitle,
)}.png?theme=light&md=0&fontSize=75px&images=https%3A%2F%2Fassets.zeit.co%2Fimage%2Fupload%2Ffront%2Fassets%2Fdesign%2Fnextjs-black-logo.svg`} )}.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="og:title" content={siteTitle} />
@@ -65,5 +65,5 @@ export default function Layout({ children, home }) {
</div> </div>
)} )}
</div> </div>
) );
} }

View File

@@ -1,16 +1,16 @@
{ {
"private": true, "private": true,
"engines": {
"node": ">=18"
},
"scripts": { "scripts": {
"dev": "next dev",
"build": "next build", "build": "next build",
"dev": "next dev",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"next": "latest", "next": "latest",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0" "react-dom": "18.2.0"
},
"engines": {
"node": ">=18"
} }
} }

View File

@@ -1,5 +1,5 @@
import '../styles/global.css' import '../styles/global.css';
export default function App({ Component, pageProps }) { export default function App({ Component, pageProps }) {
return <Component {...pageProps} /> return <Component {...pageProps} />;
} }

View File

@@ -1,6 +1,6 @@
import Head from 'next/head' import Head from 'next/head';
import Layout, { siteTitle } from '../components/layout' import Layout, { siteTitle } from '../components/layout';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
export default function Home() { export default function Home() {
return ( return (
@@ -16,5 +16,5 @@ export default function Home() {
</p> </p>
</section> </section>
</Layout> </Layout>
) );
} }

View File

@@ -1,6 +1,6 @@
import Head from 'next/head' import Head from 'next/head';
import Link from 'next/link' import Link from 'next/link';
import Layout from '../../components/layout' import Layout from '../../components/layout';
export default function FirstPost() { export default function FirstPost() {
return ( return (
@@ -13,5 +13,5 @@ export default function FirstPost() {
<Link href="/">Back to home</Link> <Link href="/">Back to home</Link>
</h2> </h2>
</Layout> </Layout>
) );
} }

View File

@@ -2,8 +2,18 @@ html,
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, font-family:
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; -apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif;
line-height: 1.6; line-height: 1.6;
font-size: 18px; font-size: 18px;
} }

View File

@@ -1 +1 @@
This is a final template for [Learn Next.js](https://nextjs.org/learn). This is a final template for [Learn Next.js](https://nextjs.org/learn).

View File

@@ -1,6 +1,6 @@
import { parseISO, format } from 'date-fns' import { parseISO, format } from 'date-fns';
export default function Date({ dateString }) { export default function Date({ dateString }) {
const date = parseISO(dateString) const date = parseISO(dateString);
return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time> return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time>;
} }

View File

@@ -1,11 +1,11 @@
import Head from 'next/head' import Head from 'next/head';
import Image from 'next/image' import Image from 'next/image';
import styles from './layout.module.css' import styles from './layout.module.css';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import Link from 'next/link' import Link from 'next/link';
const name = 'Shu Uesugi' const name = 'Shu Uesugi';
export const siteTitle = 'Next.js Sample Website' export const siteTitle = 'Next.js Sample Website';
export default function Layout({ children, home }) { export default function Layout({ children, home }) {
return ( return (
@@ -19,7 +19,7 @@ export default function Layout({ children, home }) {
<meta <meta
property="og:image" property="og:image"
content={`https://og-image.vercel.app/${encodeURI( content={`https://og-image.vercel.app/${encodeURI(
siteTitle siteTitle,
)}.png?theme=light&md=0&fontSize=75px&images=https%3A%2F%2Fassets.zeit.co%2Fimage%2Fupload%2Ffront%2Fassets%2Fdesign%2Fnextjs-black-logo.svg`} )}.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="og:title" content={siteTitle} />
@@ -65,5 +65,5 @@ export default function Layout({ children, home }) {
</div> </div>
)} )}
</div> </div>
) );
} }

View File

@@ -1,69 +1,69 @@
import fs from 'fs' import fs from 'fs';
import path from 'path' import path from 'path';
import matter from 'gray-matter' import matter from 'gray-matter';
import { remark } from 'remark' import { remark } from 'remark';
import html from 'remark-html' import html from 'remark-html';
const postsDirectory = path.join(process.cwd(), 'posts') const postsDirectory = path.join(process.cwd(), 'posts');
export function getSortedPostsData() { export function getSortedPostsData() {
// Get file names under /posts // Get file names under /posts
const fileNames = fs.readdirSync(postsDirectory) const fileNames = fs.readdirSync(postsDirectory);
const allPostsData = fileNames.map(fileName => { const allPostsData = fileNames.map((fileName) => {
// Remove ".md" from file name to get id // Remove ".md" from file name to get id
const id = fileName.replace(/\.md$/, '') const id = fileName.replace(/\.md$/, '');
// Read markdown file as string // Read markdown file as string
const fullPath = path.join(postsDirectory, fileName) const fullPath = path.join(postsDirectory, fileName);
const fileContents = fs.readFileSync(fullPath, 'utf8') const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the post metadata section // Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents) const matterResult = matter(fileContents);
// Combine the data with the id // Combine the data with the id
return { return {
id, id,
...matterResult.data ...matterResult.data,
} };
}) });
// Sort posts by date // Sort posts by date
return allPostsData.sort((a, b) => { return allPostsData.sort((a, b) => {
if (a.date < b.date) { if (a.date < b.date) {
return 1 return 1;
} else { } else {
return -1 return -1;
} }
}) });
} }
export function getAllPostIds() { export function getAllPostIds() {
const fileNames = fs.readdirSync(postsDirectory) const fileNames = fs.readdirSync(postsDirectory);
return fileNames.map(fileName => { return fileNames.map((fileName) => {
return { return {
params: { params: {
id: fileName.replace(/\.md$/, '') id: fileName.replace(/\.md$/, ''),
} },
} };
}) });
} }
export async function getPostData(id) { export async function getPostData(id) {
const fullPath = path.join(postsDirectory, `${id}.md`) const fullPath = path.join(postsDirectory, `${id}.md`);
const fileContents = fs.readFileSync(fullPath, 'utf8') const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the post metadata section // Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents) const matterResult = matter(fileContents);
// Use remark to convert markdown into HTML string // Use remark to convert markdown into HTML string
const processedContent = await remark() const processedContent = await remark()
.use(html) .use(html)
.process(matterResult.content) .process(matterResult.content);
const contentHtml = processedContent.toString() const contentHtml = processedContent.toString();
// Combine the data with the id and contentHtml // Combine the data with the id and contentHtml
return { return {
id, id,
contentHtml, contentHtml,
...matterResult.data ...matterResult.data,
} };
} }

View File

@@ -1,11 +1,8 @@
{ {
"private": true, "private": true,
"engines": {
"node": ">=18"
},
"scripts": { "scripts": {
"dev": "next dev",
"build": "next build", "build": "next build",
"dev": "next dev",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
@@ -16,5 +13,8 @@
"react-dom": "18.2.0", "react-dom": "18.2.0",
"remark": "^14.0.2", "remark": "^14.0.2",
"remark-html": "^15.0.1" "remark-html": "^15.0.1"
},
"engines": {
"node": ">=18"
} }
} }

View File

@@ -1,5 +1,5 @@
import '../styles/global.css' import '../styles/global.css';
export default function App({ Component, pageProps }) { export default function App({ Component, pageProps }) {
return <Component {...pageProps} /> return <Component {...pageProps} />;
} }

View File

@@ -1,3 +1,3 @@
export default (req, res) => { export default (req, res) => {
res.status(200).json({ text: 'Hello' }) res.status(200).json({ text: 'Hello' });
} };

View File

@@ -1,9 +1,9 @@
import Head from 'next/head' import Head from 'next/head';
import Layout, { siteTitle } from '../components/layout' import Layout, { siteTitle } from '../components/layout';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import { getSortedPostsData } from '../lib/posts' import { getSortedPostsData } from '../lib/posts';
import Link from 'next/link' import Link from 'next/link';
import Date from '../components/date' import Date from '../components/date';
export default function Home({ allPostsData }) { export default function Home({ allPostsData }) {
return ( return (
@@ -37,14 +37,14 @@ export default function Home({ allPostsData }) {
</ul> </ul>
</section> </section>
</Layout> </Layout>
) );
} }
export async function getStaticProps() { export async function getStaticProps() {
const allPostsData = getSortedPostsData() const allPostsData = getSortedPostsData();
return { return {
props: { props: {
allPostsData allPostsData,
} },
} };
} }

View File

@@ -1,8 +1,8 @@
import Layout from '../../components/layout' import Layout from '../../components/layout';
import { getAllPostIds, getPostData } from '../../lib/posts' import { getAllPostIds, getPostData } from '../../lib/posts';
import Head from 'next/head' import Head from 'next/head';
import Date from '../../components/date' import Date from '../../components/date';
import utilStyles from '../../styles/utils.module.css' import utilStyles from '../../styles/utils.module.css';
export default function Post({ postData }) { export default function Post({ postData }) {
return ( return (
@@ -18,22 +18,22 @@ export default function Post({ postData }) {
<div dangerouslySetInnerHTML={{ __html: postData.contentHtml }} /> <div dangerouslySetInnerHTML={{ __html: postData.contentHtml }} />
</article> </article>
</Layout> </Layout>
) );
} }
export async function getStaticPaths() { export async function getStaticPaths() {
const paths = getAllPostIds() const paths = getAllPostIds();
return { return {
paths, paths,
fallback: false fallback: false,
} };
} }
export async function getStaticProps({ params }) { export async function getStaticProps({ params }) {
const postData = await getPostData(params.id) const postData = await getPostData(params.id);
return { return {
props: { props: {
postData postData,
} },
} };
} }

View File

@@ -2,8 +2,18 @@ html,
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, font-family:
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; -apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif;
line-height: 1.6; line-height: 1.6;
font-size: 18px; font-size: 18px;
} }

View File

@@ -1 +1 @@
This is a starter template for [Learn Next.js](https://nextjs.org/learn). This is a starter template for [Learn Next.js](https://nextjs.org/learn).

View File

@@ -1,11 +1,11 @@
import Head from 'next/head' import Head from 'next/head';
import Image from 'next/image' import Image from 'next/image';
import styles from './layout.module.css' import styles from './layout.module.css';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import Link from 'next/link' import Link from 'next/link';
const name = '[Your Name]' const name = '[Your Name]';
export const siteTitle = 'Next.js Sample Website' export const siteTitle = 'Next.js Sample Website';
export default function Layout({ children, home }) { export default function Layout({ children, home }) {
return ( return (
@@ -19,7 +19,7 @@ export default function Layout({ children, home }) {
<meta <meta
property="og:image" property="og:image"
content={`https://og-image.vercel.app/${encodeURI( content={`https://og-image.vercel.app/${encodeURI(
siteTitle siteTitle,
)}.png?theme=light&md=0&fontSize=75px&images=https%3A%2F%2Fassets.zeit.co%2Fimage%2Fupload%2Ffront%2Fassets%2Fdesign%2Fnextjs-black-logo.svg`} )}.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="og:title" content={siteTitle} />
@@ -65,5 +65,5 @@ export default function Layout({ children, home }) {
</div> </div>
)} )}
</div> </div>
) );
} }

View File

@@ -1,35 +1,35 @@
import fs from 'fs' import fs from 'fs';
import path from 'path' import path from 'path';
import matter from 'gray-matter' import matter from 'gray-matter';
const postsDirectory = path.join(process.cwd(), 'posts') const postsDirectory = path.join(process.cwd(), 'posts');
export function getSortedPostsData() { export function getSortedPostsData() {
// Get file names under /posts // Get file names under /posts
const fileNames = fs.readdirSync(postsDirectory) const fileNames = fs.readdirSync(postsDirectory);
const allPostsData = fileNames.map(fileName => { const allPostsData = fileNames.map((fileName) => {
// Remove ".md" from file name to get id // Remove ".md" from file name to get id
const id = fileName.replace(/\.md$/, '') const id = fileName.replace(/\.md$/, '');
// Read markdown file as string // Read markdown file as string
const fullPath = path.join(postsDirectory, fileName) const fullPath = path.join(postsDirectory, fileName);
const fileContents = fs.readFileSync(fullPath, 'utf8') const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the post metadata section // Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents) const matterResult = matter(fileContents);
// Combine the data with the id // Combine the data with the id
return { return {
id, id,
...matterResult.data ...matterResult.data,
} };
}) });
// Sort posts by date // Sort posts by date
return allPostsData.sort((a, b) => { return allPostsData.sort((a, b) => {
if (a.date < b.date) { if (a.date < b.date) {
return 1 return 1;
} else { } else {
return -1 return -1;
} }
}) });
} }

View File

@@ -1,11 +1,8 @@
{ {
"private": true, "private": true,
"engines": {
"node": ">=18"
},
"scripts": { "scripts": {
"dev": "next dev",
"build": "next build", "build": "next build",
"dev": "next dev",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
@@ -13,5 +10,8 @@
"next": "latest", "next": "latest",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0" "react-dom": "18.2.0"
},
"engines": {
"node": ">=18"
} }
} }

View File

@@ -1,5 +1,5 @@
import '../styles/global.css' import '../styles/global.css';
export default function App({ Component, pageProps }) { export default function App({ Component, pageProps }) {
return <Component {...pageProps} /> return <Component {...pageProps} />;
} }

View File

@@ -1,7 +1,7 @@
import Head from 'next/head' import Head from 'next/head';
import Layout, { siteTitle } from '../components/layout' import Layout, { siteTitle } from '../components/layout';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import { getSortedPostsData } from '../lib/posts' import { getSortedPostsData } from '../lib/posts';
export default function Home({ allPostsData }) { export default function Home({ allPostsData }) {
return ( return (
@@ -27,14 +27,14 @@ export default function Home({ allPostsData }) {
</ul> </ul>
</section> </section>
</Layout> </Layout>
) );
} }
export async function getStaticProps() { export async function getStaticProps() {
const allPostsData = getSortedPostsData() const allPostsData = getSortedPostsData();
return { return {
props: { props: {
allPostsData allPostsData,
} },
} };
} }

View File

@@ -1,6 +1,6 @@
import Head from 'next/head' import Head from 'next/head';
import Link from 'next/link' import Link from 'next/link';
import Layout from '../../components/layout' import Layout from '../../components/layout';
export default function FirstPost() { export default function FirstPost() {
return ( return (
@@ -13,5 +13,5 @@ export default function FirstPost() {
<Link href="/">Back to home</Link> <Link href="/">Back to home</Link>
</h2> </h2>
</Layout> </Layout>
) );
} }

View File

@@ -2,8 +2,18 @@ html,
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, font-family:
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; -apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif;
line-height: 1.6; line-height: 1.6;
font-size: 18px; font-size: 18px;
} }

View File

@@ -1 +1 @@
This is a starter template for [Learn Next.js](https://nextjs.org/learn). This is a starter template for [Learn Next.js](https://nextjs.org/learn).

View File

@@ -1,11 +1,11 @@
import Head from 'next/head' import Head from 'next/head';
import Image from 'next/image' import Image from 'next/image';
import styles from './layout.module.css' import styles from './layout.module.css';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import Link from 'next/link' import Link from 'next/link';
const name = '[Your Name]' const name = '[Your Name]';
export const siteTitle = 'Next.js Sample Website' export const siteTitle = 'Next.js Sample Website';
export default function Layout({ children, home }) { export default function Layout({ children, home }) {
return ( return (
@@ -19,7 +19,7 @@ export default function Layout({ children, home }) {
<meta <meta
property="og:image" property="og:image"
content={`https://og-image.vercel.app/${encodeURI( content={`https://og-image.vercel.app/${encodeURI(
siteTitle siteTitle,
)}.png?theme=light&md=0&fontSize=75px&images=https%3A%2F%2Fassets.zeit.co%2Fimage%2Fupload%2Ffront%2Fassets%2Fdesign%2Fnextjs-black-logo.svg`} )}.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="og:title" content={siteTitle} />
@@ -65,5 +65,5 @@ export default function Layout({ children, home }) {
</div> </div>
)} )}
</div> </div>
) );
} }

View File

@@ -1,60 +1,60 @@
import fs from 'fs' import fs from 'fs';
import path from 'path' import path from 'path';
import matter from 'gray-matter' import matter from 'gray-matter';
const postsDirectory = path.join(process.cwd(), 'posts') const postsDirectory = path.join(process.cwd(), 'posts');
export function getSortedPostsData() { export function getSortedPostsData() {
// Get file names under /posts // Get file names under /posts
const fileNames = fs.readdirSync(postsDirectory) const fileNames = fs.readdirSync(postsDirectory);
const allPostsData = fileNames.map(fileName => { const allPostsData = fileNames.map((fileName) => {
// Remove ".md" from file name to get id // Remove ".md" from file name to get id
const id = fileName.replace(/\.md$/, '') const id = fileName.replace(/\.md$/, '');
// Read markdown file as string // Read markdown file as string
const fullPath = path.join(postsDirectory, fileName) const fullPath = path.join(postsDirectory, fileName);
const fileContents = fs.readFileSync(fullPath, 'utf8') const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the post metadata section // Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents) const matterResult = matter(fileContents);
// Combine the data with the id // Combine the data with the id
return { return {
id, id,
...matterResult.data ...matterResult.data,
} };
}) });
// Sort posts by date // Sort posts by date
return allPostsData.sort((a, b) => { return allPostsData.sort((a, b) => {
if (a.date < b.date) { if (a.date < b.date) {
return 1 return 1;
} else { } else {
return -1 return -1;
} }
}) });
} }
export function getAllPostIds() { export function getAllPostIds() {
const fileNames = fs.readdirSync(postsDirectory) const fileNames = fs.readdirSync(postsDirectory);
return fileNames.map(fileName => { return fileNames.map((fileName) => {
return { return {
params: { params: {
id: fileName.replace(/\.md$/, '') id: fileName.replace(/\.md$/, ''),
} },
} };
}) });
} }
export function getPostData(id) { export function getPostData(id) {
const fullPath = path.join(postsDirectory, `${id}.md`) const fullPath = path.join(postsDirectory, `${id}.md`);
const fileContents = fs.readFileSync(fullPath, 'utf8') const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the post metadata section // Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents) const matterResult = matter(fileContents);
// Combine the data with the id // Combine the data with the id
return { return {
id, id,
...matterResult.data ...matterResult.data,
} };
} }

View File

@@ -1,11 +1,8 @@
{ {
"private": true, "private": true,
"engines": {
"node": ">=18"
},
"scripts": { "scripts": {
"dev": "next dev",
"build": "next build", "build": "next build",
"dev": "next dev",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
@@ -13,5 +10,8 @@
"next": "latest", "next": "latest",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0" "react-dom": "18.2.0"
},
"engines": {
"node": ">=18"
} }
} }

View File

@@ -1,5 +1,5 @@
import '../styles/global.css' import '../styles/global.css';
export default function App({ Component, pageProps }) { export default function App({ Component, pageProps }) {
return <Component {...pageProps} /> return <Component {...pageProps} />;
} }

View File

@@ -1,7 +1,7 @@
import Head from 'next/head' import Head from 'next/head';
import Layout, { siteTitle } from '../components/layout' import Layout, { siteTitle } from '../components/layout';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import { getSortedPostsData } from '../lib/posts' import { getSortedPostsData } from '../lib/posts';
export default function Home({ allPostsData }) { export default function Home({ allPostsData }) {
return ( return (
@@ -27,14 +27,14 @@ export default function Home({ allPostsData }) {
</ul> </ul>
</section> </section>
</Layout> </Layout>
) );
} }
export async function getStaticProps() { export async function getStaticProps() {
const allPostsData = getSortedPostsData() const allPostsData = getSortedPostsData();
return { return {
props: { props: {
allPostsData allPostsData,
} },
} };
} }

View File

@@ -1,5 +1,5 @@
import Layout from '../../components/layout' import Layout from '../../components/layout';
import { getAllPostIds, getPostData } from '../../lib/posts' import { getAllPostIds, getPostData } from '../../lib/posts';
export default function Post({ postData }) { export default function Post({ postData }) {
return ( return (
@@ -10,22 +10,22 @@ export default function Post({ postData }) {
<br /> <br />
{postData.date} {postData.date}
</Layout> </Layout>
) );
} }
export async function getStaticPaths() { export async function getStaticPaths() {
const paths = getAllPostIds() const paths = getAllPostIds();
return { return {
paths, paths,
fallback: false fallback: false,
} };
} }
export async function getStaticProps({ params }) { export async function getStaticProps({ params }) {
const postData = getPostData(params.id) const postData = getPostData(params.id);
return { return {
props: { props: {
postData postData,
} },
} };
} }

View File

@@ -2,8 +2,18 @@ html,
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, font-family:
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; -apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif;
line-height: 1.6; line-height: 1.6;
font-size: 18px; font-size: 18px;
} }

View File

@@ -1 +1 @@
This is a starter template for [Learn Next.js](https://nextjs.org/learn). This is a starter template for [Learn Next.js](https://nextjs.org/learn).

View File

@@ -1,16 +1,16 @@
{ {
"private": true, "private": true,
"engines": {
"node": ">=18"
},
"scripts": { "scripts": {
"dev": "next dev",
"build": "next build", "build": "next build",
"dev": "next dev",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"next": "latest", "next": "latest",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0" "react-dom": "18.2.0"
},
"engines": {
"node": ">=18"
} }
} }

View File

@@ -92,8 +92,15 @@ export default function Home() {
border-radius: 5px; border-radius: 5px;
padding: 0.75rem; padding: 0.75rem;
font-size: 1.1rem; font-size: 1.1rem;
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, font-family:
DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace; Menlo,
Monaco,
Lucida Console,
Liberation Mono,
DejaVu Sans Mono,
Bitstream Vera Sans Mono,
Courier New,
monospace;
} }
`}</style> `}</style>
@@ -102,8 +109,17 @@ export default function Home() {
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, font-family:
Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, -apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif; sans-serif;
} }
* { * {
@@ -111,5 +127,5 @@ export default function Home() {
} }
`}</style> `}</style>
</div> </div>
) );
} }

View File

@@ -33,7 +33,6 @@
text-align: center; text-align: center;
} }
.description { .description {
line-height: 1.5; line-height: 1.5;
font-size: 1.5rem; font-size: 1.5rem;
@@ -58,7 +57,9 @@
text-decoration: none; text-decoration: none;
border: 1px solid #eaeaea; border: 1px solid #eaeaea;
border-radius: 10px; border-radius: 10px;
transition: color 0.15s ease, border-color 0.15s ease; transition:
color 0.15s ease,
border-color 0.15s ease;
} }
.card:hover, .card:hover,

View File

@@ -2,8 +2,19 @@ html,
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: Inter, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, font-family:
Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; Inter,
-apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif;
} }
a { a {

View File

@@ -1 +1 @@
This is a starter template for [Learn Next.js](https://nextjs.org/learn). This is a starter template for [Learn Next.js](https://nextjs.org/learn).

View File

@@ -1,16 +1,16 @@
{ {
"private": true, "private": true,
"engines": {
"node": ">=18"
},
"scripts": { "scripts": {
"dev": "next dev",
"build": "next build", "build": "next build",
"dev": "next dev",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"next": "latest", "next": "latest",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0" "react-dom": "18.2.0"
},
"engines": {
"node": ">=18"
} }
} }

View File

@@ -1,4 +1,4 @@
import Head from 'next/head' import Head from 'next/head';
import styles from '../styles/Home.module.css'; import styles from '../styles/Home.module.css';
export default function Home() { export default function Home() {
@@ -92,8 +92,15 @@ export default function Home() {
border-radius: 5px; border-radius: 5px;
padding: 0.75rem; padding: 0.75rem;
font-size: 1.1rem; font-size: 1.1rem;
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, font-family:
DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace; Menlo,
Monaco,
Lucida Console,
Liberation Mono,
DejaVu Sans Mono,
Bitstream Vera Sans Mono,
Courier New,
monospace;
} }
`}</style> `}</style>
@@ -102,8 +109,17 @@ export default function Home() {
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, font-family:
Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, -apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif; sans-serif;
} }
* { * {
@@ -111,5 +127,5 @@ export default function Home() {
} }
`}</style> `}</style>
</div> </div>
) );
} }

View File

@@ -33,7 +33,6 @@
text-align: center; text-align: center;
} }
.description { .description {
line-height: 1.5; line-height: 1.5;
font-size: 1.5rem; font-size: 1.5rem;
@@ -58,7 +57,9 @@
text-decoration: none; text-decoration: none;
border: 1px solid #eaeaea; border: 1px solid #eaeaea;
border-radius: 10px; border-radius: 10px;
transition: color 0.15s ease, border-color 0.15s ease; transition:
color 0.15s ease,
border-color 0.15s ease;
} }
.card:hover, .card:hover,

View File

@@ -2,8 +2,19 @@ html,
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: Inter, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, font-family:
Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; Inter,
-apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif;
} }
a { a {

View File

@@ -1,17 +0,0 @@
{
"private": true,
"engines": {
"node": ">=18"
},
"license": "MIT",
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
},
"devDependencies": {
"prettier": "^2.0.2",
"pretty-quick": "2.0.1",
"husky": "4.2.3"
}
}

View File

@@ -1,12 +1,12 @@
// Example: Adding className with <Link> // Example: Adding className with <Link>
import Link from 'next/link' import Link from 'next/link';
export default function LinkClassnameExample() { export default function LinkClassnameExample() {
return ( return (
<Link href="/" className="foo" target="_blank" rel="noopener noreferrer"> <Link href="/" className="foo" target="_blank" rel="noopener noreferrer">
Hello World Hello World
</Link> </Link>
) );
} }
// Take a look at https://nextjs.org/docs/api-reference/next/link // Take a look at https://nextjs.org/docs/api-reference/next/link

View File

@@ -1 +1 @@
This is a starter template for [Learn Next.js](https://nextjs.org/learn). This is a starter template for [Learn Next.js](https://nextjs.org/learn).

View File

@@ -1,6 +1,6 @@
import { parseISO, format } from 'date-fns' import { parseISO, format } from 'date-fns';
export default function Date({ dateString }: { dateString: string }) { export default function Date({ dateString }: { dateString: string }) {
const date = parseISO(dateString) const date = parseISO(dateString);
return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time> return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time>;
} }

View File

@@ -1,18 +1,18 @@
import Head from 'next/head' import Head from 'next/head';
import Image from 'next/image' import Image from 'next/image';
import styles from './layout.module.css' import styles from './layout.module.css';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import Link from 'next/link' import Link from 'next/link';
const name = '[Your Name]' const name = '[Your Name]';
export const siteTitle = 'Next.js Sample Website' export const siteTitle = 'Next.js Sample Website';
export default function Layout({ export default function Layout({
children, children,
home home,
}: { }: {
children: React.ReactNode children: React.ReactNode;
home?: boolean home?: boolean;
}) { }) {
return ( return (
<div className={styles.container}> <div className={styles.container}>
@@ -25,7 +25,7 @@ export default function Layout({
<meta <meta
property="og:image" property="og:image"
content={`https://og-image.vercel.app/${encodeURI( content={`https://og-image.vercel.app/${encodeURI(
siteTitle siteTitle,
)}.png?theme=light&md=0&fontSize=75px&images=https%3A%2F%2Fassets.zeit.co%2Fimage%2Fupload%2Ffront%2Fassets%2Fdesign%2Fnextjs-black-logo.svg`} )}.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="og:title" content={siteTitle} />
@@ -71,5 +71,5 @@ export default function Layout({
</div> </div>
)} )}
</div> </div>
) );
} }

View File

@@ -1,4 +1,4 @@
declare module 'remark-html' { declare module 'remark-html' {
const html: any const html: any;
export default html export default html;
} }

View File

@@ -1,69 +1,69 @@
import fs from 'fs' import fs from 'fs';
import path from 'path' import path from 'path';
import matter from 'gray-matter' import matter from 'gray-matter';
import { remark } from 'remark' import { remark } from 'remark';
import html from 'remark-html' import html from 'remark-html';
const postsDirectory = path.join(process.cwd(), 'posts') const postsDirectory = path.join(process.cwd(), 'posts');
export function getSortedPostsData() { export function getSortedPostsData() {
// Get file names under /posts // Get file names under /posts
const fileNames = fs.readdirSync(postsDirectory) const fileNames = fs.readdirSync(postsDirectory);
const allPostsData = fileNames.map(fileName => { const allPostsData = fileNames.map((fileName) => {
// Remove ".md" from file name to get id // Remove ".md" from file name to get id
const id = fileName.replace(/\.md$/, '') const id = fileName.replace(/\.md$/, '');
// Read markdown file as string // Read markdown file as string
const fullPath = path.join(postsDirectory, fileName) const fullPath = path.join(postsDirectory, fileName);
const fileContents = fs.readFileSync(fullPath, 'utf8') const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the post metadata section // Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents) const matterResult = matter(fileContents);
// Combine the data with the id // Combine the data with the id
return { return {
id, id,
...(matterResult.data as { date: string; title: string }) ...(matterResult.data as { date: string; title: string }),
} };
}) });
// Sort posts by date // Sort posts by date
return allPostsData.sort((a, b) => { return allPostsData.sort((a, b) => {
if (a.date < b.date) { if (a.date < b.date) {
return 1 return 1;
} else { } else {
return -1 return -1;
} }
}) });
} }
export function getAllPostIds() { export function getAllPostIds() {
const fileNames = fs.readdirSync(postsDirectory) const fileNames = fs.readdirSync(postsDirectory);
return fileNames.map(fileName => { return fileNames.map((fileName) => {
return { return {
params: { params: {
id: fileName.replace(/\.md$/, '') id: fileName.replace(/\.md$/, ''),
} },
} };
}) });
} }
export async function getPostData(id: string) { export async function getPostData(id: string) {
const fullPath = path.join(postsDirectory, `${id}.md`) const fullPath = path.join(postsDirectory, `${id}.md`);
const fileContents = fs.readFileSync(fullPath, 'utf8') const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the post metadata section // Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents) const matterResult = matter(fileContents);
// Use remark to convert markdown into HTML string // Use remark to convert markdown into HTML string
const processedContent = await remark() const processedContent = await remark()
.use(html) .use(html)
.process(matterResult.content) .process(matterResult.content);
const contentHtml = processedContent.toString() const contentHtml = processedContent.toString();
// Combine the data with the id and contentHtml // Combine the data with the id and contentHtml
return { return {
id, id,
contentHtml, contentHtml,
...(matterResult.data as { date: string; title: string }) ...(matterResult.data as { date: string; title: string }),
} };
} }

View File

@@ -1,11 +1,8 @@
{ {
"private": true, "private": true,
"engines": {
"node": ">=18"
},
"scripts": { "scripts": {
"dev": "next dev",
"build": "next build", "build": "next build",
"dev": "next dev",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
@@ -21,5 +18,8 @@
"@types/node": "^18.11.9", "@types/node": "^18.11.9",
"@types/react": "^18.0.25", "@types/react": "^18.0.25",
"typescript": "^4.8.4" "typescript": "^4.8.4"
},
"engines": {
"node": ">=18"
} }
} }

View File

@@ -1,6 +1,6 @@
import '../styles/global.css' import '../styles/global.css';
import { AppProps } from 'next/app' import { AppProps } from 'next/app';
export default function App({ Component, pageProps }: AppProps) { export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} /> return <Component {...pageProps} />;
} }

View File

@@ -1,5 +1,5 @@
import { NextApiRequest, NextApiResponse } from 'next' import { NextApiRequest, NextApiResponse } from 'next';
export default (_: NextApiRequest, res: NextApiResponse) => { export default (_: NextApiRequest, res: NextApiResponse) => {
res.status(200).json({ text: 'Hello' }) res.status(200).json({ text: 'Hello' });
} };

View File

@@ -1,19 +1,19 @@
import Head from 'next/head' import Head from 'next/head';
import Layout, { siteTitle } from '../components/layout' import Layout, { siteTitle } from '../components/layout';
import utilStyles from '../styles/utils.module.css' import utilStyles from '../styles/utils.module.css';
import { getSortedPostsData } from '../lib/posts' import { getSortedPostsData } from '../lib/posts';
import Link from 'next/link' import Link from 'next/link';
import Date from '../components/date' import Date from '../components/date';
import { GetStaticProps } from 'next' import { GetStaticProps } from 'next';
export default function Home({ export default function Home({
allPostsData allPostsData,
}: { }: {
allPostsData: { allPostsData: {
date: string date: string;
title: string title: string;
id: string id: string;
}[] }[];
}) { }) {
return ( return (
<Layout home> <Layout home>
@@ -42,14 +42,14 @@ export default function Home({
</ul> </ul>
</section> </section>
</Layout> </Layout>
) );
} }
export const getStaticProps: GetStaticProps = async () => { export const getStaticProps: GetStaticProps = async () => {
const allPostsData = getSortedPostsData() const allPostsData = getSortedPostsData();
return { return {
props: { props: {
allPostsData allPostsData,
} },
} };
} };

View File

@@ -1,18 +1,18 @@
import Layout from '../../components/layout' import Layout from '../../components/layout';
import { getAllPostIds, getPostData } from '../../lib/posts' import { getAllPostIds, getPostData } from '../../lib/posts';
import Head from 'next/head' import Head from 'next/head';
import Date from '../../components/date' import Date from '../../components/date';
import utilStyles from '../../styles/utils.module.css' import utilStyles from '../../styles/utils.module.css';
import { GetStaticProps, GetStaticPaths } from 'next' import { GetStaticProps, GetStaticPaths } from 'next';
export default function Post({ export default function Post({
postData postData,
}: { }: {
postData: { postData: {
title: string title: string;
date: string date: string;
contentHtml: string contentHtml: string;
} };
}) { }) {
return ( return (
<Layout> <Layout>
@@ -27,22 +27,22 @@ export default function Post({
<div dangerouslySetInnerHTML={{ __html: postData.contentHtml }} /> <div dangerouslySetInnerHTML={{ __html: postData.contentHtml }} />
</article> </article>
</Layout> </Layout>
) );
} }
export const getStaticPaths: GetStaticPaths = async () => { export const getStaticPaths: GetStaticPaths = async () => {
const paths = getAllPostIds() const paths = getAllPostIds();
return { return {
paths, paths,
fallback: false fallback: false,
} };
} };
export const getStaticProps: GetStaticProps = async ({ params }) => { export const getStaticProps: GetStaticProps = async ({ params }) => {
const postData = await getPostData(params?.id as string) const postData = await getPostData(params?.id as string);
return { return {
props: { props: {
postData postData,
} },
} };
} };

View File

@@ -2,8 +2,18 @@ html,
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, font-family:
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; -apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif;
line-height: 1.6; line-height: 1.6;
font-size: 18px; font-size: 18px;
} }

View File

@@ -1,3 +0,0 @@
{
"extends": "next/core-web-vitals"
}

View File

@@ -1,9 +1,9 @@
import CustomersTable from "@/app/ui/customers/table"; import CustomersTable from '@/app/ui/customers/table';
export default function Page() { export default function Page() {
return ( return (
<div> <div>
<CustomersTable /> <CustomersTable />
</div> </div>
) );
} }

View File

@@ -1,6 +1,6 @@
import InvoiceForm from "@/app/ui/invoices/form"; import InvoiceForm from '@/app/ui/invoices/form';
import { invoices } from "@/app/lib/dummy-data"; import { invoices } from '@/app/lib/dummy-data';
import { notFound } from "next/navigation"; import { notFound } from 'next/navigation';
export default function Page({ params }: { params: { id: string } }) { export default function Page({ params }: { params: { id: string } }) {
const id = params.id ? parseInt(params.id) : null; const id = params.id ? parseInt(params.id) : null;

View File

@@ -1,4 +1,4 @@
import InvoiceForm from "@/app/ui/invoices/form"; import InvoiceForm from '@/app/ui/invoices/form';
export default function Page() { export default function Page() {
return <InvoiceForm type="new" />; return <InvoiceForm type="new" />;

View File

@@ -1,4 +1,4 @@
import InvoicesTable from "@/app/ui/invoices/table"; import InvoicesTable from '@/app/ui/invoices/table';
export default function Page() { export default function Page() {
return ( return (

View File

@@ -1,5 +1,5 @@
import TopNav from "@/app/ui/dashboard/topnav"; import TopNav from '@/app/ui/dashboard/topnav';
import SideNav from "@/app/ui/dashboard/sidenav"; import SideNav from '@/app/ui/dashboard/sidenav';
export default function Layout({ children }: { children: React.ReactNode }) { export default function Layout({ children }: { children: React.ReactNode }) {
return ( return (

View File

@@ -1,4 +1,4 @@
import DashboardOverview from "@/app/ui/dashboard/overview"; import DashboardOverview from '@/app/ui/dashboard/overview';
export default function Page() { export default function Page() {
return ( return (

View File

@@ -1,11 +1,11 @@
import "./globals.css"; import './globals.css';
import type { Metadata } from "next"; import type { Metadata } from 'next';
import { Inter } from "next/font/google"; import { Inter } from 'next/font/google';
const inter = Inter({ subsets: ["latin"] }); const inter = Inter({ subsets: ['latin'] });
export const metadata: Metadata = { export const metadata: Metadata = {
title: "Create Next App", title: 'Create Next App',
description: "Generated by create next app", description: 'Generated by create next app',
}; };
export default function RootLayout({ export default function RootLayout({

View File

@@ -1,11 +1,11 @@
"use server"; 'use server';
export async function deleteInvoice(id: number) { export async function deleteInvoice(id: number) {
// TO DO: Add delete invoice logic // TO DO: Add delete invoice logic
console.log("Delete invoice", id); console.log('Delete invoice', id);
} }
export async function addOrUpdateInvoice(formData: FormData) { export async function addOrUpdateInvoice(formData: FormData) {
// TO DO: Add create/update invoice logic // TO DO: Add create/update invoice logic
console.log("Edit Invoice"); console.log('Edit Invoice');
} }

View File

@@ -1,30 +1,30 @@
import { Invoice, Revenue } from "./definitions"; import { Invoice, Revenue } from './definitions';
export const calculateAllInvoices = ( export const calculateAllInvoices = (
invoices: Invoice[], invoices: Invoice[],
status: "pending" | "paid", status: 'pending' | 'paid',
) => { ) => {
return invoices return invoices
.filter((invoice) => !status || invoice.status === status) .filter((invoice) => !status || invoice.status === status)
.reduce((total, invoice) => total + invoice.amount / 100, 0) .reduce((total, invoice) => total + invoice.amount / 100, 0)
.toLocaleString("en-US", { .toLocaleString('en-US', {
style: "currency", style: 'currency',
currency: "USD", currency: 'USD',
}); });
}; };
export const calculateCustomerInvoices = ( export const calculateCustomerInvoices = (
invoices: Invoice[], invoices: Invoice[],
status: "pending" | "paid", status: 'pending' | 'paid',
customerId: number, customerId: number,
) => { ) => {
return invoices return invoices
.filter((invoice) => invoice.customerId === customerId) .filter((invoice) => invoice.customerId === customerId)
.filter((invoice) => !status || invoice.status === status) .filter((invoice) => !status || invoice.status === status)
.reduce((total, invoice) => total + invoice.amount / 100, 0) .reduce((total, invoice) => total + invoice.amount / 100, 0)
.toLocaleString("en-US", { .toLocaleString('en-US', {
style: "currency", style: 'currency',
currency: "USD", currency: 'USD',
}); });
}; };

Some files were not shown because too many files have changed in this diff Show More