@keystatic/templates-nextjs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +20 -0
- package/app/[slug]/layout.tsx +9 -0
- package/app/[slug]/page.tsx +27 -0
- package/app/keystatic/[[...params]]/page.tsx +3 -0
- package/app/keystatic/keystatic.tsx +6 -0
- package/app/keystatic/layout.tsx +5 -0
- package/app/layout.tsx +11 -0
- package/app/page.tsx +26 -0
- package/app/reader.ts +4 -0
- package/app/styles.css +24 -0
- package/keystatic.config.tsx +25 -0
- package/next.config.js +4 -0
- package/package.json +21 -0
- package/pages/api/keystatic/[[...params]].tsx +6 -0
- package/posts/first-post.mdoc +6 -0
- package/tsconfig.json +27 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Thinkmill Labs Pty Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Keystatic in Next.js
|
|
2
|
+
|
|
3
|
+
This template shows how you can use Keystatic in a Next.js site that utilises
|
|
4
|
+
the `app` directory.
|
|
5
|
+
|
|
6
|
+
To setup:
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
To run:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
npm run dev
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Admin UI: [http://127.0.0.1:3000/keystatic](http://127.0.0.1:3000/keystatic)
|
|
19
|
+
|
|
20
|
+
Homepage: [http://localhost:3000](http://localhost:3000)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DocumentRenderer } from '@keystatic/core/renderer';
|
|
2
|
+
import { reader } from '../reader';
|
|
3
|
+
|
|
4
|
+
export default async function Post({ params }: { params: { slug: string } }) {
|
|
5
|
+
const { slug } = params;
|
|
6
|
+
|
|
7
|
+
const post = await reader.collections.posts.read(slug);
|
|
8
|
+
|
|
9
|
+
if (!post) return <div>Post not found!</div>;
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<div>
|
|
13
|
+
<h1>{post.title}</h1>
|
|
14
|
+
<div>
|
|
15
|
+
<DocumentRenderer document={await post.content()} />
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function generateStaticParams() {
|
|
22
|
+
const slugs = await reader.collections.posts.list();
|
|
23
|
+
|
|
24
|
+
return slugs.map(slug => ({
|
|
25
|
+
slug,
|
|
26
|
+
}));
|
|
27
|
+
}
|
package/app/layout.tsx
ADDED
package/app/page.tsx
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Link from 'next/link';
|
|
2
|
+
import { reader } from './reader';
|
|
3
|
+
import './styles.css';
|
|
4
|
+
|
|
5
|
+
export default async function Homepage() {
|
|
6
|
+
const posts = await reader.collections.posts.all();
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<div>
|
|
10
|
+
<h1>Keystatic ⚡️</h1>
|
|
11
|
+
<p>This homepage shows how to load a collection from the reader API.</p>
|
|
12
|
+
<p>
|
|
13
|
+
<a href="/keystatic">Click here to visit the Admin UI</a>, or the link
|
|
14
|
+
below to view a post in the collection.
|
|
15
|
+
</p>
|
|
16
|
+
<h2>Posts</h2>
|
|
17
|
+
<ul>
|
|
18
|
+
{posts.map(post => (
|
|
19
|
+
<li key={post.slug}>
|
|
20
|
+
<Link href={`/${post.slug}`}>{post.entry.title}</Link>
|
|
21
|
+
</li>
|
|
22
|
+
))}
|
|
23
|
+
</ul>
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
}
|
package/app/reader.ts
ADDED
package/app/styles.css
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
html {
|
|
2
|
+
max-width: 70ch;
|
|
3
|
+
padding: 3rem 1rem;
|
|
4
|
+
margin: auto;
|
|
5
|
+
line-height: 1.75;
|
|
6
|
+
font-size: 1.25rem;
|
|
7
|
+
font-family: sans-serif;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
h1,
|
|
11
|
+
h2,
|
|
12
|
+
h3,
|
|
13
|
+
h4,
|
|
14
|
+
h5,
|
|
15
|
+
h6 {
|
|
16
|
+
margin: 1rem 0 1rem;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
p,
|
|
20
|
+
ul,
|
|
21
|
+
ol {
|
|
22
|
+
margin-bottom: 1rem;
|
|
23
|
+
color: #1d1d1d;
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { config, collection, fields } from '@keystatic/core';
|
|
2
|
+
|
|
3
|
+
export default config({
|
|
4
|
+
storage: {
|
|
5
|
+
kind: 'local',
|
|
6
|
+
},
|
|
7
|
+
collections: {
|
|
8
|
+
posts: collection({
|
|
9
|
+
label: 'Posts',
|
|
10
|
+
slugField: 'title',
|
|
11
|
+
path: 'posts/*',
|
|
12
|
+
format: { contentField: 'content' },
|
|
13
|
+
schema: {
|
|
14
|
+
title: fields.slug({ name: { label: 'Title' } }),
|
|
15
|
+
content: fields.document({
|
|
16
|
+
label: 'Content',
|
|
17
|
+
formatting: true,
|
|
18
|
+
dividers: true,
|
|
19
|
+
links: true,
|
|
20
|
+
images: true,
|
|
21
|
+
}),
|
|
22
|
+
},
|
|
23
|
+
}),
|
|
24
|
+
},
|
|
25
|
+
});
|
package/next.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@keystatic/templates-nextjs",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@keystatic/core": "^0.0.106",
|
|
7
|
+
"@keystatic/next": "^0.0.9",
|
|
8
|
+
"next": "^13.4.4",
|
|
9
|
+
"react": "^18.2.0",
|
|
10
|
+
"react-dom": "^18.2.0"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@types/react": "^18.2.8",
|
|
14
|
+
"typescript": "^5.1.3"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "next build",
|
|
18
|
+
"dev": "next dev",
|
|
19
|
+
"start": "next start"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"strict": false,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"incremental": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"module": "esnext",
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"downlevelIteration": true,
|
|
17
|
+
"jsx": "preserve",
|
|
18
|
+
"plugins": [
|
|
19
|
+
{
|
|
20
|
+
"name": "next"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"strictNullChecks": true
|
|
24
|
+
},
|
|
25
|
+
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
|
|
26
|
+
"exclude": ["node_modules"]
|
|
27
|
+
}
|