@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 ADDED
@@ -0,0 +1,7 @@
1
+ # @keystatic/templates-nextjs
2
+
3
+ ## 0.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 818a4c14: Initial release of the NextJS template package.
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,9 @@
1
+ import '../styles.css';
2
+
3
+ export default function RootLayout({
4
+ children,
5
+ }: {
6
+ children: React.ReactNode;
7
+ }) {
8
+ return <>{children}</>;
9
+ }
@@ -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
+ }
@@ -0,0 +1,3 @@
1
+ export default function Page() {
2
+ return null;
3
+ }
@@ -0,0 +1,6 @@
1
+ 'use client';
2
+
3
+ import { makePage } from '@keystatic/next/ui/app';
4
+ import config from '../../keystatic.config';
5
+
6
+ export default makePage(config);
@@ -0,0 +1,5 @@
1
+ import KeystaticApp from './keystatic';
2
+
3
+ export default function RootLayout() {
4
+ return <KeystaticApp />;
5
+ }
package/app/layout.tsx ADDED
@@ -0,0 +1,11 @@
1
+ export default function RootLayout({
2
+ children,
3
+ }: {
4
+ children: React.ReactNode;
5
+ }) {
6
+ return (
7
+ <html lang="en">
8
+ <body>{children}</body>
9
+ </html>
10
+ );
11
+ }
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
@@ -0,0 +1,4 @@
1
+ import { createReader } from '@keystatic/core/reader';
2
+ import keystaticConfig from '../keystatic.config';
3
+
4
+ export const reader = createReader(process.cwd(), keystaticConfig);
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
@@ -0,0 +1,4 @@
1
+ /** @type {import('next').NextConfig} */
2
+ module.exports = {
3
+ reactStrictMode: false,
4
+ };
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
+ }
@@ -0,0 +1,6 @@
1
+ import config from '../../../keystatic.config';
2
+ import { makeAPIRouteHandler } from '@keystatic/next/api';
3
+
4
+ export default makeAPIRouteHandler({
5
+ config,
6
+ });
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: First post
3
+ ---
4
+ First!
5
+
6
+ You can edit this page in the [Admin UI](/keystatic/collection/posts/item/first-post), or directly in your IDE at `./posts/first-post.mdoc`.
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
+ }