@digitalygo/create-diggocms-app 0.1.0
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/README.md +152 -0
- package/bin/cli.js +392 -0
- package/package.json +44 -0
- package/templates/full/.env.local.example +13 -0
- package/templates/full/README.md +101 -0
- package/templates/full/app/[...slug]/page.tsx +115 -0
- package/templates/full/app/globals.css +187 -0
- package/templates/full/app/layout.tsx +25 -0
- package/templates/full/app/page.tsx +6 -0
- package/templates/full/components/DiggoProvider.tsx +15 -0
- package/templates/full/components/ExtendedCard.tsx +15 -0
- package/templates/full/components/ExtendedImage.tsx +16 -0
- package/templates/full/components/ExtendedMenuContainer.tsx +10 -0
- package/templates/full/components/ExtendedMenuItem.tsx +22 -0
- package/templates/full/components/ExtendedRichtext.tsx +15 -0
- package/templates/full/components/ExtendedSubtitle.tsx +10 -0
- package/templates/full/components/ExtendedTitle.tsx +10 -0
- package/templates/full/components/server-components.ts +8 -0
- package/templates/full/lib/data-fetching.ts +205 -0
- package/templates/full/lib/diggo-config.ts +48 -0
- package/templates/full/next-env.d.ts +2 -0
- package/templates/full/next.config.ts +7 -0
- package/templates/full/package.json +25 -0
- package/templates/full/tsconfig.json +23 -0
- package/templates/minimal/.env.local.example +13 -0
- package/templates/minimal/README.md +67 -0
- package/templates/minimal/app/[...slug]/page.tsx +56 -0
- package/templates/minimal/app/globals.css +11 -0
- package/templates/minimal/app/layout.tsx +22 -0
- package/templates/minimal/app/page.tsx +6 -0
- package/templates/minimal/components/DiggoProvider.tsx +15 -0
- package/templates/minimal/lib/data-fetching.ts +59 -0
- package/templates/minimal/lib/diggo-config.ts +35 -0
- package/templates/minimal/next-env.d.ts +2 -0
- package/templates/minimal/next.config.ts +7 -0
- package/templates/minimal/package.json +25 -0
- package/templates/minimal/tsconfig.json +23 -0
- package/templates/with-mock/.env.local.example +13 -0
- package/templates/with-mock/README.md +128 -0
- package/templates/with-mock/app/[...slug]/page.tsx +115 -0
- package/templates/with-mock/app/globals.css +187 -0
- package/templates/with-mock/app/layout.tsx +25 -0
- package/templates/with-mock/app/page.tsx +6 -0
- package/templates/with-mock/components/DiggoProvider.tsx +15 -0
- package/templates/with-mock/components/ExtendedCard.tsx +15 -0
- package/templates/with-mock/components/ExtendedImage.tsx +16 -0
- package/templates/with-mock/components/ExtendedMenuContainer.tsx +10 -0
- package/templates/with-mock/components/ExtendedMenuItem.tsx +22 -0
- package/templates/with-mock/components/ExtendedRichtext.tsx +15 -0
- package/templates/with-mock/components/ExtendedSubtitle.tsx +10 -0
- package/templates/with-mock/components/ExtendedTitle.tsx +10 -0
- package/templates/with-mock/components/server-components.ts +8 -0
- package/templates/with-mock/fixtures/collection.json +28 -0
- package/templates/with-mock/fixtures/menu.json +29 -0
- package/templates/with-mock/fixtures/pages/chi-siamo.json +37 -0
- package/templates/with-mock/fixtures/pages/contatti.json +33 -0
- package/templates/with-mock/fixtures/pages/home.json +62 -0
- package/templates/with-mock/fixtures/pages/index.json +17 -0
- package/templates/with-mock/lib/data-fetching.ts +205 -0
- package/templates/with-mock/lib/diggo-config.ts +48 -0
- package/templates/with-mock/next-env.d.ts +2 -0
- package/templates/with-mock/next.config.ts +7 -0
- package/templates/with-mock/package.json +27 -0
- package/templates/with-mock/scripts/mock-server.ts +231 -0
- package/templates/with-mock/tsconfig.json +23 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ComponentRegistry, NavigationRegistry, DiggoConfig } from '@digitalygo/diggocms-sdk-core';
|
|
2
|
+
import {
|
|
3
|
+
ExtendedTitle,
|
|
4
|
+
ExtendedSubtitle,
|
|
5
|
+
ExtendedImage,
|
|
6
|
+
ExtendedRichtext,
|
|
7
|
+
ExtendedCard,
|
|
8
|
+
ExtendedMenuItem,
|
|
9
|
+
ExtendedMenuContainer,
|
|
10
|
+
} from '@/components/server-components';
|
|
11
|
+
|
|
12
|
+
export const componentsRegistry: ComponentRegistry = {
|
|
13
|
+
subtitle: ExtendedSubtitle,
|
|
14
|
+
image: ExtendedImage,
|
|
15
|
+
richtext: ExtendedRichtext,
|
|
16
|
+
card: ExtendedCard,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const navigationRegistry: NavigationRegistry = {
|
|
20
|
+
MenuItem: ExtendedMenuItem,
|
|
21
|
+
MenuContainer: ExtendedMenuContainer,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const isMock = process.env.MOCK === '1';
|
|
25
|
+
const baseUrl = process.env.BASE_URL;
|
|
26
|
+
const mockApiUrl = process.env.MOCK_API_URL;
|
|
27
|
+
|
|
28
|
+
function getBaseUrl(): string {
|
|
29
|
+
if (isMock) {
|
|
30
|
+
return mockApiUrl ?? 'http://localhost:3001';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return baseUrl ?? 'http://placeholder.local';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const sdkConfig: DiggoConfig = {
|
|
37
|
+
baseUrl: getBaseUrl(),
|
|
38
|
+
components: componentsRegistry,
|
|
39
|
+
navigation: navigationRegistry,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export function isMockMode(): boolean {
|
|
43
|
+
return isMock;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function hasBaseUrl(): boolean {
|
|
47
|
+
return !!baseUrl;
|
|
48
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-diggocms-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "next dev",
|
|
8
|
+
"build": "next build",
|
|
9
|
+
"start": "next start",
|
|
10
|
+
"lint": "next lint",
|
|
11
|
+
"typecheck": "tsc --noEmit"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@digitalygo/diggocms-sdk-core": "^0.1.0",
|
|
15
|
+
"next": "^16.0.0",
|
|
16
|
+
"react": "^18.3.0",
|
|
17
|
+
"react-dom": "^18.3.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^20.0.0",
|
|
21
|
+
"@types/react": "^18.3.0",
|
|
22
|
+
"@types/react-dom": "^18.3.0",
|
|
23
|
+
"typescript": "^5.5.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["dom", "dom.iterable", "ES2022"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"module": "ESNext",
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"jsx": "preserve",
|
|
15
|
+
"incremental": true,
|
|
16
|
+
"plugins": [{ "name": "next" }],
|
|
17
|
+
"paths": {
|
|
18
|
+
"@/*": ["./*"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
22
|
+
"exclude": ["node_modules"]
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# DiggoCMS Environment Configuration
|
|
2
|
+
# Copy this file to .env.local and update the values
|
|
3
|
+
|
|
4
|
+
# CMS API Configuration
|
|
5
|
+
# Set your DiggoCMS API base URL
|
|
6
|
+
BASE_URL=https://your-cms-api.com
|
|
7
|
+
|
|
8
|
+
# Mock Mode
|
|
9
|
+
# Set to 1 to use local mock data instead of a real API
|
|
10
|
+
MOCK=0
|
|
11
|
+
|
|
12
|
+
# Mock API URL (only used when MOCK=1)
|
|
13
|
+
MOCK_API_URL=http://localhost:3001
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# My DiggoCMS App
|
|
2
|
+
|
|
3
|
+
A minimal DiggoCMS application built with Next.js and the DiggoCMS SDK.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
1. Copy `.env.local.example` to `.env.local` and configure your environment:
|
|
8
|
+
```bash
|
|
9
|
+
cp .env.local.example .env.local
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
2. Install dependencies:
|
|
13
|
+
```bash
|
|
14
|
+
npm install
|
|
15
|
+
# or
|
|
16
|
+
bun install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
3. Run the development server:
|
|
20
|
+
```bash
|
|
21
|
+
npm run dev
|
|
22
|
+
# or
|
|
23
|
+
bun run dev
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
4. Open [http://localhost:3000](http://localhost:3000) in your browser.
|
|
27
|
+
|
|
28
|
+
## Configuration
|
|
29
|
+
|
|
30
|
+
### Using a Real CMS API
|
|
31
|
+
|
|
32
|
+
Set your CMS API base URL:
|
|
33
|
+
```env
|
|
34
|
+
BASE_URL=https://your-cms-api.com
|
|
35
|
+
MOCK=0
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Using Mock Mode
|
|
39
|
+
|
|
40
|
+
Enable mock mode to use local fixtures:
|
|
41
|
+
```env
|
|
42
|
+
MOCK=1
|
|
43
|
+
MOCK_API_URL=http://localhost:3001
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Project Structure
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
app/ # Next.js app router
|
|
50
|
+
components/ # React components (add your extended components here)
|
|
51
|
+
lib/ # Utility functions and SDK configuration
|
|
52
|
+
public/ # Static assets
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Next Steps
|
|
56
|
+
|
|
57
|
+
This is a minimal template. To extend it:
|
|
58
|
+
|
|
59
|
+
1. Create custom components in `components/`
|
|
60
|
+
2. Register them in `lib/diggo-config.ts`
|
|
61
|
+
3. Add navigation components if needed
|
|
62
|
+
4. Set up your CMS API or mock server
|
|
63
|
+
|
|
64
|
+
## Documentation
|
|
65
|
+
|
|
66
|
+
- [DiggoCMS SDK Documentation](https://github.com/digitalygo/diggocms-sdk)
|
|
67
|
+
- [Next.js Documentation](https://nextjs.org/docs)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { Metadata } from 'next';
|
|
3
|
+
import { notFound } from 'next/navigation';
|
|
4
|
+
import { fetchPageData } from '@/lib/data-fetching';
|
|
5
|
+
import { renderPage } from '@digitalygo/diggocms-sdk-core/server';
|
|
6
|
+
import { componentsRegistry } from '@/lib/diggo-config';
|
|
7
|
+
|
|
8
|
+
export const dynamic = 'force-dynamic';
|
|
9
|
+
|
|
10
|
+
interface CatchAllPageProps {
|
|
11
|
+
params: Promise<{ slug: string[] }>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function generateMetadata({
|
|
15
|
+
params,
|
|
16
|
+
}: CatchAllPageProps): Promise<Metadata> {
|
|
17
|
+
const { slug: slugParam } = await params;
|
|
18
|
+
const slug = (Array.isArray(slugParam) ? slugParam : []).join('/') || 'home';
|
|
19
|
+
const { page } = await fetchPageData(slug);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
title: page?.title,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default async function CatchAllPage({
|
|
27
|
+
params,
|
|
28
|
+
}: CatchAllPageProps): Promise<ReactElement> {
|
|
29
|
+
const { slug: slugParam } = await params;
|
|
30
|
+
const slug = (Array.isArray(slugParam) ? slugParam : []).join('/') || 'home';
|
|
31
|
+
|
|
32
|
+
const { page, error } = await fetchPageData(slug);
|
|
33
|
+
|
|
34
|
+
if (!page) {
|
|
35
|
+
notFound();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<main style={{ maxWidth: '1200px', margin: '0 auto', padding: '2rem' }}>
|
|
40
|
+
{error && (
|
|
41
|
+
<div
|
|
42
|
+
style={{
|
|
43
|
+
background: '#fef3c7',
|
|
44
|
+
border: '1px solid #fbbf24',
|
|
45
|
+
padding: '1rem',
|
|
46
|
+
marginBottom: '1.5rem',
|
|
47
|
+
borderRadius: '0.375rem',
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<strong>Warning:</strong> {error}
|
|
51
|
+
</div>
|
|
52
|
+
)}
|
|
53
|
+
{renderPage(page, componentsRegistry)}
|
|
54
|
+
</main>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { DiggoProvider } from '@/components/DiggoProvider';
|
|
3
|
+
import './globals.css';
|
|
4
|
+
|
|
5
|
+
export const metadata = {
|
|
6
|
+
title: 'My DiggoCMS App',
|
|
7
|
+
description: 'Built with DiggoCMS SDK',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default function RootLayout({
|
|
11
|
+
children,
|
|
12
|
+
}: {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
}): ReactElement {
|
|
15
|
+
return (
|
|
16
|
+
<html lang="en">
|
|
17
|
+
<body>
|
|
18
|
+
<DiggoProvider>{children}</DiggoProvider>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
4
|
+
import { DiggoProvider as SDKProvider } from '@digitalygo/diggocms-sdk-core';
|
|
5
|
+
import { sdkConfig } from '@/lib/diggo-config';
|
|
6
|
+
|
|
7
|
+
interface DiggoProviderWrapperProps {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function DiggoProvider({
|
|
12
|
+
children,
|
|
13
|
+
}: DiggoProviderWrapperProps): ReactElement {
|
|
14
|
+
return <SDKProvider config={sdkConfig}>{children}</SDKProvider>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { PagePayload } from '@digitalygo/diggocms-sdk-core';
|
|
2
|
+
import { sdkConfig, isMockMode, hasBaseUrl } from './diggo-config';
|
|
3
|
+
|
|
4
|
+
export interface FetchPageResult {
|
|
5
|
+
page: PagePayload | null;
|
|
6
|
+
error: string | null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function fetchPageData(slug: string): Promise<FetchPageResult> {
|
|
10
|
+
if (isMockMode()) {
|
|
11
|
+
// Mock mode: fetch from local mock API
|
|
12
|
+
try {
|
|
13
|
+
const mockApiUrl = process.env.MOCK_API_URL ?? 'http://localhost:3001';
|
|
14
|
+
const response = await fetch(`${mockApiUrl}/pages/${slug}`);
|
|
15
|
+
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
return {
|
|
18
|
+
page: null,
|
|
19
|
+
error: `Mock API returned ${response.status}`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const page = (await response.json()) as PagePayload;
|
|
24
|
+
return { page, error: null };
|
|
25
|
+
} catch {
|
|
26
|
+
return {
|
|
27
|
+
page: null,
|
|
28
|
+
error: 'Failed to connect to mock API. Is it running?',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!hasBaseUrl()) {
|
|
34
|
+
return {
|
|
35
|
+
page: null,
|
|
36
|
+
error: 'BASE_URL is not configured and MOCK mode is not enabled.',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Real API mode: fetch from CMS
|
|
41
|
+
try {
|
|
42
|
+
const response = await fetch(`${sdkConfig.baseUrl}/pages/${slug}`);
|
|
43
|
+
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
return {
|
|
46
|
+
page: null,
|
|
47
|
+
error: `CMS returned ${response.status}`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const page = (await response.json()) as PagePayload;
|
|
52
|
+
return { page, error: null };
|
|
53
|
+
} catch {
|
|
54
|
+
return {
|
|
55
|
+
page: null,
|
|
56
|
+
error: 'Error connecting to CMS',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ComponentRegistry, NavigationRegistry, DiggoConfig } from '@digitalygo/diggocms-sdk-core';
|
|
2
|
+
|
|
3
|
+
// Add your custom components here
|
|
4
|
+
export const componentsRegistry: ComponentRegistry = {
|
|
5
|
+
// Example: title: ExtendedTitle,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const navigationRegistry: NavigationRegistry = {
|
|
9
|
+
// Example: MenuItem: ExtendedMenuItem,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const isMock = process.env.MOCK === '1';
|
|
13
|
+
const baseUrl = process.env.BASE_URL;
|
|
14
|
+
const mockApiUrl = process.env.MOCK_API_URL;
|
|
15
|
+
|
|
16
|
+
function getBaseUrl(): string {
|
|
17
|
+
if (isMock) {
|
|
18
|
+
return mockApiUrl ?? 'http://localhost:3001';
|
|
19
|
+
}
|
|
20
|
+
return baseUrl ?? 'http://placeholder.local';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const sdkConfig: DiggoConfig = {
|
|
24
|
+
baseUrl: getBaseUrl(),
|
|
25
|
+
components: componentsRegistry,
|
|
26
|
+
navigation: navigationRegistry,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function isMockMode(): boolean {
|
|
30
|
+
return isMock;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function hasBaseUrl(): boolean {
|
|
34
|
+
return !!baseUrl;
|
|
35
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-diggocms-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "next dev",
|
|
8
|
+
"build": "next build",
|
|
9
|
+
"start": "next start",
|
|
10
|
+
"lint": "next lint",
|
|
11
|
+
"typecheck": "tsc --noEmit"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@digitalygo/diggocms-sdk-core": "^0.1.0",
|
|
15
|
+
"next": "^16.0.0",
|
|
16
|
+
"react": "^18.3.0",
|
|
17
|
+
"react-dom": "^18.3.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^20.0.0",
|
|
21
|
+
"@types/react": "^18.3.0",
|
|
22
|
+
"@types/react-dom": "^18.3.0",
|
|
23
|
+
"typescript": "^5.5.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["dom", "dom.iterable", "ES2022"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"module": "ESNext",
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"jsx": "preserve",
|
|
15
|
+
"incremental": true,
|
|
16
|
+
"plugins": [{ "name": "next" }],
|
|
17
|
+
"paths": {
|
|
18
|
+
"@/*": ["./*"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
22
|
+
"exclude": ["node_modules"]
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# DiggoCMS Environment Configuration
|
|
2
|
+
# Copy this file to .env.local and update the values
|
|
3
|
+
|
|
4
|
+
# CMS API Configuration
|
|
5
|
+
# Set your DiggoCMS API base URL (not needed in mock mode)
|
|
6
|
+
BASE_URL=https://your-cms-api.com
|
|
7
|
+
|
|
8
|
+
# Mock Mode
|
|
9
|
+
# Set to 1 to use the local mock API server
|
|
10
|
+
MOCK=1
|
|
11
|
+
|
|
12
|
+
# Mock API URL
|
|
13
|
+
MOCK_API_URL=http://localhost:3001
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# My DiggoCMS App
|
|
2
|
+
|
|
3
|
+
A complete DiggoCMS application with mock API server for development.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Dynamic routing with `[...slug]` pattern
|
|
8
|
+
- Extended components (Title, Subtitle, Image, Richtext, Card)
|
|
9
|
+
- Navigation with dropdown support
|
|
10
|
+
- Built-in mock API server
|
|
11
|
+
- Sample fixtures included
|
|
12
|
+
- Mock mode for development
|
|
13
|
+
- Error handling and loading states
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
1. Copy `.env.local.example` to `.env.local`:
|
|
18
|
+
```bash
|
|
19
|
+
cp .env.local.example .env.local
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
2. Install dependencies:
|
|
23
|
+
```bash
|
|
24
|
+
bun install
|
|
25
|
+
# or
|
|
26
|
+
npm install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
3. Start the mock API and dev server:
|
|
30
|
+
```bash
|
|
31
|
+
bun run dev:mock
|
|
32
|
+
# or run separately:
|
|
33
|
+
bun run mock:api # Terminal 1
|
|
34
|
+
bun run dev # Terminal 2
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
4. Open [http://localhost:3000](http://localhost:3000) in your browser.
|
|
38
|
+
|
|
39
|
+
## Available Pages
|
|
40
|
+
|
|
41
|
+
The mock API includes these sample pages:
|
|
42
|
+
|
|
43
|
+
- `/` - Home page
|
|
44
|
+
- `/chi-siamo` - About page
|
|
45
|
+
- `/contatti` - Contact page
|
|
46
|
+
|
|
47
|
+
## Scripts
|
|
48
|
+
|
|
49
|
+
| Script | Description |
|
|
50
|
+
|--------|-------------|
|
|
51
|
+
| `bun run dev` | Start Next.js dev server only |
|
|
52
|
+
| `bun run build` | Build for production |
|
|
53
|
+
| `bun run start` | Start production server |
|
|
54
|
+
| `bun run mock:api` | Start mock API server only |
|
|
55
|
+
| `bun run dev:mock` | Start mock API and dev server together |
|
|
56
|
+
|
|
57
|
+
## Mock API Endpoints
|
|
58
|
+
|
|
59
|
+
The mock server provides these endpoints:
|
|
60
|
+
|
|
61
|
+
- `GET /pages` - List all pages
|
|
62
|
+
- `GET /pages/:slug` - Get page by slug
|
|
63
|
+
- `GET /collections/:type` - Get collection
|
|
64
|
+
- `GET /menus/:key` - Get menu by key
|
|
65
|
+
|
|
66
|
+
## Project Structure
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
app/ # Next.js app router
|
|
70
|
+
├── [...slug]/ # Dynamic catch-all route
|
|
71
|
+
├── layout.tsx # Root layout with DiggoProvider
|
|
72
|
+
├── page.tsx # Home redirect
|
|
73
|
+
└── globals.css # Global styles
|
|
74
|
+
|
|
75
|
+
components/ # React components
|
|
76
|
+
├── DiggoProvider.tsx
|
|
77
|
+
├── server-components.ts
|
|
78
|
+
├── ExtendedTitle.tsx
|
|
79
|
+
├── ExtendedSubtitle.tsx
|
|
80
|
+
├── ExtendedImage.tsx
|
|
81
|
+
├── ExtendedRichtext.tsx
|
|
82
|
+
├── ExtendedCard.tsx
|
|
83
|
+
├── ExtendedMenuItem.tsx
|
|
84
|
+
└── ExtendedMenuContainer.tsx
|
|
85
|
+
|
|
86
|
+
lib/ # Utility functions
|
|
87
|
+
├── diggo-config.ts
|
|
88
|
+
└── data-fetching.ts
|
|
89
|
+
|
|
90
|
+
fixtures/ # Mock data
|
|
91
|
+
├── pages/
|
|
92
|
+
│ ├── index.json # Pages list
|
|
93
|
+
│ ├── home.json # Home page
|
|
94
|
+
│ ├── chi-siamo.json
|
|
95
|
+
│ └── contatti.json
|
|
96
|
+
├── menu.json # Navigation menu
|
|
97
|
+
└── collection.json # Sample collection
|
|
98
|
+
|
|
99
|
+
scripts/
|
|
100
|
+
└── mock-server.ts # Mock API server
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Switching to Real API
|
|
104
|
+
|
|
105
|
+
To use a real CMS API instead of mock data:
|
|
106
|
+
|
|
107
|
+
1. Update `.env.local`:
|
|
108
|
+
```env
|
|
109
|
+
BASE_URL=https://your-cms-api.com
|
|
110
|
+
MOCK=0
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
2. Restart the dev server:
|
|
114
|
+
```bash
|
|
115
|
+
bun run dev
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Customization
|
|
119
|
+
|
|
120
|
+
1. **Edit fixtures** - Modify files in `fixtures/` to change content
|
|
121
|
+
2. **Add components** - Create new components in `components/` and register in `lib/diggo-config.ts`
|
|
122
|
+
3. **Update styles** - Edit `app/globals.css` or component styles
|
|
123
|
+
4. **Extend mock API** - Add new routes in `scripts/mock-server.ts`
|
|
124
|
+
|
|
125
|
+
## Documentation
|
|
126
|
+
|
|
127
|
+
- [DiggoCMS SDK Documentation](https://github.com/digitalygo/diggocms-sdk)
|
|
128
|
+
- [Next.js Documentation](https://nextjs.org/docs)
|