Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
StephDietz committed Sep 6, 2023
2 parents 8f74509 + 5a9bee2 commit fd7cf0e
Show file tree
Hide file tree
Showing 136 changed files with 6,782 additions and 777 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'weekly'
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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@v4
- 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 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.log
.DS_Store
node_modules
File renamed without changes.
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/.next
**/node_modules
**/package-lock.json
**/pnpm-lock.yaml
5 changes: 0 additions & 5 deletions basics/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions basics/.prettierignore

This file was deleted.

7 changes: 0 additions & 7 deletions basics/.prettierrc

This file was deleted.

2 changes: 1 addition & 1 deletion basics/api-routes-starter/README.md
Original file line number Diff line number Diff line change
@@ -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).
6 changes: 3 additions & 3 deletions basics/api-routes-starter/components/date.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parseISO, format } from 'date-fns'
import { parseISO, format } from 'date-fns';

export default function Date({ dateString }) {
const date = parseISO(dateString)
return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time>
const date = parseISO(dateString);
return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time>;
}
18 changes: 9 additions & 9 deletions basics/api-routes-starter/components/layout.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Head from 'next/head'
import Image from 'next/image'
import styles from './layout.module.css'
import utilStyles from '../styles/utils.module.css'
import Link from 'next/link'
import Head from 'next/head';
import Image from 'next/image';
import styles from './layout.module.css';
import utilStyles from '../styles/utils.module.css';
import Link from 'next/link';

const name = '[Your Name]'
export const siteTitle = 'Next.js Sample Website'
const name = '[Your Name]';
export const siteTitle = 'Next.js Sample Website';

export default function Layout({ children, home }) {
return (
Expand All @@ -19,7 +19,7 @@ export default function Layout({ children, home }) {
<meta
property="og:image"
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`}
/>
<meta name="og:title" content={siteTitle} />
Expand Down Expand Up @@ -65,5 +65,5 @@ export default function Layout({ children, home }) {
</div>
)}
</div>
)
);
}
62 changes: 31 additions & 31 deletions basics/api-routes-starter/lib/posts.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'
import { remark } from 'remark'
import html from 'remark-html'
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')
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 => {
const fileNames = fs.readdirSync(postsDirectory);
const allPostsData = fileNames.map((fileName) => {
// Remove ".md" from file name to get id
const id = fileName.replace(/\.md$/, '')
const id = fileName.replace(/\.md$/, '');

// Read markdown file as string
const fullPath = path.join(postsDirectory, fileName)
const fileContents = fs.readFileSync(fullPath, 'utf8')
const fullPath = path.join(postsDirectory, fileName);
const fileContents = fs.readFileSync(fullPath, 'utf8');

// Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents)
const matterResult = matter(fileContents);

// Combine the data with the id
return {
id,
...matterResult.data
}
})
...matterResult.data,
};
});
// Sort posts by date
return allPostsData.sort((a, b) => {
if (a.date < b.date) {
return 1
return 1;
} else {
return -1
return -1;
}
})
});
}

export function getAllPostIds() {
const fileNames = fs.readdirSync(postsDirectory)
return fileNames.map(fileName => {
const fileNames = fs.readdirSync(postsDirectory);
return fileNames.map((fileName) => {
return {
params: {
id: fileName.replace(/\.md$/, '')
}
}
})
id: fileName.replace(/\.md$/, ''),
},
};
});
}

export async function getPostData(id) {
const fullPath = path.join(postsDirectory, `${id}.md`)
const fileContents = fs.readFileSync(fullPath, 'utf8')
const fullPath = path.join(postsDirectory, `${id}.md`);
const fileContents = fs.readFileSync(fullPath, 'utf8');

// Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents)
const matterResult = matter(fileContents);

// Use remark to convert markdown into HTML string
const processedContent = await remark()
.use(html)
.process(matterResult.content)
const contentHtml = processedContent.toString()
.process(matterResult.content);
const contentHtml = processedContent.toString();

// Combine the data with the id and contentHtml
return {
id,
contentHtml,
...matterResult.data
}
...matterResult.data,
};
}
8 changes: 4 additions & 4 deletions basics/api-routes-starter/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"private": true,
"engines": {
"node": ">=18"
},
"scripts": {
"dev": "next dev",
"build": "next build",
"dev": "next dev",
"start": "next start"
},
"dependencies": {
Expand All @@ -16,5 +13,8 @@
"react-dom": "18.2.0",
"remark": "^14.0.2",
"remark-html": "^15.0.1"
},
"engines": {
"node": ">=18"
}
}
4 changes: 2 additions & 2 deletions basics/api-routes-starter/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '../styles/global.css'
import '../styles/global.css';

export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
return <Component {...pageProps} />;
}
22 changes: 11 additions & 11 deletions basics/api-routes-starter/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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'
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';

export default function Home({ allPostsData }) {
return (
Expand Down Expand Up @@ -33,14 +33,14 @@ export default function Home({ allPostsData }) {
</ul>
</section>
</Layout>
)
);
}

export async function getStaticProps() {
const allPostsData = getSortedPostsData()
const allPostsData = getSortedPostsData();
return {
props: {
allPostsData
}
}
allPostsData,
},
};
}
26 changes: 13 additions & 13 deletions basics/api-routes-starter/pages/posts/[id].js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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'
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';

export default function Post({ postData }) {
return (
Expand All @@ -18,22 +18,22 @@ export default function Post({ postData }) {
<div dangerouslySetInnerHTML={{ __html: postData.contentHtml }} />
</article>
</Layout>
)
);
}

export async function getStaticPaths() {
const paths = getAllPostIds()
const paths = getAllPostIds();
return {
paths,
fallback: false
}
fallback: false,
};
}

export async function getStaticProps({ params }) {
const postData = await getPostData(params.id)
const postData = await getPostData(params.id);
return {
props: {
postData
}
}
postData,
},
};
}
14 changes: 12 additions & 2 deletions basics/api-routes-starter/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ 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;
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;
}
Expand Down
2 changes: 1 addition & 1 deletion basics/assets-metadata-css-starter/README.md
Original file line number Diff line number Diff line change
@@ -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).
8 changes: 4 additions & 4 deletions basics/assets-metadata-css-starter/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"private": true,
"engines": {
"node": ">=18"
},
"scripts": {
"dev": "next dev",
"build": "next build",
"dev": "next dev",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"engines": {
"node": ">=18"
}
}
Loading

0 comments on commit fd7cf0e

Please sign in to comment.