RustyCMS: File-based headless CMS with REST API, admin UI, multilingual support
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
18
.env.example
Normal file
18
.env.example
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Store backend: file | sqlite (default: file)
|
||||||
|
RUSTYCMS_STORE=file
|
||||||
|
|
||||||
|
# Multilingual: comma-separated locales (e.g. de,en). First = default. Content under content/{locale}/{collection}/.
|
||||||
|
RUSTYCMS_LOCALES=de,en
|
||||||
|
|
||||||
|
# Only when RUSTYCMS_STORE=sqlite: SQLite URL (default: sqlite:content.db)
|
||||||
|
# RUSTYCMS_DATABASE_URL=sqlite:content.db
|
||||||
|
|
||||||
|
# API key for write access (POST/PUT/DELETE + POST /api/schemas). GET stays without key.
|
||||||
|
# Authorization: Bearer <key> or X-API-Key: <key>. For Admin UI in browser: set same value in admin-ui as NEXT_PUBLIC_RUSTYCMS_API_KEY.
|
||||||
|
RUSTYCMS_API_KEY=dein-geheimes-token
|
||||||
|
|
||||||
|
# Optional: CORS – allowed origin (e.g. https://my-frontend.com). Empty or * = allow all.
|
||||||
|
# RUSTYCMS_CORS_ORIGIN=
|
||||||
|
|
||||||
|
# Optional: Response cache for GET /api/content (TTL in seconds). 0 = off. Default: 60.
|
||||||
|
# RUSTYCMS_CACHE_TTL_SECS=60
|
||||||
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/target
|
||||||
|
Cargo.lock
|
||||||
|
.env
|
||||||
|
.DS_Store
|
||||||
|
*.db
|
||||||
|
content.db
|
||||||
|
content/
|
||||||
|
.history
|
||||||
5
.vscode/extensions.json
vendored
Normal file
5
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"rust-lang.rust-analyzer"
|
||||||
|
]
|
||||||
|
}
|
||||||
67
.vscode/settings.json
vendored
Normal file
67
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": [
|
||||||
|
"content/blog_post/*.json5",
|
||||||
|
"content/blog_post/*.json"
|
||||||
|
],
|
||||||
|
"url": "./schemas/blog_post.schema.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fileMatch": [
|
||||||
|
"content/content_layout/*.json5",
|
||||||
|
"content/content_layout/*.json"
|
||||||
|
],
|
||||||
|
"url": "./schemas/content_layout.schema.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fileMatch": [
|
||||||
|
"content/fullwidth_banner/*.json5",
|
||||||
|
"content/fullwidth_banner/*.json"
|
||||||
|
],
|
||||||
|
"url": "./schemas/fullwidth_banner.schema.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fileMatch": [
|
||||||
|
"content/markdown/*.json5",
|
||||||
|
"content/markdown/*.json"
|
||||||
|
],
|
||||||
|
"url": "./schemas/markdown.schema.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fileMatch": [
|
||||||
|
"content/page/*.json5",
|
||||||
|
"content/page/*.json"
|
||||||
|
],
|
||||||
|
"url": "./schemas/page.schema.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fileMatch": [
|
||||||
|
"content/post/*.json5",
|
||||||
|
"content/post/*.json"
|
||||||
|
],
|
||||||
|
"url": "./schemas/post.schema.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fileMatch": [
|
||||||
|
"content/product/*.json5",
|
||||||
|
"content/product/*.json"
|
||||||
|
],
|
||||||
|
"url": "./schemas/product.schema.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fileMatch": [
|
||||||
|
"content/seo/*.json5",
|
||||||
|
"content/seo/*.json"
|
||||||
|
],
|
||||||
|
"url": "./schemas/seo.schema.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fileMatch": [
|
||||||
|
"content/tag/*.json5",
|
||||||
|
"content/tag/*.json"
|
||||||
|
],
|
||||||
|
"url": "./schemas/tag.schema.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
@types/Contentful_Badges.ts
Normal file
14
@types/Contentful_Badges.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentListSkeleton } from "src/@types/Contentful_List";
|
||||||
|
|
||||||
|
export interface CF_ComponentBadges {
|
||||||
|
internal: string;
|
||||||
|
badges: CF_ComponentListSkeleton;
|
||||||
|
variants: "light" | "dark";
|
||||||
|
layout?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_ComponentBadgesSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.badges;
|
||||||
|
fields: CF_ComponentBadges;
|
||||||
|
}
|
||||||
24
@types/Contentful_Campaign.ts
Normal file
24
@types/Contentful_Campaign.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
import type { Asset } from "contentful";
|
||||||
|
|
||||||
|
export interface CF_Campaign {
|
||||||
|
campaignName: string;
|
||||||
|
urlPatter: string;
|
||||||
|
selector: string;
|
||||||
|
insertHtml:
|
||||||
|
| "afterbegin"
|
||||||
|
| "beforeend"
|
||||||
|
| "afterend"
|
||||||
|
| "beforebegin"
|
||||||
|
| "replace";
|
||||||
|
timeUntil?: string;
|
||||||
|
javascript?: string;
|
||||||
|
medias?: Asset[];
|
||||||
|
html?: string;
|
||||||
|
css?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_CampaignSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.campaign;
|
||||||
|
fields: CF_Campaign;
|
||||||
|
}
|
||||||
13
@types/Contentful_Campaigns.ts
Normal file
13
@types/Contentful_Campaigns.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
import type { CF_CampaignSkeleton } from "./Contentful_Campaign";
|
||||||
|
|
||||||
|
export interface CF_Campaigns {
|
||||||
|
id: string;
|
||||||
|
campaigns: CF_CampaignSkeleton[];
|
||||||
|
enable: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_CampaignsSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.campaigns;
|
||||||
|
fields: CF_Campaigns;
|
||||||
|
}
|
||||||
15
@types/Contentful_CloudinaryImage.ts
Normal file
15
@types/Contentful_CloudinaryImage.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
export interface CF_CloudinaryImage {
|
||||||
|
bytes: number;
|
||||||
|
created_at: string;
|
||||||
|
format: string;
|
||||||
|
height: number;
|
||||||
|
original_secure_url: string;
|
||||||
|
original_url: string;
|
||||||
|
public_id: string;
|
||||||
|
resource_type: string;
|
||||||
|
secure_url: string;
|
||||||
|
type: string;
|
||||||
|
url: string;
|
||||||
|
version: number;
|
||||||
|
width: number;
|
||||||
|
}
|
||||||
24
@types/Contentful_Content.ts
Normal file
24
@types/Contentful_Content.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import type { EntrySkeletonType } from "contentful";
|
||||||
|
|
||||||
|
export type rowJutify =
|
||||||
|
| "start"
|
||||||
|
| "end"
|
||||||
|
| "center"
|
||||||
|
| "between"
|
||||||
|
| "around"
|
||||||
|
| "evenly";
|
||||||
|
export type rowAlignItems = "start" | "end" | "center" | "baseline" | "stretch";
|
||||||
|
|
||||||
|
export interface CF_Content {
|
||||||
|
row1JustifyContent: rowJutify;
|
||||||
|
row1AlignItems: rowAlignItems;
|
||||||
|
row1Content: EntrySkeletonType<any>[];
|
||||||
|
|
||||||
|
row2JustifyContent: rowJutify;
|
||||||
|
row2AlignItems: rowAlignItems;
|
||||||
|
row2Content: EntrySkeletonType<any>[];
|
||||||
|
|
||||||
|
row3JustifyContent: rowJutify;
|
||||||
|
row3AlignItems: rowAlignItems;
|
||||||
|
row3Content: EntrySkeletonType<any>[];
|
||||||
|
}
|
||||||
34
@types/Contentful_ContentType.enum.ts
Normal file
34
@types/Contentful_ContentType.enum.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
export enum CF_ContentType {
|
||||||
|
"componentLinkList" = "componentLinkList",
|
||||||
|
"badges" = "badges",
|
||||||
|
"componentPostOverview" = "componentPostOverview",
|
||||||
|
"footer" = "footer",
|
||||||
|
"fullwidthBanner" = "fullwidthBanner",
|
||||||
|
"headline" = "headline",
|
||||||
|
"html" = "html",
|
||||||
|
"image" = "image",
|
||||||
|
"img" = "img",
|
||||||
|
"iframe" = "iframe",
|
||||||
|
"imgGallery" = "imageGallery",
|
||||||
|
"internalReference" = "internalComponent",
|
||||||
|
"link" = "link",
|
||||||
|
"list" = "list",
|
||||||
|
"markdown" = "markdown",
|
||||||
|
"navigation" = "navigation",
|
||||||
|
"page" = "page",
|
||||||
|
"pageConfig" = "pageConfig",
|
||||||
|
"picture" = "picture",
|
||||||
|
"post" = "post",
|
||||||
|
"postComponent" = "postComponent",
|
||||||
|
"quote" = "quoteComponent",
|
||||||
|
"richtext" = "richtext",
|
||||||
|
"row" = "row",
|
||||||
|
"rowLayout" = "rowLayout",
|
||||||
|
"tag" = "tag",
|
||||||
|
"youtubeVideo" = "youtubeVideo",
|
||||||
|
"campaign" = "campaign",
|
||||||
|
"campaigns" = "campaigns",
|
||||||
|
"topBanner" = "topBanner",
|
||||||
|
"textFragment" = "textFragment",
|
||||||
|
"componentSearchableText" = "componentSearchableText",
|
||||||
|
}
|
||||||
10
@types/Contentful_Footer.ts
Normal file
10
@types/Contentful_Footer.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
import type { CF_Content } from "./Contentful_Content";
|
||||||
|
|
||||||
|
export interface CF_Footer extends CF_Content {
|
||||||
|
id : string;
|
||||||
|
}
|
||||||
|
export type CF_FooterSkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.footer
|
||||||
|
fields: CF_Footer
|
||||||
|
}
|
||||||
24
@types/Contentful_FullwidthBanner.ts
Normal file
24
@types/Contentful_FullwidthBanner.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import type { CF_ComponentImgSkeleton } from "src/@types/Contentful_Img";
|
||||||
|
import type { CF_CloudinaryImage } from "src/@types/Contentful_CloudinaryImage";
|
||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
|
||||||
|
|
||||||
|
export enum CF_FullwidthBannerVariant {
|
||||||
|
"dark"= "dark",
|
||||||
|
"light" = "light"
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_FullwidthBanner {
|
||||||
|
name: string,
|
||||||
|
variant : CF_FullwidthBannerVariant,
|
||||||
|
headline : string,
|
||||||
|
subheadline: string,
|
||||||
|
text : string,
|
||||||
|
image: CF_CloudinaryImage[];
|
||||||
|
img: CF_ComponentImgSkeleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_FullwidthBannerSkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.fullwidthBanner
|
||||||
|
fields: CF_FullwidthBanner
|
||||||
|
}
|
||||||
29
@types/Contentful_Grid.ts
Normal file
29
@types/Contentful_Grid.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import type { EntrySkeletonType } from "contentful";
|
||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
|
||||||
|
export type CF_justfyContent = "start" | "end" | "center" | "between" | "around" | "evenly";
|
||||||
|
export type CF_alignItems = "start" | "end" | "center" | "baseline" | "stretch"
|
||||||
|
|
||||||
|
export interface CF_Column_Alignment {
|
||||||
|
justifyContent: CF_justfyContent,
|
||||||
|
alignItems: CF_alignItems
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_Column_Layout<T> {
|
||||||
|
layoutMobile: T
|
||||||
|
layoutTablet: T
|
||||||
|
layoutDesktop: T
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_Row_1_Column_Layout = "auto" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12";
|
||||||
|
|
||||||
|
export interface CF_Row {
|
||||||
|
alignment: EntrySkeletonType<CF_Column_Alignment>
|
||||||
|
layout: EntrySkeletonType<CF_Column_Layout<CF_Row_1_Column_Layout>>
|
||||||
|
content: EntrySkeletonType<any>[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_RowSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.row
|
||||||
|
fields: CF_Row
|
||||||
|
}
|
||||||
33
@types/Contentful_Headline.ts
Normal file
33
@types/Contentful_Headline.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentLayout } from "src/@types/Contentful_Layout";
|
||||||
|
|
||||||
|
export type CF_Component_Headline_Align =
|
||||||
|
| "left"
|
||||||
|
| "center"
|
||||||
|
| "right"
|
||||||
|
|
||||||
|
export type CF_Component_Headline_Tag =
|
||||||
|
| "h1"
|
||||||
|
| "h2"
|
||||||
|
| "h3"
|
||||||
|
| "h4"
|
||||||
|
| "h5"
|
||||||
|
| "h6"
|
||||||
|
|
||||||
|
export type CF_alignTextClasses =
|
||||||
|
| "text-left"
|
||||||
|
| "text-center"
|
||||||
|
| "text-right"
|
||||||
|
|
||||||
|
export interface CF_ComponentHeadline {
|
||||||
|
internal: string;
|
||||||
|
text: string;
|
||||||
|
tag: CF_Component_Headline_Tag,
|
||||||
|
layout: CF_ComponentLayout
|
||||||
|
align?: CF_Component_Headline_Align
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_ComponentHeadlineSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.headline
|
||||||
|
fields: CF_ComponentHeadline
|
||||||
|
}
|
||||||
13
@types/Contentful_Html.ts
Normal file
13
@types/Contentful_Html.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentLayout } from "./Contentful_Layout";
|
||||||
|
|
||||||
|
export interface CF_HTML {
|
||||||
|
id: string;
|
||||||
|
html: string;
|
||||||
|
layout: CF_ComponentLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_HTMLSkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.html;
|
||||||
|
fields: CF_HTML;
|
||||||
|
};
|
||||||
16
@types/Contentful_Iframe.ts
Normal file
16
@types/Contentful_Iframe.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentImgSkeleton } from "./Contentful_Img";
|
||||||
|
import type { CF_ComponentLayout } from "./Contentful_Layout";
|
||||||
|
|
||||||
|
export interface CF_ComponentIframe {
|
||||||
|
name: string;
|
||||||
|
content: string;
|
||||||
|
iframe: string;
|
||||||
|
overlayImage?: CF_ComponentImgSkeleton;
|
||||||
|
layout: CF_ComponentLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_ComponentIframeSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.iframe;
|
||||||
|
fields: CF_ComponentIframe;
|
||||||
|
}
|
||||||
17
@types/Contentful_Image.ts
Normal file
17
@types/Contentful_Image.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentImgSkeleton } from "./Contentful_Img";
|
||||||
|
import type { CF_ComponentLayout } from "./Contentful_Layout";
|
||||||
|
|
||||||
|
export interface CF_ComponentImage {
|
||||||
|
name: string;
|
||||||
|
image: CF_ComponentImgSkeleton;
|
||||||
|
caption: string;
|
||||||
|
layout: CF_ComponentLayout;
|
||||||
|
maxWidth?: number;
|
||||||
|
aspectRatio?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_ComponentImageSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.image;
|
||||||
|
fields: CF_ComponentImage;
|
||||||
|
}
|
||||||
15
@types/Contentful_ImageGallery.ts
Normal file
15
@types/Contentful_ImageGallery.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentImgSkeleton } from "./Contentful_Img";
|
||||||
|
import type { CF_ComponentLayout } from "./Contentful_Layout";
|
||||||
|
|
||||||
|
export interface CF_ImageGallery {
|
||||||
|
name: string;
|
||||||
|
images: CF_ComponentImgSkeleton[];
|
||||||
|
layout: CF_ComponentLayout;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_ImageGallerySkeleton {
|
||||||
|
contentTypeId: CF_ContentType.imgGallery
|
||||||
|
fields:CF_ImageGallery
|
||||||
|
}
|
||||||
26
@types/Contentful_Img.ts
Normal file
26
@types/Contentful_Img.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
|
||||||
|
|
||||||
|
export interface CF_ComponentImgDetails {
|
||||||
|
size: number,
|
||||||
|
image: {
|
||||||
|
width: number,
|
||||||
|
height: number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_ComponentImg {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
file: {
|
||||||
|
url: string;
|
||||||
|
details: CF_ComponentImgDetails;
|
||||||
|
fileName: string;
|
||||||
|
contentType: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_ComponentImgSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.img
|
||||||
|
fields: CF_ComponentImg
|
||||||
|
}
|
||||||
14
@types/Contentful_InternalReference.ts
Normal file
14
@types/Contentful_InternalReference.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentLayout } from "src/@types/Contentful_Layout";
|
||||||
|
import type { EntryFieldTypes } from "contentful";
|
||||||
|
|
||||||
|
export interface CF_internalReference {
|
||||||
|
data: EntryFieldTypes.Object,
|
||||||
|
reference: string,
|
||||||
|
layout: CF_ComponentLayout
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_internalReferenceSkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.internalReference
|
||||||
|
fields: CF_internalReference
|
||||||
|
}
|
||||||
100
@types/Contentful_Layout.ts
Normal file
100
@types/Contentful_Layout.ts
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
|
||||||
|
export type CF_Component_Layout_Width =
|
||||||
|
| "1"
|
||||||
|
| "2"
|
||||||
|
| "3"
|
||||||
|
| "4"
|
||||||
|
| "5"
|
||||||
|
| "6"
|
||||||
|
| "7"
|
||||||
|
| "8"
|
||||||
|
| "9"
|
||||||
|
| "10"
|
||||||
|
| "11"
|
||||||
|
| "12";
|
||||||
|
|
||||||
|
export type CF_widths_mobile =
|
||||||
|
| "w-full"
|
||||||
|
| "w-1/12"
|
||||||
|
| "w-2/12"
|
||||||
|
| "w-3/12"
|
||||||
|
| "w-4/12"
|
||||||
|
| "w-5/12"
|
||||||
|
| "w-6/12"
|
||||||
|
| "w-7/12"
|
||||||
|
| "w-8/12"
|
||||||
|
| "w-9/12"
|
||||||
|
| "w-10/12"
|
||||||
|
| "w-11/12";
|
||||||
|
|
||||||
|
export type CF_widths_tablet =
|
||||||
|
| ""
|
||||||
|
| "md:w-full"
|
||||||
|
| "md:w-1/12"
|
||||||
|
| "md:w-2/12"
|
||||||
|
| "md:w-3/12"
|
||||||
|
| "md:w-4/12"
|
||||||
|
| "md:w-5/12"
|
||||||
|
| "md:w-6/12"
|
||||||
|
| "md:w-7/12"
|
||||||
|
| "md:w-8/12"
|
||||||
|
| "md:w-9/12"
|
||||||
|
| "md:w-10/12"
|
||||||
|
| "md:w-11/12";
|
||||||
|
|
||||||
|
export type CF_widths_desktop =
|
||||||
|
| ""
|
||||||
|
| "lg:w-full"
|
||||||
|
| "lg:w-1/12"
|
||||||
|
| "lg:w-2/12"
|
||||||
|
| "lg:w-3/12"
|
||||||
|
| "lg:w-4/12"
|
||||||
|
| "lg:w-5/12"
|
||||||
|
| "lg:w-6/12"
|
||||||
|
| "lg:w-7/12"
|
||||||
|
| "lg:w-8/12"
|
||||||
|
| "lg:w-9/12"
|
||||||
|
| "lg:w-10/12"
|
||||||
|
| "lg:w-11/12";
|
||||||
|
|
||||||
|
export type CF_Component_Layout_Space =
|
||||||
|
| 0
|
||||||
|
| .5
|
||||||
|
| 1
|
||||||
|
| 1.5
|
||||||
|
| 2
|
||||||
|
|
||||||
|
export type CF_Component_Space =
|
||||||
|
| ""
|
||||||
|
| "mb-[0.5rem]"
|
||||||
|
| "mb-[1rem]"
|
||||||
|
| "mb-[1.5rem]"
|
||||||
|
| "mb-[2rem]"
|
||||||
|
|
||||||
|
export type CF_justfyContent =
|
||||||
|
| "justify-start"
|
||||||
|
| "justify-end"
|
||||||
|
| "justify-center"
|
||||||
|
| "justify-between"
|
||||||
|
| "justify-around"
|
||||||
|
| "justify-evenly";
|
||||||
|
|
||||||
|
export type CF_alignItems =
|
||||||
|
| "items-start"
|
||||||
|
| "items-end"
|
||||||
|
| "items-center"
|
||||||
|
| "items-baseline"
|
||||||
|
| "items-stretch";
|
||||||
|
|
||||||
|
export interface CF_ComponentLayout {
|
||||||
|
mobile: CF_Component_Layout_Width;
|
||||||
|
tablet?: CF_Component_Layout_Width;
|
||||||
|
desktop?: CF_Component_Layout_Width;
|
||||||
|
spaceBottom?: CF_Component_Layout_Space
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_ComponentLayoutSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.rowLayout
|
||||||
|
fields: CF_ComponentLayout
|
||||||
|
}
|
||||||
23
@types/Contentful_Link.ts
Normal file
23
@types/Contentful_Link.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
|
||||||
|
export interface CF_Link {
|
||||||
|
name: string;
|
||||||
|
internal: string;
|
||||||
|
linkName: string;
|
||||||
|
icon?: string;
|
||||||
|
color?: string;
|
||||||
|
url: string;
|
||||||
|
newTab?: boolean;
|
||||||
|
external?: boolean;
|
||||||
|
description?: string;
|
||||||
|
alt?: string;
|
||||||
|
showText?: boolean;
|
||||||
|
author: string;
|
||||||
|
date: string;
|
||||||
|
source: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_LinkSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.link;
|
||||||
|
fields: CF_Link;
|
||||||
|
}
|
||||||
12
@types/Contentful_Link_List.ts
Normal file
12
@types/Contentful_Link_List.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
import type { CF_LinkSkeleton } from "./Contentful_Link";
|
||||||
|
|
||||||
|
export interface CF_Link_List {
|
||||||
|
headline: string;
|
||||||
|
links: CF_LinkSkeleton[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_LinkListSkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.componentLinkList;
|
||||||
|
fields: CF_Link_List;
|
||||||
|
};
|
||||||
11
@types/Contentful_List.ts
Normal file
11
@types/Contentful_List.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
|
||||||
|
export interface CF_ComponentList {
|
||||||
|
internal: string;
|
||||||
|
item: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_ComponentListSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.list
|
||||||
|
fields: CF_ComponentList
|
||||||
|
}
|
||||||
15
@types/Contentful_Markdown.ts
Normal file
15
@types/Contentful_Markdown.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentLayout } from "src/@types/Contentful_Layout";
|
||||||
|
import type { TextAlignment } from "src/@types/TextAlignment";
|
||||||
|
|
||||||
|
export interface CF_Markdown {
|
||||||
|
name: string,
|
||||||
|
content: string,
|
||||||
|
layout: CF_ComponentLayout
|
||||||
|
alignment: TextAlignment
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_MarkdownSkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.markdown
|
||||||
|
fields: CF_Markdown
|
||||||
|
}
|
||||||
17
@types/Contentful_Names.enum.ts
Normal file
17
@types/Contentful_Names.enum.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
export enum CF_Navigation_Keys {
|
||||||
|
"header" = "navigation-header",
|
||||||
|
"socialMedia" = "navigation-social-media",
|
||||||
|
"footer" = "navigation-footer",
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum CF_PageConfigKey {
|
||||||
|
"pageConfig" = "page-config",
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum CF_Footer_Keys {
|
||||||
|
"main" = "main",
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum CF_Campaigns_Keys {
|
||||||
|
"campaigns" = "campaigns",
|
||||||
|
}
|
||||||
15
@types/Contentful_Navigation.ts
Normal file
15
@types/Contentful_Navigation.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import type { EntrySkeletonType } from "contentful";
|
||||||
|
import type { CF_Link } from "src/lib/contentful";
|
||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
import type { CF_Page } from "./Contentful_Page";
|
||||||
|
|
||||||
|
export interface CF_Navigation {
|
||||||
|
name: string,
|
||||||
|
internal: string,
|
||||||
|
links: EntrySkeletonType<CF_Link, CF_Page>[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_NavigationSkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.navigation
|
||||||
|
fields: CF_Navigation
|
||||||
|
}
|
||||||
19
@types/Contentful_Page.ts
Normal file
19
@types/Contentful_Page.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
import type { CF_FullwidthBannerSkeleton } from "src/@types/Contentful_FullwidthBanner";
|
||||||
|
import type { CF_Content } from "./Contentful_Content";
|
||||||
|
import type { CF_SEO } from "./Contentful_SEO";
|
||||||
|
|
||||||
|
export interface CF_Page extends CF_Content, CF_SEO {
|
||||||
|
slug: string;
|
||||||
|
name: string;
|
||||||
|
linkName: string;
|
||||||
|
icon?: string;
|
||||||
|
headline: string;
|
||||||
|
subheadline: string;
|
||||||
|
topFullwidthBanner: CF_FullwidthBannerSkeleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_PageSkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.page;
|
||||||
|
fields: CF_Page;
|
||||||
|
};
|
||||||
18
@types/Contentful_PageConfig.ts
Normal file
18
@types/Contentful_PageConfig.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentImgSkeleton } from "./Contentful_Img";
|
||||||
|
|
||||||
|
export interface CF_PageConfig {
|
||||||
|
logo: CF_ComponentImgSkeleton;
|
||||||
|
footerText1: string;
|
||||||
|
seoTitle: string;
|
||||||
|
seoDescription: string;
|
||||||
|
blogTagPageHeadline: string;
|
||||||
|
blogPostsPageHeadline: string;
|
||||||
|
blogPostsPageSubHeadline: string;
|
||||||
|
website: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_PageConfigSkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.pageConfig;
|
||||||
|
fields: CF_PageConfig;
|
||||||
|
};
|
||||||
7
@types/Contentful_Page_Seo.ts
Normal file
7
@types/Contentful_Page_Seo.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export interface CF_Page_Seo {
|
||||||
|
name: "page-about-seo",
|
||||||
|
title: "about",
|
||||||
|
description: "about",
|
||||||
|
metaRobotsIndex: "index",
|
||||||
|
metaRobotsFollow: "follow"
|
||||||
|
}
|
||||||
57
@types/Contentful_Picture.ts
Normal file
57
@types/Contentful_Picture.ts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import type { EntryFieldTypes } from "contentful";
|
||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
import type { CF_CloudinaryImage } from "src/@types/Contentful_CloudinaryImage";
|
||||||
|
|
||||||
|
|
||||||
|
export type CF_PictureWidths = 400 | 800 | 1200 | 1400
|
||||||
|
export type CF_PictureFormats = "aviv" | "jpg" | "png" | "webp"
|
||||||
|
export type CF_PictureFit = "contain" | "cover" | "fill" | "inside" | "outside"
|
||||||
|
export type CF_PicturePosition = "top"
|
||||||
|
| "right top"
|
||||||
|
| "right"
|
||||||
|
| "right bottom"
|
||||||
|
| "bottom"
|
||||||
|
| "left bottom"
|
||||||
|
| "left"
|
||||||
|
| "left top"
|
||||||
|
| "north"
|
||||||
|
| "northeast"
|
||||||
|
| "east"
|
||||||
|
| "southeast"
|
||||||
|
| "south"
|
||||||
|
| "southwest"
|
||||||
|
| "west"
|
||||||
|
| "northwest"
|
||||||
|
| "center"
|
||||||
|
| "centre"
|
||||||
|
| "cover"
|
||||||
|
| "entropy"
|
||||||
|
| "attention"
|
||||||
|
export type CF_PictureAspectRatio = 'original'
|
||||||
|
| '32:9'
|
||||||
|
| '16:9'
|
||||||
|
| '5:4'
|
||||||
|
| '4:3'
|
||||||
|
| '3:2'
|
||||||
|
| '1:1'
|
||||||
|
| '2:3'
|
||||||
|
| '3:4'
|
||||||
|
| '4:5'
|
||||||
|
|
||||||
|
|
||||||
|
export interface CF_Picture {
|
||||||
|
name: EntryFieldTypes.Text;
|
||||||
|
image: CF_CloudinaryImage[];
|
||||||
|
alt?: EntryFieldTypes.Text;
|
||||||
|
widths: Array<CF_PictureWidths>;
|
||||||
|
aspectRatio: CF_PictureAspectRatio;
|
||||||
|
formats: CF_PictureFormats;
|
||||||
|
fit: CF_PictureFit;
|
||||||
|
position: CF_PicturePosition;
|
||||||
|
layout?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_PictureSkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.picture
|
||||||
|
fields: CF_Picture
|
||||||
|
}
|
||||||
27
@types/Contentful_Post.ts
Normal file
27
@types/Contentful_Post.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentImgSkeleton } from "./Contentful_Img";
|
||||||
|
import type { CF_Content } from "./Contentful_Content";
|
||||||
|
import type { CF_SEO } from "./Contentful_SEO";
|
||||||
|
import type { CF_TagSkeleton } from "./Contentful_Tag";
|
||||||
|
|
||||||
|
export interface CF_Post extends CF_Content, CF_SEO {
|
||||||
|
postImage: CF_ComponentImgSkeleton;
|
||||||
|
postTag: CF_TagSkeleton[];
|
||||||
|
slug: string;
|
||||||
|
linkName: string;
|
||||||
|
icon?: string;
|
||||||
|
headline: string;
|
||||||
|
important: boolean;
|
||||||
|
created: string;
|
||||||
|
date?: string;
|
||||||
|
subheadline: string;
|
||||||
|
excerpt: string;
|
||||||
|
content: string;
|
||||||
|
/** Show comment section (default: true) */
|
||||||
|
showCommentSection?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_PostEntrySkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.post;
|
||||||
|
fields: CF_Post;
|
||||||
|
};
|
||||||
14
@types/Contentful_Post_Component.ts
Normal file
14
@types/Contentful_Post_Component.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentLayout } from "./Contentful_Layout";
|
||||||
|
import type { CF_PostEntrySkeleton } from "./Contentful_Post";
|
||||||
|
|
||||||
|
export interface CF_PostComponent {
|
||||||
|
id: string;
|
||||||
|
post: CF_PostEntrySkeleton;
|
||||||
|
layout: CF_ComponentLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_PostComponentSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.postComponent;
|
||||||
|
fields: CF_PostComponent;
|
||||||
|
}
|
||||||
24
@types/Contentful_Post_Overview.ts
Normal file
24
@types/Contentful_Post_Overview.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
import type { CF_Content } from "./Contentful_Content";
|
||||||
|
import type { CF_SEO } from "src/@types/Contentful_SEO";
|
||||||
|
import type { CF_ComponentLayout } from "src/@types/Contentful_Layout";
|
||||||
|
import type { CF_PostEntrySkeleton } from "src/@types/Contentful_Post";
|
||||||
|
import type { CF_TagSkeleton } from "src/@types/Contentful_Tag";
|
||||||
|
import type { Document } from "@contentful/rich-text-types";
|
||||||
|
|
||||||
|
export interface CF_Post_Overview extends CF_Content, CF_SEO {
|
||||||
|
id: string;
|
||||||
|
headline: string;
|
||||||
|
text: Document;
|
||||||
|
layout: CF_ComponentLayout;
|
||||||
|
allPosts: boolean;
|
||||||
|
filterByTag: CF_TagSkeleton[];
|
||||||
|
posts: CF_PostEntrySkeleton[];
|
||||||
|
numberItems: number;
|
||||||
|
design?: "cards" | "list";
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_Post_OverviewEntrySkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.post;
|
||||||
|
fields: CF_Post_Overview;
|
||||||
|
};
|
||||||
14
@types/Contentful_Quote.ts
Normal file
14
@types/Contentful_Quote.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentLayout } from "src/@types/Contentful_Layout";
|
||||||
|
|
||||||
|
export interface CF_Quote {
|
||||||
|
quote: string,
|
||||||
|
author: string,
|
||||||
|
variant: 'left' | 'right',
|
||||||
|
layout: CF_ComponentLayout
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_QuoteSkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.quote
|
||||||
|
fields: CF_Quote
|
||||||
|
}
|
||||||
11
@types/Contentful_Richtext.ts
Normal file
11
@types/Contentful_Richtext.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
|
||||||
|
export interface CF_ComponentRichtext {
|
||||||
|
content?: Document;
|
||||||
|
layout?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_ComponentRichtextSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.richtext
|
||||||
|
fields: CF_ComponentRichtext
|
||||||
|
}
|
||||||
8
@types/Contentful_SEO.ts
Normal file
8
@types/Contentful_SEO.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
export type metaRobots = "index, follow" | "noindex, follow" | "index, nofollow" | "noindex, nofollow";
|
||||||
|
|
||||||
|
export interface CF_SEO {
|
||||||
|
seoTitle : string,
|
||||||
|
seoMetaRobots : metaRobots,
|
||||||
|
seoDescription : string,
|
||||||
|
}
|
||||||
18
@types/Contentful_SearchableText.ts
Normal file
18
@types/Contentful_SearchableText.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentLayout } from "./Contentful_Layout";
|
||||||
|
import type { CF_TextFragmentSkeleton } from "./Contentful_TextFragment";
|
||||||
|
import type { CF_TagSkeleton } from "./Contentful_Tag";
|
||||||
|
|
||||||
|
export interface CF_ComponentSearchableText {
|
||||||
|
id: string;
|
||||||
|
tagWhitelist?: CF_TagSkeleton[];
|
||||||
|
textFragments: CF_TextFragmentSkeleton[];
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
layout: CF_ComponentLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_ComponentSearchableTextSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.componentSearchableText;
|
||||||
|
fields: CF_ComponentSearchableText;
|
||||||
|
}
|
||||||
6
@types/Contentful_SkeletonTypes.ts
Normal file
6
@types/Contentful_SkeletonTypes.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import type { CF_PostEntrySkeleton } from "src/@types/Contentful_Post";
|
||||||
|
import type { CF_NavigationSkeleton } from "src/@types/Contentful_Navigation";
|
||||||
|
import type { CF_PageSkeleton } from "src/@types/Contentful_Page";
|
||||||
|
import type { CF_PageConfigSkeleton } from "src/@types/Contentful_PageConfig";
|
||||||
|
|
||||||
|
export type CF_SkeletonTypes = CF_PostEntrySkeleton | CF_NavigationSkeleton | CF_PageSkeleton | CF_PageConfigSkeleton;
|
||||||
11
@types/Contentful_Tag.ts
Normal file
11
@types/Contentful_Tag.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
|
||||||
|
export interface CF_Tag {
|
||||||
|
name: string;
|
||||||
|
icon: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_TagSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.tag;
|
||||||
|
fields: CF_Tag;
|
||||||
|
}
|
||||||
14
@types/Contentful_TextFragment.ts
Normal file
14
@types/Contentful_TextFragment.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
import type { CF_TagSkeleton } from "./Contentful_Tag";
|
||||||
|
|
||||||
|
export interface CF_TextFragment {
|
||||||
|
id: string;
|
||||||
|
tags?: CF_TagSkeleton[];
|
||||||
|
title: string;
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_TextFragmentSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.textFragment;
|
||||||
|
fields: CF_TextFragment;
|
||||||
|
}
|
||||||
11
@types/Contentful_TopBanner.ts
Normal file
11
@types/Contentful_TopBanner.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import type { CF_ContentType } from "src/@types/Contentful_ContentType.enum";
|
||||||
|
|
||||||
|
export interface CF_TopBanner {
|
||||||
|
id: string;
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CF_TopBannerSkeleton = {
|
||||||
|
contentTypeId: CF_ContentType.topBanner;
|
||||||
|
fields: CF_TopBanner;
|
||||||
|
};
|
||||||
16
@types/Contentful_YoutubeVideo.ts
Normal file
16
@types/Contentful_YoutubeVideo.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import type { CF_ContentType } from "./Contentful_ContentType.enum";
|
||||||
|
import type { CF_ComponentLayout } from "./Contentful_Layout";
|
||||||
|
|
||||||
|
export interface CF_YoutubeVideo {
|
||||||
|
id: string;
|
||||||
|
youtubeId: string;
|
||||||
|
params?: string;
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
layout: CF_ComponentLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CF_ComponentYoutubeVideoSkeleton {
|
||||||
|
contentTypeId: CF_ContentType.youtubeVideo;
|
||||||
|
fields: CF_YoutubeVideo;
|
||||||
|
}
|
||||||
91
@types/SeoProps.ts
Normal file
91
@types/SeoProps.ts
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
export type TwitterCardType =
|
||||||
|
| "summary"
|
||||||
|
| "summary_large_image"
|
||||||
|
| "app"
|
||||||
|
| "player";
|
||||||
|
|
||||||
|
// Link interface matching astro-seo's Link (which extends HTMLLinkElement)
|
||||||
|
// href must be string (not URL) to match astro-seo's expectations
|
||||||
|
export interface Link {
|
||||||
|
rel?: string;
|
||||||
|
href?: string; // Only string, not URL
|
||||||
|
hreflang?: string;
|
||||||
|
media?: string;
|
||||||
|
type?: string;
|
||||||
|
sizes?: string;
|
||||||
|
prefetch?: boolean;
|
||||||
|
crossorigin?: string;
|
||||||
|
as?: string;
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Meta {
|
||||||
|
property?: string;
|
||||||
|
name?: string;
|
||||||
|
content?: string;
|
||||||
|
httpEquiv?: string;
|
||||||
|
charset?: string;
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SeoProperties {
|
||||||
|
title?: string;
|
||||||
|
titleTemplate?: string;
|
||||||
|
titleDefault?: string;
|
||||||
|
charset?: string;
|
||||||
|
description?: string;
|
||||||
|
canonical?: URL | string;
|
||||||
|
nofollow?: boolean;
|
||||||
|
noindex?: boolean;
|
||||||
|
languageAlternates?: {
|
||||||
|
href: URL | string;
|
||||||
|
hrefLang: string;
|
||||||
|
}[];
|
||||||
|
openGraph?: {
|
||||||
|
basic: {
|
||||||
|
title: string;
|
||||||
|
type: string;
|
||||||
|
image: string;
|
||||||
|
url?: URL | string;
|
||||||
|
};
|
||||||
|
optional?: {
|
||||||
|
audio?: string;
|
||||||
|
description?: string;
|
||||||
|
determiner?: string;
|
||||||
|
locale?: string;
|
||||||
|
localeAlternate?: string[];
|
||||||
|
siteName?: string;
|
||||||
|
video?: string;
|
||||||
|
};
|
||||||
|
image?: {
|
||||||
|
url?: URL | string;
|
||||||
|
secureUrl?: URL | string;
|
||||||
|
type?: string;
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
alt?: string;
|
||||||
|
};
|
||||||
|
article?: {
|
||||||
|
publishedTime?: string;
|
||||||
|
modifiedTime?: string;
|
||||||
|
expirationTime?: string;
|
||||||
|
authors?: string[];
|
||||||
|
section?: string;
|
||||||
|
tags?: string[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
twitter?: {
|
||||||
|
card?: TwitterCardType;
|
||||||
|
site?: string;
|
||||||
|
creator?: string;
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
image?: URL | string;
|
||||||
|
imageAlt?: string;
|
||||||
|
};
|
||||||
|
extend?: {
|
||||||
|
link?: Partial<Link>[];
|
||||||
|
meta?: Partial<Meta>[];
|
||||||
|
};
|
||||||
|
surpressWarnings?: boolean;
|
||||||
|
}
|
||||||
6
@types/TextAlignment.ts
Normal file
6
@types/TextAlignment.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export type TextAlignment = 'left' | 'center' | 'right';
|
||||||
|
export enum TextAlignmentClasses {
|
||||||
|
'left' = 'text-left',
|
||||||
|
'center' = 'text-center',
|
||||||
|
'right' = 'text-right'
|
||||||
|
}
|
||||||
6
@types/astro-imagetools.d.ts
vendored
Normal file
6
@types/astro-imagetools.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
declare module "astro-imagetools/api" {
|
||||||
|
export function renderImg(
|
||||||
|
options: any
|
||||||
|
): Promise<{ link: string; style: string; img: string } | null>;
|
||||||
|
export function importImage(src: string): Promise<string | null>;
|
||||||
|
}
|
||||||
31
Cargo.toml
Normal file
31
Cargo.toml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
[package]
|
||||||
|
name = "rustycms"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
description = "A file-based headless CMS written in Rust"
|
||||||
|
default-run = "rustycms"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "export-json-schema"
|
||||||
|
path = "src/bin/export_json_schema.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
axum = "0.7"
|
||||||
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1"
|
||||||
|
json5 = "0.4"
|
||||||
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
|
tower-http = { version = "0.5", features = ["cors", "trace"] }
|
||||||
|
tracing = "0.1"
|
||||||
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
|
indexmap = { version = "2", features = ["serde"] }
|
||||||
|
anyhow = "1"
|
||||||
|
clap = { version = "4", features = ["derive"] }
|
||||||
|
regex = "1"
|
||||||
|
notify = "6"
|
||||||
|
async-trait = "0.1"
|
||||||
|
dotenvy = "0.15"
|
||||||
|
sqlx = { version = "0.8", features = ["runtime-tokio", "sqlite"] }
|
||||||
|
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] }
|
||||||
|
image = "0.25"
|
||||||
520
README.md
Normal file
520
README.md
Normal file
@@ -0,0 +1,520 @@
|
|||||||
|
# RustyCMS
|
||||||
|
|
||||||
|
A file-based headless CMS written in Rust. Content types are defined as JSON5 schemas, content is stored as JSON5 files, and served via a REST API.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **Schema-first**: Define content types in `types/*.json5` – fields, types, constraints, defaults
|
||||||
|
- **TypeScript-like type system**: `extends` (including multiple), `pick`, `omit`, `partial`
|
||||||
|
- **Rich validation**: `minLength`, `maxLength`, `min`, `max`, `pattern`, `enum`, `unique`, `nullable`, `readonly`, `strict`
|
||||||
|
- **File-based (default)**: No database setup – everything is files, versionable with Git
|
||||||
|
- **Optional SQLite**: Switch store via env – same API, different storage layer
|
||||||
|
- **REST API**: Full CRUD endpoints, auto-generated per content type
|
||||||
|
- **References & _resolve**: Reference fields as `{ _type, _slug }`; embed with `?_resolve=all`
|
||||||
|
- **Reusable partials**: `reusable` schemas and `useFields` for shared field groups (e.g. layout)
|
||||||
|
- **Optional API auth**: Protect write access (POST/PUT/DELETE) with an API key via env
|
||||||
|
- **Swagger UI**: Interactive API docs at `/swagger-ui`
|
||||||
|
- **Image transformation**: `GET /api/transform` – load image from external URL, optional resize (w, h), aspect-ratio crop (e.g. 1:1), fit (fill/contain/cover), output formats jpeg, png, webp, avif; with response cache
|
||||||
|
- **JSON5**: Human-friendly format with comments, trailing commas, unquoted keys
|
||||||
|
- **Editor validation**: Export JSON Schema from your types so VS Code/Cursor validate `content/*.json5` while you edit
|
||||||
|
- **CORS**: Open by default for frontend development
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- [Rust](https://www.rust-lang.org/tools/install) (1.70+)
|
||||||
|
|
||||||
|
## Quick start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd rustycms
|
||||||
|
cargo run
|
||||||
|
```
|
||||||
|
|
||||||
|
The server starts at `http://127.0.0.1:3000`.
|
||||||
|
|
||||||
|
### CLI options
|
||||||
|
|
||||||
|
| Option | Default | Description |
|
||||||
|
|-----------------|-----------------|---------------------------------------|
|
||||||
|
| `--types-dir` | `./types` | Directory with type definitions |
|
||||||
|
| `--content-dir` | `./content` | Directory with content files |
|
||||||
|
| `-p, --port` | `3000` | Port |
|
||||||
|
| `--host` | `127.0.0.1` | Host address |
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo run -- --types-dir ./my-schemas --content-dir ./my-data -p 8080
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configuration (environment variables)
|
||||||
|
|
||||||
|
A `.env` in the project directory is loaded at startup. See `.env.example`.
|
||||||
|
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|--------------------------|---------------|--------------|
|
||||||
|
| `RUSTYCMS_STORE` | `file` | Store backend: `file` or `sqlite` |
|
||||||
|
| `RUSTYCMS_DATABASE_URL` | `sqlite:content.db` | When using `sqlite`: SQLite URL (fallback: `DATABASE_URL`) |
|
||||||
|
| `RUSTYCMS_API_KEY` | – | Optional. When set: POST/PUT/DELETE require this key (Bearer or X-API-Key). GET stays public. |
|
||||||
|
| `RUSTYCMS_CORS_ORIGIN` | all | Optional. One allowed CORS origin (e.g. `https://my-frontend.com`). Empty or `*` = all allowed. |
|
||||||
|
| `RUSTYCMS_CACHE_TTL_SECS` | `60` | Optional. Response cache for GET /api/content in seconds. `0` = cache off. |
|
||||||
|
|
||||||
|
**Examples:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# File store (default), no auth
|
||||||
|
cargo run
|
||||||
|
|
||||||
|
# SQLite backend
|
||||||
|
RUSTYCMS_STORE=sqlite cargo run
|
||||||
|
|
||||||
|
# Write access only with API key
|
||||||
|
RUSTYCMS_API_KEY=your-secret-token cargo run
|
||||||
|
```
|
||||||
|
|
||||||
|
## Project structure
|
||||||
|
|
||||||
|
```
|
||||||
|
rustycms/
|
||||||
|
├── Cargo.toml
|
||||||
|
├── src/
|
||||||
|
│ ├── main.rs # Entry point, CLI, server
|
||||||
|
│ ├── schema/
|
||||||
|
│ │ ├── types.rs # SchemaDefinition, FieldDefinition
|
||||||
|
│ │ ├── loader.rs # Load JSON5, resolve extends/pick/omit/partial
|
||||||
|
│ │ ├── json_schema.rs # Export JSON Schema for editor validation
|
||||||
|
│ │ ├── validator.rs # Validation (constraints, unique, readonly, …)
|
||||||
|
│ │ └── mod.rs # SchemaRegistry
|
||||||
|
│ ├── bin/
|
||||||
|
│ │ └── export_json_schema.rs # CLI: export schemas + optional .vscode/settings.json
|
||||||
|
│ ├── store/
|
||||||
|
│ │ ├── store.rs # ContentStore trait (abstract storage layer)
|
||||||
|
│ │ ├── filesystem.rs # FileStore – CRUD on JSON5 files
|
||||||
|
│ │ ├── sqlite.rs # SqliteStore – optional SQLite backend
|
||||||
|
│ │ ├── query.rs # Filter, sort, paginate
|
||||||
|
│ │ ├── slug.rs # Slug normalisation & validation
|
||||||
|
│ │ └── mod.rs
|
||||||
|
│ └── api/
|
||||||
|
│ ├── handlers.rs # REST handlers (CRUD + validation)
|
||||||
|
│ ├── routes.rs # Axum router
|
||||||
|
│ ├── openapi.rs # OpenAPI spec & Swagger UI
|
||||||
|
│ ├── auth.rs # Optional API key check (POST/PUT/DELETE)
|
||||||
|
│ ├── error.rs # API error types
|
||||||
|
│ ├── response.rs # Reference formatting, _resolve
|
||||||
|
│ ├── transform.rs # Image transformation (external URL → resize/crop/format)
|
||||||
|
│ └── mod.rs
|
||||||
|
├── types/ # Type definitions (layer 1)
|
||||||
|
│ ├── blog_post.json5
|
||||||
|
│ ├── page.json5 # extends blog_post
|
||||||
|
│ └── product.json5 # strict mode, constraints, unique, pattern
|
||||||
|
├── schemas/ # Generated JSON Schema (optional, for editor)
|
||||||
|
└── content/ # Content files (layer 2)
|
||||||
|
├── blog_post/
|
||||||
|
├── page/
|
||||||
|
└── product/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Editor validation (JSON Schema)
|
||||||
|
|
||||||
|
You can export JSON Schema files from your type definitions so that VS Code / Cursor validate `content/*.json5` (and `*.json`) while you edit. Invalid fields, wrong types, or constraint violations show as squiggles in the editor.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Export one .schema.json per content type into ./schemas
|
||||||
|
cargo run --bin export-json-schema
|
||||||
|
|
||||||
|
# Also write .vscode/settings.json so content/<type>/*.json5 uses schemas/<type>.schema.json
|
||||||
|
cargo run --bin export-json-schema -- --vscode
|
||||||
|
```
|
||||||
|
|
||||||
|
Options: `--types-dir` (default `./types`), `--out-dir` (default `./schemas`). After running with `--vscode`, open any file under `content/blog_post/`, `content/page/`, etc. – the editor will use the matching schema. Re-run the command after changing type definitions to refresh schemas and (with `--vscode`) the settings.
|
||||||
|
|
||||||
|
## Defining types
|
||||||
|
|
||||||
|
Add a `.json5` file under `types/`:
|
||||||
|
|
||||||
|
```json5
|
||||||
|
// types/blog_post.json5
|
||||||
|
{
|
||||||
|
name: "blog_post",
|
||||||
|
fields: {
|
||||||
|
title: {
|
||||||
|
type: "string",
|
||||||
|
required: true,
|
||||||
|
minLength: 1,
|
||||||
|
maxLength: 200,
|
||||||
|
description: "Title of the blog post",
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
type: "richtext",
|
||||||
|
required: true,
|
||||||
|
description: "Main content (Markdown)",
|
||||||
|
},
|
||||||
|
author: { type: "string" },
|
||||||
|
tags: { type: "array", items: { type: "string" } },
|
||||||
|
published: { type: "boolean", default: false },
|
||||||
|
created_at: { type: "datetime", auto: true, readonly: true },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Schema options
|
||||||
|
|
||||||
|
| Option | Type | Description |
|
||||||
|
|-----------|-----------------|----------------------------------------------------------|
|
||||||
|
| `name` | string | **Required.** Content type name |
|
||||||
|
| `extends` | string / array | Parent type(s) to inherit from |
|
||||||
|
| `strict` | boolean | Reject unknown fields |
|
||||||
|
| `pick` | string[] | Only inherit these fields from parent (`Pick<T>`) |
|
||||||
|
| `omit` | string[] | Exclude these fields from parent (`Omit<T>`) |
|
||||||
|
| `partial` | boolean | Make all inherited fields optional (`Partial<T>`) |
|
||||||
|
| `reusable`| boolean | Schema only as partial (useFields), no collection/API |
|
||||||
|
|
||||||
|
### Field options
|
||||||
|
|
||||||
|
| Option | Type | Description |
|
||||||
|
|-------------|----------|-----------------------------------------------------|
|
||||||
|
| `type` | string | **Required.** Field type (see below) |
|
||||||
|
| `required` | boolean | Field must be present when creating |
|
||||||
|
| `unique` | boolean | Value must be unique in the collection |
|
||||||
|
| `default` | any | Default value if not provided |
|
||||||
|
| `auto` | boolean | Auto-generated (e.g. timestamp) |
|
||||||
|
| `readonly` | boolean | Field cannot be changed after creation |
|
||||||
|
| `nullable` | boolean | Field allows explicit `null` |
|
||||||
|
| `enum` | array | Allowed values |
|
||||||
|
| `description` | string | Description (shown in Swagger UI) |
|
||||||
|
| `minLength` | number | Minimum string length |
|
||||||
|
| `maxLength` | number | Maximum string length |
|
||||||
|
| `pattern` | string | Regex pattern for strings |
|
||||||
|
| `min` | number | Minimum numeric value |
|
||||||
|
| `max` | number | Maximum numeric value |
|
||||||
|
| `minItems` | number | Minimum array length |
|
||||||
|
| `maxItems` | number | Maximum array length |
|
||||||
|
| `items` | object | Item definition for array fields |
|
||||||
|
| `fields` | object | Nested fields for object type |
|
||||||
|
| `collection`| string | Target collection for reference type |
|
||||||
|
| `useFields` | string | For `type: "object"`: use fields from this schema (partial) |
|
||||||
|
|
||||||
|
### Field types
|
||||||
|
|
||||||
|
| Type | JSON type | Description |
|
||||||
|
|--------------|-----------|--------------------------------|
|
||||||
|
| `string` | string | Plain text |
|
||||||
|
| `richtext` | string | Markdown / rich text |
|
||||||
|
| `number` | number | Integer or float |
|
||||||
|
| `boolean` | boolean | true / false |
|
||||||
|
| `datetime` | string | ISO 8601 date/time |
|
||||||
|
| `array` | array | List (optional `items`) |
|
||||||
|
| `object` | object | Nested object |
|
||||||
|
| `reference` | string | Reference to another type |
|
||||||
|
|
||||||
|
### Inheritance & type composition
|
||||||
|
|
||||||
|
**Simple inheritance** – inherit all fields from parent:
|
||||||
|
|
||||||
|
```json5
|
||||||
|
{
|
||||||
|
name: "page",
|
||||||
|
extends: "blog_post",
|
||||||
|
fields: {
|
||||||
|
nav_order: { type: "number", min: 0 },
|
||||||
|
template: { type: "string", enum: ["default", "landing", "docs"] },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Multiple inheritance** – inherit from several types:
|
||||||
|
|
||||||
|
```json5
|
||||||
|
{
|
||||||
|
name: "featured_article",
|
||||||
|
extends: ["blog_post", "seo_meta"],
|
||||||
|
fields: {
|
||||||
|
featured_until: { type: "datetime" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Pick** – only certain fields from parent:
|
||||||
|
|
||||||
|
```json5
|
||||||
|
{
|
||||||
|
name: "blog_post_preview",
|
||||||
|
extends: "blog_post",
|
||||||
|
pick: ["title", "excerpt", "author", "created_at"],
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Omit** – exclude certain fields:
|
||||||
|
|
||||||
|
```json5
|
||||||
|
{
|
||||||
|
name: "blog_post_light",
|
||||||
|
extends: "blog_post",
|
||||||
|
omit: ["body"],
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Partial** – make all inherited fields optional:
|
||||||
|
|
||||||
|
```json5
|
||||||
|
{
|
||||||
|
name: "blog_post_patch",
|
||||||
|
extends: "blog_post",
|
||||||
|
partial: true,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Reusable partials (useFields)
|
||||||
|
|
||||||
|
Define shared field groups once and reuse in multiple types:
|
||||||
|
|
||||||
|
1. **Reusable schema** – e.g. `types/component_layout.json5` with `reusable: true` and only the shared fields (e.g. `mobile`, `tablet`, `desktop`, `spaceBottom`).
|
||||||
|
2. **Reference in type** – on an object field: `type: "object"`, `useFields: "component_layout"`. On load, the partial’s fields are inlined.
|
||||||
|
|
||||||
|
This keeps layout in one place and reuses it in Markdown, Headline, etc.
|
||||||
|
|
||||||
|
### Strict mode
|
||||||
|
|
||||||
|
In strict mode, unknown fields are rejected:
|
||||||
|
|
||||||
|
```json5
|
||||||
|
{
|
||||||
|
name: "product",
|
||||||
|
strict: true,
|
||||||
|
fields: {
|
||||||
|
title: { type: "string", required: true },
|
||||||
|
price: { type: "number", required: true, min: 0 },
|
||||||
|
sku: { type: "string", required: true, unique: true, pattern: "^[A-Z]{2,4}-\\d{3,6}$" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Creating content
|
||||||
|
|
||||||
|
### Via files
|
||||||
|
|
||||||
|
Add a `.json5` file under `content/<type>/`. The filename becomes the slug:
|
||||||
|
|
||||||
|
```json5
|
||||||
|
// content/product/laptop-pro.json5
|
||||||
|
{
|
||||||
|
title: "Laptop Pro 16",
|
||||||
|
sku: "EL-1001",
|
||||||
|
price: 1499.99,
|
||||||
|
category: "electronics",
|
||||||
|
images: ["laptop-front.jpg", "laptop-side.jpg"],
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Via API
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:3000/api/content/product \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"_slug": "keyboard-mx",
|
||||||
|
"title": "Keyboard MX",
|
||||||
|
"sku": "EL-2000",
|
||||||
|
"price": 79.99,
|
||||||
|
"category": "electronics",
|
||||||
|
"images": ["keyboard.jpg"]
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
`_slug` sets the filename. Fields with `default` or `auto` are set automatically.
|
||||||
|
|
||||||
|
**Note:** If `RUSTYCMS_API_KEY` is set, POST/PUT/DELETE must send the key – see section “Optional API auth”.
|
||||||
|
|
||||||
|
## REST API
|
||||||
|
|
||||||
|
### Overview
|
||||||
|
|
||||||
|
| Method | Endpoint | Description |
|
||||||
|
|----------|-----------------------------|--------------------------------|
|
||||||
|
| `GET` | `/api/collections` | List all content types |
|
||||||
|
| `GET` | `/api/collections/:type` | Get schema for a type |
|
||||||
|
| `GET` | `/api/content/:type` | List all entries |
|
||||||
|
| `GET` | `/api/content/:type/:slug` | Get single entry |
|
||||||
|
| `POST` | `/api/content/:type` | Create entry |
|
||||||
|
| `PUT` | `/api/content/:type/:slug` | Update entry |
|
||||||
|
| `DELETE` | `/api/content/:type/:slug` | Delete entry |
|
||||||
|
| `GET` | `/api` or `/api/` | API index (living docs: links to Swagger UI + endpoint overview) |
|
||||||
|
| `GET` | `/swagger-ui` | Swagger UI |
|
||||||
|
| `GET` | `/api-docs/openapi.json` | OpenAPI 3.0 spec |
|
||||||
|
| `GET` | `/api/transform` | Transform image from external URL (resize, crop, format) |
|
||||||
|
| `GET` | `/health` | Health check (e.g. for K8s/Docker), always 200 + `{"status":"ok"}` |
|
||||||
|
|
||||||
|
### Image transformation (external URLs)
|
||||||
|
|
||||||
|
`GET /api/transform` loads an image from an external URL and returns it transformed. Parameters:
|
||||||
|
|
||||||
|
| Parameter | Alias | Description |
|
||||||
|
|---------------|-------|-------------|
|
||||||
|
| `url` | – | **Required.** External image URL (e.g. HTTPS). |
|
||||||
|
| `width` | `w` | Target width in pixels. |
|
||||||
|
| `height` | `h` | Target height in pixels. |
|
||||||
|
| `aspect_ratio`| `ar` | Aspect ratio before resize, e.g. `1:1` or `16:9` (center crop). |
|
||||||
|
| `fit` | – | `fill` (exact w×h), `contain` (keep aspect ratio), `cover` (fill with crop). When **w and h** are set: default `fill`; otherwise default `contain`. |
|
||||||
|
| `format` | – | Output: `jpeg`, `png`, `webp` or `avif`. Default: `jpeg`. (WebP = lossless; AVIF at default quality.) |
|
||||||
|
| `quality` | – | JPEG quality 1–100. Default: 85. |
|
||||||
|
|
||||||
|
Example: 50×50 square from any image:
|
||||||
|
`GET /api/transform?url=https://example.com/image.jpg&w=50&h=50&ar=1:1`
|
||||||
|
|
||||||
|
**Caching:** Identical requests (same URL + same params) are served from memory when response cache is enabled (`RUSTYCMS_CACHE_TTL_SECS` > 0) until TTL expires (no re-download/resize).
|
||||||
|
|
||||||
|
### ETags (conditional GET)
|
||||||
|
|
||||||
|
`GET /api/content/:type/:slug` sets an **ETag** header (content hash). If the client sends **If-None-Match** with that value and the content is unchanged, the API responds with **304 Not Modified** (no body) – saves bandwidth and load.
|
||||||
|
|
||||||
|
### Resolving references (_resolve)
|
||||||
|
|
||||||
|
Reference fields return only `{ "_type": "collection", "_slug": "slug" }` by default. With the `_resolve` query parameter you can **embed** referenced entries:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Resolve all references (e.g. page with Markdown blocks, banner)
|
||||||
|
GET /api/content/page/contact?_resolve=all
|
||||||
|
|
||||||
|
# Resolve only a specific field
|
||||||
|
GET /api/content/page/home?_resolve=row1Content
|
||||||
|
```
|
||||||
|
|
||||||
|
Response then includes the full object in `row1Content` instead of just `{ _type, _slug }`.
|
||||||
|
|
||||||
|
### Filtering
|
||||||
|
|
||||||
|
Exact match: `?field=value`. Suffixes are also supported:
|
||||||
|
|
||||||
|
- `?title_prefix=Hello` – title starts with “Hello”
|
||||||
|
- `?body_contains=rust` – body contains “rust”
|
||||||
|
- `?price_min=10` – number/string >= 10
|
||||||
|
- `?price_max=100` – number/string <= 100
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GET /api/content/blog_post?published=true
|
||||||
|
GET /api/content/blog_post?title_prefix=Intro
|
||||||
|
GET /api/content/product?category=electronics&price_min=50
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sorting
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GET /api/content/blog_post?_sort=created_at&_order=desc
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pagination
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GET /api/content/blog_post?_page=2&_per_page=10
|
||||||
|
```
|
||||||
|
|
||||||
|
Response:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"items": [ ... ],
|
||||||
|
"total": 42,
|
||||||
|
"page": 2,
|
||||||
|
"per_page": 10,
|
||||||
|
"total_pages": 5
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Validation
|
||||||
|
|
||||||
|
The API validates automatically against the schema:
|
||||||
|
|
||||||
|
```
|
||||||
|
POST with title: 123 → "Expected type 'string', got 'number'"
|
||||||
|
POST without required field → "Field is required"
|
||||||
|
POST with sku: "bad" → "Value does not match pattern '^[A-Z]{2,4}-\\d{3,6}$'"
|
||||||
|
POST with price: -5 → "Value -5 is below minimum 0"
|
||||||
|
POST with duplicate SKU → "Value must be unique"
|
||||||
|
POST with unknown field → "Unknown field (strict mode is enabled)"
|
||||||
|
PUT with changed readonly → "Field is readonly and cannot be changed"
|
||||||
|
POST with title: null → "Field does not allow null"
|
||||||
|
POST with rating: null → OK (nullable: true)
|
||||||
|
POST with images: [] → "Array too short (min 1 items)"
|
||||||
|
POST with excerpt (501 chars)→ "String too long (max 500 characters)"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Store: file vs SQLite
|
||||||
|
|
||||||
|
By default the **file store** is used: each collection is a subdirectory under `content/`, each entry a `.json5` file.
|
||||||
|
|
||||||
|
You can switch to **SQLite** – same REST API, same schemas, different backing store (one table with `collection`, `slug`, JSON `data`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
RUSTYCMS_STORE=sqlite RUSTYCMS_DATABASE_URL=sqlite:content.db cargo run
|
||||||
|
```
|
||||||
|
|
||||||
|
The database file is created when needed (`create_if_missing`). Useful for larger setups, concurrent writers, or when you want content in a database.
|
||||||
|
|
||||||
|
## Optional API auth
|
||||||
|
|
||||||
|
If you set `RUSTYCMS_API_KEY` (e.g. in `.env`), **POST, PUT and DELETE** require a valid key. **GET** stays public (read without auth).
|
||||||
|
|
||||||
|
**Send the key** – one of:
|
||||||
|
|
||||||
|
- Header: `Authorization: Bearer <your-api-key>`
|
||||||
|
- Header: `X-API-Key: <your-api-key>`
|
||||||
|
|
||||||
|
**Example with curl:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Without key → 401 Unauthorized
|
||||||
|
curl -X POST http://localhost:3000/api/content/tag -H "Content-Type: application/json" -d '{"_slug":"x","name":"y"}'
|
||||||
|
|
||||||
|
# With key → 201 Created (or validation error)
|
||||||
|
curl -X POST http://localhost:3000/api/content/tag \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "X-API-Key: your-secret-token" \
|
||||||
|
-d '{"_slug":"x","name":"y"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
If `RUSTYCMS_API_KEY` is **not** set, all endpoints behave as before without auth.
|
||||||
|
|
||||||
|
## Swagger UI
|
||||||
|
|
||||||
|
Auto-generated interactive API documentation:
|
||||||
|
|
||||||
|
```
|
||||||
|
http://localhost:3000/swagger-ui
|
||||||
|
```
|
||||||
|
|
||||||
|
The OpenAPI spec is generated at startup from the schemas – including all constraints (minLength, pattern, min/max, nullable, readOnly, …). The spec can also be fetched directly; it is served with cache headers so clients can cache it:
|
||||||
|
|
||||||
|
```
|
||||||
|
http://localhost:3000/api-docs/openapi.json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Schema hot-reload:** Changes in `types/*.json5` are watched – after saving, schemas and the OpenAPI spec are reloaded automatically without restarting the server.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
| Problem | Possible cause |
|
||||||
|
|--------|-----------------|
|
||||||
|
| `Collection 'xyz' not found` | Type does not exist or path typo. Check `GET /api/collections`. |
|
||||||
|
| `Field '_slug' is required` | POST must include `_slug` in the JSON body. |
|
||||||
|
| `Missing or invalid API key` | `RUSTYCMS_API_KEY` is set; POST/PUT/DELETE need header `Authorization: Bearer <key>` or `X-API-Key: <key>`. |
|
||||||
|
| `Entry 'slug' not found` | Slug misspelled or entry not present in the collection. |
|
||||||
|
| Validation errors (type, pattern, unique, …) | Check request body: types, required fields, patterns and uniqueness per schema. |
|
||||||
|
|
||||||
|
## Operation
|
||||||
|
|
||||||
|
- **Graceful shutdown:** On SIGINT (Ctrl+C) or SIGTERM (e.g. K8s), in-flight requests are completed, then the server exits cleanly.
|
||||||
|
|
||||||
|
## Logging
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Default (info)
|
||||||
|
cargo run
|
||||||
|
|
||||||
|
# Debug
|
||||||
|
RUST_LOG=rustycms=debug,tower_http=debug cargo run
|
||||||
|
|
||||||
|
# Warnings only
|
||||||
|
RUST_LOG=warn cargo run
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
||||||
41
admin-ui/.gitignore
vendored
Normal file
41
admin-ui/.gitignore
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.*
|
||||||
|
.yarn/*
|
||||||
|
!.yarn/patches
|
||||||
|
!.yarn/plugins
|
||||||
|
!.yarn/releases
|
||||||
|
!.yarn/versions
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# next.js
|
||||||
|
/.next/
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# env files (can opt-in for committing if needed)
|
||||||
|
.env*
|
||||||
|
|
||||||
|
# vercel
|
||||||
|
.vercel
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
next-env.d.ts
|
||||||
36
admin-ui/README.md
Normal file
36
admin-ui/README.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
First, run the development server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev
|
||||||
|
# or
|
||||||
|
yarn dev
|
||||||
|
# or
|
||||||
|
pnpm dev
|
||||||
|
# or
|
||||||
|
bun dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||||
|
|
||||||
|
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||||
|
|
||||||
|
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||||
|
|
||||||
|
## Learn More
|
||||||
|
|
||||||
|
To learn more about Next.js, take a look at the following resources:
|
||||||
|
|
||||||
|
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||||
|
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||||
|
|
||||||
|
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
||||||
|
|
||||||
|
## Deploy on Vercel
|
||||||
|
|
||||||
|
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||||
|
|
||||||
|
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
||||||
18
admin-ui/eslint.config.mjs
Normal file
18
admin-ui/eslint.config.mjs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { defineConfig, globalIgnores } from "eslint/config";
|
||||||
|
import nextVitals from "eslint-config-next/core-web-vitals";
|
||||||
|
import nextTs from "eslint-config-next/typescript";
|
||||||
|
|
||||||
|
const eslintConfig = defineConfig([
|
||||||
|
...nextVitals,
|
||||||
|
...nextTs,
|
||||||
|
// Override default ignores of eslint-config-next.
|
||||||
|
globalIgnores([
|
||||||
|
// Default ignores of eslint-config-next:
|
||||||
|
".next/**",
|
||||||
|
"out/**",
|
||||||
|
"build/**",
|
||||||
|
"next-env.d.ts",
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export default eslintConfig;
|
||||||
7
admin-ui/next.config.ts
Normal file
7
admin-ui/next.config.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
|
const nextConfig: NextConfig = {
|
||||||
|
/* config options here */
|
||||||
|
};
|
||||||
|
|
||||||
|
export default nextConfig;
|
||||||
7752
admin-ui/package-lock.json
generated
Normal file
7752
admin-ui/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
admin-ui/package.json
Normal file
29
admin-ui/package.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "admin-ui",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "next dev -p 2001",
|
||||||
|
"build": "next build",
|
||||||
|
"start": "next start",
|
||||||
|
"lint": "eslint"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@tanstack/react-query": "^5.90.21",
|
||||||
|
"next": "16.1.6",
|
||||||
|
"react": "19.2.3",
|
||||||
|
"react-dom": "19.2.3",
|
||||||
|
"react-hook-form": "^7.71.1",
|
||||||
|
"react-markdown": "^10.1.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tailwindcss/postcss": "^4",
|
||||||
|
"@types/node": "^20",
|
||||||
|
"@types/react": "^19",
|
||||||
|
"@types/react-dom": "^19",
|
||||||
|
"eslint": "^9",
|
||||||
|
"eslint-config-next": "16.1.6",
|
||||||
|
"tailwindcss": "^4",
|
||||||
|
"typescript": "^5"
|
||||||
|
}
|
||||||
|
}
|
||||||
7
admin-ui/postcss.config.mjs
Normal file
7
admin-ui/postcss.config.mjs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
const config = {
|
||||||
|
plugins: {
|
||||||
|
"@tailwindcss/postcss": {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
1
admin-ui/public/file.svg
Normal file
1
admin-ui/public/file.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||||
|
After Width: | Height: | Size: 391 B |
1
admin-ui/public/globe.svg
Normal file
1
admin-ui/public/globe.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||||
|
After Width: | Height: | Size: 1.0 KiB |
1
admin-ui/public/next.svg
Normal file
1
admin-ui/public/next.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||||
|
After Width: | Height: | Size: 1.3 KiB |
1
admin-ui/public/vercel.svg
Normal file
1
admin-ui/public/vercel.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||||
|
After Width: | Height: | Size: 128 B |
1
admin-ui/public/window.svg
Normal file
1
admin-ui/public/window.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||||
|
After Width: | Height: | Size: 385 B |
292
admin-ui/src/app/admin/new-type/page.tsx
Normal file
292
admin-ui/src/app/admin/new-type/page.tsx
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { createSchema, type SchemaDefinition, type FieldDefinition } from "@/lib/api";
|
||||||
|
|
||||||
|
const FIELD_TYPES = [
|
||||||
|
"string",
|
||||||
|
"number",
|
||||||
|
"integer",
|
||||||
|
"boolean",
|
||||||
|
"datetime",
|
||||||
|
"richtext",
|
||||||
|
"html",
|
||||||
|
"markdown",
|
||||||
|
"reference",
|
||||||
|
"array",
|
||||||
|
"object",
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
type FieldRow = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
required: boolean;
|
||||||
|
description: string;
|
||||||
|
collection: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function nextId() {
|
||||||
|
return Math.random().toString(36).slice(2, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function NewTypePage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const [name, setName] = useState("");
|
||||||
|
const [description, setDescription] = useState("");
|
||||||
|
const [category, setCategory] = useState("");
|
||||||
|
const [tagsStr, setTagsStr] = useState("");
|
||||||
|
const [strict, setStrict] = useState(false);
|
||||||
|
const [fields, setFields] = useState<FieldRow[]>([
|
||||||
|
{ id: nextId(), name: "title", type: "string", required: true, description: "", collection: "" },
|
||||||
|
]);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
|
||||||
|
const addField = () => {
|
||||||
|
setFields((prev) => [
|
||||||
|
...prev,
|
||||||
|
{ id: nextId(), name: "", type: "string", required: false, description: "", collection: "" },
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeField = (id: string) => {
|
||||||
|
setFields((prev) => (prev.length <= 1 ? prev : prev.filter((f) => f.id !== id)));
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateField = (id: string, patch: Partial<FieldRow>) => {
|
||||||
|
setFields((prev) =>
|
||||||
|
prev.map((f) => (f.id === id ? { ...f, ...patch } : f))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setError(null);
|
||||||
|
const nameTrim = name.trim().toLowerCase().replace(/\s+/g, "_");
|
||||||
|
if (!nameTrim) {
|
||||||
|
setError("Name is required.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!/^[a-z0-9_]+$/.test(nameTrim)) {
|
||||||
|
setError("Name: only lowercase letters, digits and underscores.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const fieldNames = fields.map((f) => f.name.trim()).filter(Boolean);
|
||||||
|
if (fieldNames.length === 0) {
|
||||||
|
setError("At least one field required.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const unique = new Set(fieldNames);
|
||||||
|
if (unique.size !== fieldNames.length) {
|
||||||
|
setError("Field names must be unique.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldsObj: Record<string, FieldDefinition> = {};
|
||||||
|
for (const row of fields) {
|
||||||
|
const fn = row.name.trim();
|
||||||
|
if (!fn) continue;
|
||||||
|
const def: FieldDefinition = {
|
||||||
|
type: row.type,
|
||||||
|
required: row.required,
|
||||||
|
description: row.description.trim() || undefined,
|
||||||
|
collection: row.type === "reference" && row.collection.trim() ? row.collection.trim() : undefined,
|
||||||
|
};
|
||||||
|
fieldsObj[fn] = def;
|
||||||
|
}
|
||||||
|
|
||||||
|
const schema: SchemaDefinition = {
|
||||||
|
name: nameTrim,
|
||||||
|
description: description.trim() || undefined,
|
||||||
|
category: category.trim() || undefined,
|
||||||
|
tags: tagsStr.trim() ? tagsStr.split(",").map((t) => t.trim()).filter(Boolean) : undefined,
|
||||||
|
strict,
|
||||||
|
reusable: false,
|
||||||
|
fields: fieldsObj,
|
||||||
|
};
|
||||||
|
|
||||||
|
setSubmitting(true);
|
||||||
|
try {
|
||||||
|
await createSchema(schema);
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ["collections"] });
|
||||||
|
router.push(`/content/${nameTrim}`);
|
||||||
|
router.refresh();
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : "Error creating type.");
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="max-w-2xl">
|
||||||
|
<h1 className="mb-6 text-2xl font-semibold text-gray-900">Add new type</h1>
|
||||||
|
<p className="mb-6 text-sm text-gray-600">
|
||||||
|
Creates a new content type (collection). The schema file is saved on the server at{" "}
|
||||||
|
<code className="rounded bg-gray-100 px-1">types/<name>.json</code> and loaded via hot-reload.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-6">
|
||||||
|
{error && (
|
||||||
|
<div className="rounded-lg bg-red-50 p-3 text-sm text-red-700">{error}</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="mb-1 block text-sm font-medium text-gray-700">
|
||||||
|
Name <span className="text-red-500">*</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)}
|
||||||
|
placeholder="e.g. product, blog_post"
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<p className="mt-0.5 text-xs text-gray-500">
|
||||||
|
Lowercase letters, digits and underscores only.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="mb-1 block text-sm font-medium text-gray-700">Description</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={description}
|
||||||
|
onChange={(e) => setDescription(e.target.value)}
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
|
<div>
|
||||||
|
<label className="mb-1 block text-sm font-medium text-gray-700">Category</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={category}
|
||||||
|
onChange={(e) => setCategory(e.target.value)}
|
||||||
|
placeholder="e.g. content"
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="mb-1 block text-sm font-medium text-gray-700">Tags (comma-separated)</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={tagsStr}
|
||||||
|
onChange={(e) => setTagsStr(e.target.value)}
|
||||||
|
placeholder="e.g. content, blog"
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="strict"
|
||||||
|
checked={strict}
|
||||||
|
onChange={(e) => setStrict(e.target.checked)}
|
||||||
|
className="h-4 w-4 rounded border-gray-300"
|
||||||
|
/>
|
||||||
|
<label htmlFor="strict" className="text-sm text-gray-700">
|
||||||
|
Strict (reject unknown fields)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div className="mb-2 flex items-center justify-between">
|
||||||
|
<label className="text-sm font-medium text-gray-700">Fields</label>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={addField}
|
||||||
|
className="rounded border border-gray-300 bg-white px-2 py-1 text-sm text-gray-700 hover:bg-gray-50"
|
||||||
|
>
|
||||||
|
+ Add field
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-3 rounded-lg border border-gray-200 bg-gray-50/50 p-4">
|
||||||
|
{fields.map((f) => (
|
||||||
|
<div
|
||||||
|
key={f.id}
|
||||||
|
className="grid gap-2 rounded border border-gray-200 bg-white p-3 sm:grid-cols-[1fr_1fr_auto_auto]"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={f.name}
|
||||||
|
onChange={(e) => updateField(f.id, { name: e.target.value })}
|
||||||
|
placeholder="Field name"
|
||||||
|
className="rounded border border-gray-300 px-2 py-1.5 text-sm"
|
||||||
|
/>
|
||||||
|
<select
|
||||||
|
value={f.type}
|
||||||
|
onChange={(e) => updateField(f.id, { type: e.target.value })}
|
||||||
|
className="rounded border border-gray-300 px-2 py-1.5 text-sm"
|
||||||
|
>
|
||||||
|
{FIELD_TYPES.map((t) => (
|
||||||
|
<option key={t} value={t}>
|
||||||
|
{t}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<label className="flex items-center gap-1 text-sm">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={f.required}
|
||||||
|
onChange={(e) => updateField(f.id, { required: e.target.checked })}
|
||||||
|
className="h-4 w-4 rounded border-gray-300"
|
||||||
|
/>
|
||||||
|
Required
|
||||||
|
</label>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => removeField(f.id)}
|
||||||
|
className="rounded px-2 py-1 text-sm text-red-600 hover:bg-red-50"
|
||||||
|
title="Remove field"
|
||||||
|
>
|
||||||
|
Entfernen
|
||||||
|
</button>
|
||||||
|
{f.type === "reference" && (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={f.collection}
|
||||||
|
onChange={(e) => updateField(f.id, { collection: e.target.value })}
|
||||||
|
placeholder="Collection (e.g. page)"
|
||||||
|
className="sm:col-span-2 rounded border border-gray-300 px-2 py-1.5 text-sm"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={f.description}
|
||||||
|
onChange={(e) => updateField(f.id, { description: e.target.value })}
|
||||||
|
placeholder="Field description (optional)"
|
||||||
|
className="sm:col-span-2 rounded border border-gray-300 px-2 py-1.5 text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex gap-3">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={submitting}
|
||||||
|
className="rounded-lg bg-gray-900 px-4 py-2 text-sm font-medium text-white hover:bg-gray-800 disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{submitting ? "Creating…" : "Create type"}
|
||||||
|
</button>
|
||||||
|
<Link
|
||||||
|
href="/"
|
||||||
|
className="rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
BIN
admin-ui/src/app/favicon.ico
Normal file
BIN
admin-ui/src/app/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
34
admin-ui/src/app/globals.css
Normal file
34
admin-ui/src/app/globals.css
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--background: #ffffff;
|
||||||
|
--foreground: #171717;
|
||||||
|
}
|
||||||
|
|
||||||
|
@theme inline {
|
||||||
|
--color-background: var(--background);
|
||||||
|
--color-foreground: var(--foreground);
|
||||||
|
--font-sans: var(--font-geist-sans);
|
||||||
|
--font-mono: var(--font-geist-mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--background: #0a0a0a;
|
||||||
|
--foreground: #ededed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: var(--background);
|
||||||
|
color: var(--foreground);
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lesbare Eingabefelder: dunkler Text, heller Hintergrund */
|
||||||
|
input:not([type="checkbox"]):not([type="radio"]),
|
||||||
|
textarea,
|
||||||
|
select {
|
||||||
|
color: #111827; /* gray-900 */
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
41
admin-ui/src/app/layout.tsx
Normal file
41
admin-ui/src/app/layout.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import type { Metadata } from "next";
|
||||||
|
import { Geist, Geist_Mono } from "next/font/google";
|
||||||
|
import { Providers } from "./providers";
|
||||||
|
import { Sidebar } from "@/components/Sidebar";
|
||||||
|
import "./globals.css";
|
||||||
|
|
||||||
|
const geistSans = Geist({
|
||||||
|
variable: "--font-geist-sans",
|
||||||
|
subsets: ["latin"],
|
||||||
|
});
|
||||||
|
|
||||||
|
const geistMono = Geist_Mono({
|
||||||
|
variable: "--font-geist-mono",
|
||||||
|
subsets: ["latin"],
|
||||||
|
});
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "RustyCMS Admin",
|
||||||
|
description: "RustyCMS admin interface",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function RootLayout({
|
||||||
|
children,
|
||||||
|
}: Readonly<{
|
||||||
|
children: React.ReactNode;
|
||||||
|
}>) {
|
||||||
|
return (
|
||||||
|
<html lang="en">
|
||||||
|
<body
|
||||||
|
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||||
|
>
|
||||||
|
<Providers>
|
||||||
|
<div className="flex h-screen overflow-hidden bg-white">
|
||||||
|
<Sidebar />
|
||||||
|
<main className="min-h-0 flex-1 overflow-auto p-6">{children}</main>
|
||||||
|
</div>
|
||||||
|
</Providers>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
43
admin-ui/src/app/page.tsx
Normal file
43
admin-ui/src/app/page.tsx
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { fetchCollections } from "@/lib/api";
|
||||||
|
|
||||||
|
export default async function DashboardPage() {
|
||||||
|
let collections: { name: string }[] = [];
|
||||||
|
try {
|
||||||
|
const res = await fetchCollections();
|
||||||
|
collections = res.collections ?? [];
|
||||||
|
} catch {
|
||||||
|
// API unreachable etc.
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1 className="mb-6 text-2xl font-semibold text-gray-900">Dashboard</h1>
|
||||||
|
<p className="mb-6 text-gray-600">
|
||||||
|
Choose a collection to manage content.
|
||||||
|
</p>
|
||||||
|
<ul className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||||
|
{collections.map((c) => (
|
||||||
|
<li key={c.name}>
|
||||||
|
<Link
|
||||||
|
href={`/content/${c.name}`}
|
||||||
|
className="block rounded-lg border border-gray-200 bg-gray-50 px-4 py-3 font-medium text-gray-900 hover:border-gray-300 hover:bg-gray-100"
|
||||||
|
>
|
||||||
|
{c.name}
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
{collections.length === 0 && (
|
||||||
|
<p className="text-gray-500">
|
||||||
|
No collections loaded. Check that the RustyCMS API is running at{" "}
|
||||||
|
<code className="rounded bg-gray-100 px-1">
|
||||||
|
{process.env.NEXT_PUBLIC_RUSTYCMS_API_URL ??
|
||||||
|
"http://127.0.0.1:3000"}
|
||||||
|
</code>
|
||||||
|
.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
18
admin-ui/src/app/providers.tsx
Normal file
18
admin-ui/src/app/providers.tsx
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
export function Providers({ children }: { children: React.ReactNode }) {
|
||||||
|
const [client] = useState(
|
||||||
|
() =>
|
||||||
|
new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: { staleTime: 60 * 1000 },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<QueryClientProvider client={client}>{children}</QueryClientProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
632
admin-ui/src/components/ContentForm.tsx
Normal file
632
admin-ui/src/components/ContentForm.tsx
Normal file
@@ -0,0 +1,632 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useId } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useForm, Controller } from "react-hook-form";
|
||||||
|
import type { SchemaDefinition, FieldDefinition } from "@/lib/api";
|
||||||
|
import { checkSlug } from "@/lib/api";
|
||||||
|
import { ReferenceArrayField } from "./ReferenceArrayField";
|
||||||
|
import { MarkdownEditor } from "./MarkdownEditor";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
collection: string;
|
||||||
|
schema: SchemaDefinition;
|
||||||
|
initialValues?: Record<string, unknown>;
|
||||||
|
slug?: string;
|
||||||
|
locale?: string;
|
||||||
|
onSuccess?: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** _slug field with format and duplicate check via API. */
|
||||||
|
function SlugField({
|
||||||
|
collection,
|
||||||
|
currentSlug,
|
||||||
|
locale,
|
||||||
|
register,
|
||||||
|
setError,
|
||||||
|
clearErrors,
|
||||||
|
error,
|
||||||
|
}: {
|
||||||
|
collection: string;
|
||||||
|
currentSlug?: string;
|
||||||
|
locale?: string;
|
||||||
|
register: ReturnType<typeof useForm>["register"];
|
||||||
|
setError: ReturnType<typeof useForm>["setError"];
|
||||||
|
clearErrors: ReturnType<typeof useForm>["clearErrors"];
|
||||||
|
error: ReturnType<typeof useForm>["formState"]["errors"]["_slug"];
|
||||||
|
}) {
|
||||||
|
const { ref, onChange, onBlur, name } = register("_slug", {
|
||||||
|
required: "Slug is required.",
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleBlur = async (e: React.FocusEvent<HTMLInputElement>) => {
|
||||||
|
onBlur(e);
|
||||||
|
const value = e.target.value?.trim();
|
||||||
|
if (!value) return;
|
||||||
|
try {
|
||||||
|
const res = await checkSlug(collection, value, {
|
||||||
|
exclude: currentSlug ?? undefined,
|
||||||
|
_locale: locale,
|
||||||
|
});
|
||||||
|
if (!res.valid && res.error) {
|
||||||
|
setError("_slug", { type: "server", message: res.error });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!res.available) {
|
||||||
|
setError("_slug", {
|
||||||
|
type: "server",
|
||||||
|
message: "Slug already in use.",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearErrors("_slug");
|
||||||
|
} catch {
|
||||||
|
// Network error etc. – no setError, user will see it on submit
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<label className="mb-1 block text-sm font-medium text-gray-700">
|
||||||
|
_slug <span className="text-red-500">*</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
ref={ref}
|
||||||
|
name={name}
|
||||||
|
onChange={onChange}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
placeholder="e.g. my-post"
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 font-mono"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
<p className="mt-1 text-xs text-gray-500">
|
||||||
|
Lowercase letters (a-z), digits (0-9), hyphens. Spaces become hyphens.
|
||||||
|
</p>
|
||||||
|
{error ? (
|
||||||
|
<p className="mt-1 text-sm text-red-600">{String(error.message)}</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Builds form initial values from API response: references → slug strings, objects recursively. */
|
||||||
|
function buildDefaultValues(
|
||||||
|
schema: SchemaDefinition,
|
||||||
|
initialValues?: Record<string, unknown>,
|
||||||
|
): Record<string, unknown> {
|
||||||
|
const out: Record<string, unknown> = {};
|
||||||
|
const fields = schema.fields ?? {};
|
||||||
|
if (initialValues) {
|
||||||
|
for (const [key, value] of Object.entries(initialValues)) {
|
||||||
|
const def = fields[key] as FieldDefinition | undefined;
|
||||||
|
if (value == null) {
|
||||||
|
out[key] = value;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (def?.type === "reference") {
|
||||||
|
out[key] =
|
||||||
|
typeof value === "object" && value !== null && "_slug" in value
|
||||||
|
? String((value as { _slug?: string })._slug ?? "")
|
||||||
|
: typeof value === "string"
|
||||||
|
? value
|
||||||
|
: "";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
def?.type === "array" &&
|
||||||
|
def.items?.type === "reference" &&
|
||||||
|
Array.isArray(value)
|
||||||
|
) {
|
||||||
|
out[key] = value.map((v) =>
|
||||||
|
typeof v === "object" && v !== null && "_slug" in v
|
||||||
|
? (v as { _slug: string })._slug
|
||||||
|
: String(v),
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
def?.type === "object" &&
|
||||||
|
def.fields &&
|
||||||
|
typeof value === "object" &&
|
||||||
|
value !== null &&
|
||||||
|
!Array.isArray(value)
|
||||||
|
) {
|
||||||
|
out[key] = buildDefaultValues(
|
||||||
|
{ name: key, fields: def.fields as Record<string, FieldDefinition> },
|
||||||
|
value as Record<string, unknown>,
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
out[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const key of Object.keys(fields)) {
|
||||||
|
if (!(key in out)) {
|
||||||
|
const def = fields[key] as FieldDefinition | undefined;
|
||||||
|
if (def?.default !== undefined && def.default !== null) {
|
||||||
|
if (
|
||||||
|
def?.type === "object" &&
|
||||||
|
def.fields &&
|
||||||
|
typeof def.default === "object" &&
|
||||||
|
def.default !== null &&
|
||||||
|
!Array.isArray(def.default)
|
||||||
|
) {
|
||||||
|
out[key] = buildDefaultValues(
|
||||||
|
{
|
||||||
|
name: key,
|
||||||
|
fields: def.fields as Record<string, FieldDefinition>,
|
||||||
|
},
|
||||||
|
def.default as Record<string, unknown>,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
out[key] = def.default;
|
||||||
|
}
|
||||||
|
} else if (def?.type === "boolean") out[key] = false;
|
||||||
|
else if (def?.type === "array")
|
||||||
|
out[key] =
|
||||||
|
(def as FieldDefinition).items?.type === "reference" ? [] : "";
|
||||||
|
else if (def?.type === "object" && def.fields)
|
||||||
|
out[key] = buildDefaultValues(
|
||||||
|
{ name: key, fields: def.fields as Record<string, FieldDefinition> },
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
else out[key] = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ContentForm({
|
||||||
|
collection,
|
||||||
|
schema,
|
||||||
|
initialValues,
|
||||||
|
slug,
|
||||||
|
locale,
|
||||||
|
onSuccess,
|
||||||
|
}: Props) {
|
||||||
|
const router = useRouter();
|
||||||
|
const isEdit = !!slug;
|
||||||
|
const defaultValues = buildDefaultValues(schema, initialValues);
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
setError,
|
||||||
|
clearErrors,
|
||||||
|
control,
|
||||||
|
formState: { errors, isSubmitting },
|
||||||
|
} = useForm({
|
||||||
|
defaultValues,
|
||||||
|
});
|
||||||
|
|
||||||
|
const onSubmit = async (data: Record<string, unknown>) => {
|
||||||
|
const payload: Record<string, unknown> = {};
|
||||||
|
for (const [key, value] of Object.entries(data)) {
|
||||||
|
const def = schema.fields?.[key];
|
||||||
|
if (def?.type === "array" && def.items?.type === "reference") {
|
||||||
|
payload[key] = Array.isArray(value)
|
||||||
|
? value
|
||||||
|
: typeof value === "string"
|
||||||
|
? value
|
||||||
|
.split(/[\n,]+/)
|
||||||
|
.map((s) => s.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
: [];
|
||||||
|
} else {
|
||||||
|
payload[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isEdit) {
|
||||||
|
delete payload._slug;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const params = locale ? { _locale: locale } : {};
|
||||||
|
if (isEdit) {
|
||||||
|
const { updateEntry } = await import("@/lib/api");
|
||||||
|
await updateEntry(collection, slug!, payload, params);
|
||||||
|
onSuccess?.();
|
||||||
|
} else {
|
||||||
|
const { createEntry } = await import("@/lib/api");
|
||||||
|
await createEntry(collection, payload, params);
|
||||||
|
onSuccess?.();
|
||||||
|
const newSlug = payload._slug as string | undefined;
|
||||||
|
const q = locale ? `?_locale=${locale}` : "";
|
||||||
|
if (newSlug) {
|
||||||
|
router.push(
|
||||||
|
`/content/${collection}/${encodeURIComponent(newSlug)}${q}`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
router.push(`/content/${collection}${q}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setError("root", {
|
||||||
|
message: err instanceof Error ? err.message : "Error saving",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const fields = schema.fields ?? {};
|
||||||
|
const slugParam = locale ? `?_locale=${locale}` : "";
|
||||||
|
const showSlugField = !isEdit && !(fields._slug != null);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form onSubmit={handleSubmit(onSubmit)} className="max-w-2xl space-y-4">
|
||||||
|
{errors.root && (
|
||||||
|
<div className="rounded bg-red-50 p-3 text-sm text-red-700">
|
||||||
|
{errors.root.message}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{showSlugField && (
|
||||||
|
<SlugField
|
||||||
|
collection={collection}
|
||||||
|
currentSlug={slug}
|
||||||
|
locale={locale}
|
||||||
|
register={register}
|
||||||
|
setError={setError}
|
||||||
|
clearErrors={clearErrors}
|
||||||
|
error={errors._slug}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{Object.entries(fields).map(([name, def]) =>
|
||||||
|
(def as FieldDefinition).type === "object" &&
|
||||||
|
(def as FieldDefinition).fields ? (
|
||||||
|
<ObjectFieldSet
|
||||||
|
key={name}
|
||||||
|
name={name}
|
||||||
|
def={def as FieldDefinition}
|
||||||
|
register={register}
|
||||||
|
control={control}
|
||||||
|
errors={errors}
|
||||||
|
isEdit={isEdit}
|
||||||
|
locale={locale}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Field
|
||||||
|
key={name}
|
||||||
|
name={name}
|
||||||
|
def={def as FieldDefinition}
|
||||||
|
register={register}
|
||||||
|
control={control}
|
||||||
|
errors={errors}
|
||||||
|
isEdit={isEdit}
|
||||||
|
locale={locale}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
<div className="flex gap-3 pt-4">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
className="rounded-lg bg-gray-900 px-4 py-2 text-sm font-medium text-white hover:bg-gray-800 disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{isSubmitting ? "Saving…" : "Save"}
|
||||||
|
</button>
|
||||||
|
{isEdit && (
|
||||||
|
<a
|
||||||
|
href={`/content/${collection}${slugParam}`}
|
||||||
|
className="rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50"
|
||||||
|
>
|
||||||
|
Back to list
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get error for path "layout.mobile" from errors.layout.mobile */
|
||||||
|
function getFieldError(errors: Record<string, unknown>, name: string): unknown {
|
||||||
|
const parts = name.split(".");
|
||||||
|
let current: unknown = errors;
|
||||||
|
for (const p of parts) {
|
||||||
|
current =
|
||||||
|
current != null && typeof current === "object" && p in current
|
||||||
|
? (current as Record<string, unknown>)[p]
|
||||||
|
: undefined;
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ObjectFieldSet({
|
||||||
|
name,
|
||||||
|
def,
|
||||||
|
register,
|
||||||
|
control,
|
||||||
|
errors,
|
||||||
|
isEdit,
|
||||||
|
locale,
|
||||||
|
}: {
|
||||||
|
name: string;
|
||||||
|
def: FieldDefinition;
|
||||||
|
register: ReturnType<typeof useForm>["register"];
|
||||||
|
control: ReturnType<typeof useForm>["control"];
|
||||||
|
errors: ReturnType<typeof useForm>["formState"]["errors"];
|
||||||
|
isEdit: boolean;
|
||||||
|
locale?: string;
|
||||||
|
}) {
|
||||||
|
const nestedFields = def.fields ?? {};
|
||||||
|
const displayName = name.split(".").pop() ?? name;
|
||||||
|
return (
|
||||||
|
<fieldset className="rounded border border-gray-200 bg-gray-50/50 p-4">
|
||||||
|
<legend className="mb-3 text-sm font-medium text-gray-700">
|
||||||
|
{displayName}
|
||||||
|
</legend>
|
||||||
|
<div className="space-y-4">
|
||||||
|
{Object.entries(nestedFields).map(([subName, subDef]) => (
|
||||||
|
<Field
|
||||||
|
key={subName}
|
||||||
|
name={`${name}.${subName}`}
|
||||||
|
def={subDef as FieldDefinition}
|
||||||
|
register={register}
|
||||||
|
control={control}
|
||||||
|
errors={errors}
|
||||||
|
isEdit={isEdit}
|
||||||
|
locale={locale}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Field({
|
||||||
|
name,
|
||||||
|
def,
|
||||||
|
register,
|
||||||
|
control,
|
||||||
|
errors,
|
||||||
|
isEdit,
|
||||||
|
locale,
|
||||||
|
}: {
|
||||||
|
name: string;
|
||||||
|
def: FieldDefinition;
|
||||||
|
register: ReturnType<typeof useForm>["register"];
|
||||||
|
control: ReturnType<typeof useForm>["control"];
|
||||||
|
errors: ReturnType<typeof useForm>["formState"]["errors"];
|
||||||
|
isEdit: boolean;
|
||||||
|
locale?: string;
|
||||||
|
}) {
|
||||||
|
const type = (def.type ?? "string") as string;
|
||||||
|
const required = !!def.required;
|
||||||
|
const isSlug = name === "_slug";
|
||||||
|
const readonly = isEdit && isSlug;
|
||||||
|
const fieldError = getFieldError(errors as Record<string, unknown>, name);
|
||||||
|
const fieldId = useId();
|
||||||
|
|
||||||
|
const fieldDescription = def.description ? (
|
||||||
|
<p className="mt-0.5 text-xs text-gray-500">{def.description}</p>
|
||||||
|
) : null;
|
||||||
|
|
||||||
|
const label = (
|
||||||
|
<>
|
||||||
|
<label className="mb-1 block text-sm font-bold text-gray-700">
|
||||||
|
{name.split(".").pop()}
|
||||||
|
{required && <span className="text-red-500"> *</span>}
|
||||||
|
</label>
|
||||||
|
{fieldDescription}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (type === "boolean") {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="flex items-start gap-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id={fieldId}
|
||||||
|
{...register(name)}
|
||||||
|
className="mt-0.5 h-5 w-5 rounded border-gray-300 focus:ring-gray-400"
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
htmlFor={fieldId}
|
||||||
|
className="cursor-pointer text-sm font-medium text-gray-700"
|
||||||
|
>
|
||||||
|
{name.split(".").pop()}
|
||||||
|
{required && <span className="text-red-500"> *</span>}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{fieldDescription}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === "number") {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{label}
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
step="any"
|
||||||
|
{...register(name, { valueAsNumber: true, required })}
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900"
|
||||||
|
/>
|
||||||
|
{fieldError ? (
|
||||||
|
<p className="mt-1 text-sm text-red-600">
|
||||||
|
{String((fieldError as { message?: string })?.message)}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === "integer") {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{label}
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
step={1}
|
||||||
|
{...register(name, { valueAsNumber: true, required })}
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900"
|
||||||
|
/>
|
||||||
|
{fieldError ? (
|
||||||
|
<p className="mt-1 text-sm text-red-600">
|
||||||
|
{String((fieldError as { message?: string })?.message)}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Markdown: editor with live preview */
|
||||||
|
if (type === "markdown") {
|
||||||
|
return (
|
||||||
|
<Controller
|
||||||
|
name={name}
|
||||||
|
control={control!}
|
||||||
|
rules={{ required }}
|
||||||
|
render={({ field }) => (
|
||||||
|
<MarkdownEditor
|
||||||
|
value={typeof field.value === "string" ? field.value : ""}
|
||||||
|
onChange={field.onChange}
|
||||||
|
label={label}
|
||||||
|
error={fieldError}
|
||||||
|
required={required}
|
||||||
|
readOnly={readonly}
|
||||||
|
rows={12}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lange Texte: richtext, html → Textarea */
|
||||||
|
if (type === "richtext" || type === "html") {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{label}
|
||||||
|
<textarea
|
||||||
|
{...register(name, { required })}
|
||||||
|
rows={10}
|
||||||
|
readOnly={readonly}
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 font-mono"
|
||||||
|
/>
|
||||||
|
{fieldError ? (
|
||||||
|
<p className="mt-1 text-sm text-red-600">
|
||||||
|
{String((fieldError as { message?: string })?.message)}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === "datetime") {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{label}
|
||||||
|
<input
|
||||||
|
type="datetime-local"
|
||||||
|
{...register(name, { required })}
|
||||||
|
readOnly={readonly}
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900"
|
||||||
|
/>
|
||||||
|
{fieldError ? (
|
||||||
|
<p className="mt-1 text-sm text-red-600">
|
||||||
|
{String((fieldError as { message?: string })?.message)}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === "array" && def.items?.type === "reference") {
|
||||||
|
return (
|
||||||
|
<Controller
|
||||||
|
name={name}
|
||||||
|
control={control!}
|
||||||
|
rules={{ required }}
|
||||||
|
render={({ field }) => (
|
||||||
|
<ReferenceArrayField
|
||||||
|
name={name}
|
||||||
|
def={def}
|
||||||
|
value={Array.isArray(field.value) ? field.value : []}
|
||||||
|
onChange={field.onChange}
|
||||||
|
required={required}
|
||||||
|
error={fieldError}
|
||||||
|
locale={locale}
|
||||||
|
label={label}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === "reference") {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{label}
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
{...register(name, { required })}
|
||||||
|
placeholder="Slug of referenced entry"
|
||||||
|
readOnly={readonly}
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 font-mono"
|
||||||
|
/>
|
||||||
|
{fieldError ? (
|
||||||
|
<p className="mt-1 text-sm text-red-600">
|
||||||
|
{String((fieldError as { message?: string })?.message)}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Nested objects (e.g. file.details, file.details.image) recursively as fieldset */
|
||||||
|
if (type === "object" && def.fields) {
|
||||||
|
return (
|
||||||
|
<ObjectFieldSet
|
||||||
|
name={name}
|
||||||
|
def={def}
|
||||||
|
register={register}
|
||||||
|
control={control}
|
||||||
|
errors={errors}
|
||||||
|
isEdit={isEdit}
|
||||||
|
locale={locale}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// string, default
|
||||||
|
const enumValues = def.enum as string[] | undefined;
|
||||||
|
if (Array.isArray(enumValues) && enumValues.length > 0) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{label}
|
||||||
|
<select
|
||||||
|
{...register(name, { required })}
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900"
|
||||||
|
>
|
||||||
|
<option value="">— Please select —</option>
|
||||||
|
{enumValues.map((v) => (
|
||||||
|
<option key={String(v)} value={String(v)}>
|
||||||
|
{String(v)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
{fieldError ? (
|
||||||
|
<p className="mt-1 text-sm text-red-600">
|
||||||
|
{String((fieldError as { message?: string })?.message)}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{label}
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
{...register(name, { required })}
|
||||||
|
readOnly={readonly}
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900"
|
||||||
|
/>
|
||||||
|
{fieldError ? (
|
||||||
|
<p className="mt-1 text-sm text-red-600">
|
||||||
|
{String((fieldError as { message?: string })?.message)}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
171
admin-ui/src/components/MarkdownEditor.tsx
Normal file
171
admin-ui/src/components/MarkdownEditor.tsx
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useId, useRef } from "react";
|
||||||
|
import ReactMarkdown from "react-markdown";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
value: string;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
label: React.ReactNode;
|
||||||
|
error?: unknown;
|
||||||
|
required?: boolean;
|
||||||
|
readOnly?: boolean;
|
||||||
|
rows?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
function wrapSelection(
|
||||||
|
text: string,
|
||||||
|
start: number,
|
||||||
|
end: number,
|
||||||
|
before: string,
|
||||||
|
after: string
|
||||||
|
): { newText: string; newStart: number; newEnd: number } {
|
||||||
|
const sel = text.slice(start, end);
|
||||||
|
const newText = text.slice(0, start) + before + sel + after + text.slice(end);
|
||||||
|
return {
|
||||||
|
newText,
|
||||||
|
newStart: start + before.length,
|
||||||
|
newEnd: end + before.length,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertAtCursor(
|
||||||
|
text: string,
|
||||||
|
start: number,
|
||||||
|
end: number,
|
||||||
|
placeholder: string,
|
||||||
|
cursorAfter: number
|
||||||
|
): { newText: string; newStart: number; newEnd: number } {
|
||||||
|
const insert = start === end ? placeholder : text.slice(start, end);
|
||||||
|
const newText = text.slice(0, start) + insert + text.slice(end);
|
||||||
|
const newStart = start + (start === end ? cursorAfter : 0);
|
||||||
|
const newEnd = start === end ? newStart : newStart + insert.length;
|
||||||
|
return { newText, newStart, newEnd };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MarkdownEditor({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
label,
|
||||||
|
error,
|
||||||
|
required,
|
||||||
|
readOnly,
|
||||||
|
rows = 12,
|
||||||
|
}: Props) {
|
||||||
|
const id = useId();
|
||||||
|
const previewId = `${id}-preview`;
|
||||||
|
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||||
|
|
||||||
|
const apply = (result: { newText: string; newStart: number; newEnd: number }) => {
|
||||||
|
onChange(result.newText);
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
const el = textareaRef.current;
|
||||||
|
if (el) {
|
||||||
|
el.focus();
|
||||||
|
el.setSelectionRange(result.newStart, result.newEnd);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleToolbar = (before: string, after: string, placeholder = "Text") => {
|
||||||
|
const el = textareaRef.current;
|
||||||
|
if (!el || readOnly) return;
|
||||||
|
const start = el.selectionStart;
|
||||||
|
const end = el.selectionEnd;
|
||||||
|
const result = wrapSelection(el.value, start, end, before, after);
|
||||||
|
if (start === end) {
|
||||||
|
result.newEnd = result.newStart + placeholder.length;
|
||||||
|
}
|
||||||
|
apply(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleInsert = (placeholder: string, cursorOffset: number) => {
|
||||||
|
const el = textareaRef.current;
|
||||||
|
if (!el || readOnly) return;
|
||||||
|
const start = el.selectionStart;
|
||||||
|
const end = el.selectionEnd;
|
||||||
|
apply(insertAtCursor(el.value, start, end, placeholder, cursorOffset));
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{label}
|
||||||
|
{!readOnly && (
|
||||||
|
<div className="mb-1 flex flex-wrap items-center gap-1 rounded border border-gray-200 bg-gray-100 px-2 py-1">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => handleToolbar("**", "**", "bold")}
|
||||||
|
className="rounded px-2 py-1 text-sm font-bold text-gray-700 hover:bg-gray-200"
|
||||||
|
title="Bold"
|
||||||
|
>
|
||||||
|
B
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => handleToolbar("*", "*", "italic")}
|
||||||
|
className="rounded px-2 py-1 text-sm italic text-gray-700 hover:bg-gray-200"
|
||||||
|
title="Italic"
|
||||||
|
>
|
||||||
|
I
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => handleToolbar("`", "`", "code")}
|
||||||
|
className="rounded px-2 py-1 font-mono text-sm text-gray-700 hover:bg-gray-200"
|
||||||
|
title="Code"
|
||||||
|
>
|
||||||
|
</>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => handleInsert("[Link-Text](url)", 10)}
|
||||||
|
className="rounded px-2 py-1 text-sm text-gray-700 hover:bg-gray-200"
|
||||||
|
title="Link"
|
||||||
|
>
|
||||||
|
Link
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => handleInsert("\n- ", 3)}
|
||||||
|
className="rounded px-2 py-1 text-sm text-gray-700 hover:bg-gray-200"
|
||||||
|
title="Bullet list"
|
||||||
|
>
|
||||||
|
• List
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<textarea
|
||||||
|
ref={textareaRef}
|
||||||
|
id={id}
|
||||||
|
value={value ?? ""}
|
||||||
|
onChange={(e) => onChange(e.target.value)}
|
||||||
|
rows={rows}
|
||||||
|
readOnly={readOnly}
|
||||||
|
required={required}
|
||||||
|
aria-describedby={previewId}
|
||||||
|
placeholder="Enter markdown… **bold**, *italic*, [link](url), - list"
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 font-mono focus:border-gray-400 focus:outline-none focus:ring-1 focus:ring-gray-400"
|
||||||
|
/>
|
||||||
|
{error ? (
|
||||||
|
<p className="mt-1 text-sm text-red-600">
|
||||||
|
{String((error as { message?: string })?.message)}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
<div className="mt-3">
|
||||||
|
<span className="mb-1 block text-xs font-medium text-gray-500">
|
||||||
|
Preview
|
||||||
|
</span>
|
||||||
|
<div
|
||||||
|
id={previewId}
|
||||||
|
className="min-h-[120px] rounded border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-800 [&_ul]:list-inside [&_ul]:list-disc [&_ol]:list-inside [&_ol]:list-decimal [&_pre]:overflow-x-auto [&_pre]:rounded [&_pre]:bg-gray-200 [&_pre]:p-2 [&_code]:rounded [&_code]:bg-gray-200 [&_code]:px-1 [&_pre_code]:bg-transparent [&_pre_code]:p-0 [&_h1]:text-lg [&_h1]:font-bold [&_h2]:text-base [&_h2]:font-bold [&_h3]:text-sm [&_h3]:font-bold [&_a]:text-blue-600 [&_a]:underline"
|
||||||
|
>
|
||||||
|
{(value ?? "").trim() ? (
|
||||||
|
<ReactMarkdown>{value}</ReactMarkdown>
|
||||||
|
) : (
|
||||||
|
<span className="text-gray-400">Empty — preview appears as you type.</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
361
admin-ui/src/components/ReferenceArrayField.tsx
Normal file
361
admin-ui/src/components/ReferenceArrayField.tsx
Normal file
@@ -0,0 +1,361 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { fetchContentList, fetchCollections } from "@/lib/api";
|
||||||
|
import type { FieldDefinition } from "@/lib/api";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
name: string;
|
||||||
|
def: FieldDefinition;
|
||||||
|
value: string[] | string;
|
||||||
|
onChange: (value: string[]) => void;
|
||||||
|
required?: boolean;
|
||||||
|
error?: unknown;
|
||||||
|
locale?: string;
|
||||||
|
label: React.ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Referenced collection(s) from schema: single collection or list for polymorphic. */
|
||||||
|
function getCollections(def: FieldDefinition): string[] {
|
||||||
|
const items = def.items as FieldDefinition | undefined;
|
||||||
|
if (!items) return [];
|
||||||
|
if (items.collection) return [items.collection];
|
||||||
|
if (Array.isArray(items.collections) && items.collections.length > 0)
|
||||||
|
return items.collections;
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ReferenceArrayField({
|
||||||
|
name,
|
||||||
|
def,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
required,
|
||||||
|
error,
|
||||||
|
locale,
|
||||||
|
label,
|
||||||
|
}: Props) {
|
||||||
|
const schemaCollections = getCollections(def);
|
||||||
|
const singleCollection =
|
||||||
|
schemaCollections.length === 1 ? schemaCollections[0] : null;
|
||||||
|
const multipleCollections =
|
||||||
|
schemaCollections.length > 1 ? schemaCollections : [];
|
||||||
|
const valueList: string[] = Array.isArray(value)
|
||||||
|
? value
|
||||||
|
: typeof value === "string"
|
||||||
|
? value
|
||||||
|
.split(/[\n,]+/)
|
||||||
|
.map((s) => s.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const [pickedCollection, setPickedCollection] = useState<string>(
|
||||||
|
singleCollection ?? multipleCollections[0] ?? "",
|
||||||
|
);
|
||||||
|
|
||||||
|
const { data: collectionsData } = useQuery({
|
||||||
|
queryKey: ["collections"],
|
||||||
|
queryFn: fetchCollections,
|
||||||
|
enabled: schemaCollections.length === 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
const availableCollections =
|
||||||
|
schemaCollections.length > 0
|
||||||
|
? schemaCollections
|
||||||
|
: (collectionsData?.collections ?? [])
|
||||||
|
.map((c) => c.name)
|
||||||
|
.filter(
|
||||||
|
(n) =>
|
||||||
|
n !== "content_layout" && n !== "component_layout" && n !== "seo",
|
||||||
|
);
|
||||||
|
|
||||||
|
const effectiveCollection = singleCollection ?? pickedCollection;
|
||||||
|
|
||||||
|
const listParams = { _per_page: 200, ...(locale ? { _locale: locale } : {}) };
|
||||||
|
|
||||||
|
const singleQuery = useQuery({
|
||||||
|
queryKey: ["content", effectiveCollection, listParams],
|
||||||
|
queryFn: () => fetchContentList(effectiveCollection!, listParams),
|
||||||
|
enabled: !!effectiveCollection && schemaCollections.length <= 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
const multiQueries = useQuery({
|
||||||
|
queryKey: ["content-multi", multipleCollections, listParams],
|
||||||
|
queryFn: async () => {
|
||||||
|
const results = await Promise.all(
|
||||||
|
multipleCollections.map((coll) => fetchContentList(coll, listParams)),
|
||||||
|
);
|
||||||
|
return multipleCollections.map((coll, i) => ({
|
||||||
|
collection: coll,
|
||||||
|
items: results[i]?.items ?? [],
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
enabled: multipleCollections.length > 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
type OptionItem = { slug: string; collection: string };
|
||||||
|
const options: OptionItem[] =
|
||||||
|
multipleCollections.length > 1 && multiQueries.data
|
||||||
|
? multiQueries.data.flatMap(({ collection: coll, items }) =>
|
||||||
|
(items as { _slug?: string }[])
|
||||||
|
.map((o) => ({
|
||||||
|
slug: String(o._slug ?? ""),
|
||||||
|
collection: coll,
|
||||||
|
}))
|
||||||
|
.filter((o) => o.slug),
|
||||||
|
)
|
||||||
|
: ((singleQuery.data?.items ?? []) as { _slug?: string }[])
|
||||||
|
.map((o) => ({
|
||||||
|
slug: String(o._slug ?? ""),
|
||||||
|
collection: effectiveCollection ?? "",
|
||||||
|
}))
|
||||||
|
.filter((o) => o.slug);
|
||||||
|
|
||||||
|
const isLoading =
|
||||||
|
schemaCollections.length <= 1
|
||||||
|
? singleQuery.isLoading
|
||||||
|
: multiQueries.isLoading;
|
||||||
|
|
||||||
|
const add = (slug: string) => {
|
||||||
|
if (!slug || valueList.includes(slug)) return;
|
||||||
|
onChange([...valueList, slug]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const addFromOption = (optionValue: string) => {
|
||||||
|
const slug = optionValue.includes(":")
|
||||||
|
? optionValue.split(":")[1]!
|
||||||
|
: optionValue;
|
||||||
|
add(slug);
|
||||||
|
};
|
||||||
|
|
||||||
|
const remove = (index: number) => {
|
||||||
|
onChange(valueList.filter((_, i) => i !== index));
|
||||||
|
};
|
||||||
|
|
||||||
|
const move = (index: number, dir: number) => {
|
||||||
|
const next = index + dir;
|
||||||
|
if (next < 0 || next >= valueList.length) return;
|
||||||
|
const copy = [...valueList];
|
||||||
|
const tmp = copy[index];
|
||||||
|
copy[index] = copy[next];
|
||||||
|
copy[next] = tmp;
|
||||||
|
onChange(copy);
|
||||||
|
};
|
||||||
|
|
||||||
|
const collectionsForNew =
|
||||||
|
multipleCollections.length > 1
|
||||||
|
? multipleCollections
|
||||||
|
: effectiveCollection
|
||||||
|
? [effectiveCollection]
|
||||||
|
: [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="mb-1 flex items-center justify-between">
|
||||||
|
<span className="text-sm font-medium text-gray-700">{label}</span>
|
||||||
|
{schemaCollections.length > 0 ? (
|
||||||
|
<span className="text-xs text-gray-500">
|
||||||
|
{schemaCollections.length === 1
|
||||||
|
? `Typ: ${schemaCollections[0]}`
|
||||||
|
: `Typen: ${schemaCollections.join(", ")}`}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Selected entries */}
|
||||||
|
<ul className="mb-2 space-y-1.5">
|
||||||
|
{valueList.map((slug, index) => (
|
||||||
|
<li
|
||||||
|
key={`${slug}-${index}`}
|
||||||
|
className="flex items-center gap-2 rounded border border-gray-200 bg-gray-50 px-3 py-2 text-sm"
|
||||||
|
>
|
||||||
|
<span className="flex-1 font-mono text-gray-900">{slug}</span>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => move(index, -1)}
|
||||||
|
disabled={index === 0}
|
||||||
|
className="rounded p-1 text-gray-500 hover:bg-gray-200 hover:text-gray-700 disabled:opacity-40"
|
||||||
|
title="Move up"
|
||||||
|
aria-label="Move up"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
className="h-4 w-4"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M5 15l7-7 7 7"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => move(index, 1)}
|
||||||
|
disabled={index === valueList.length - 1}
|
||||||
|
className="rounded p-1 text-gray-500 hover:bg-gray-200 hover:text-gray-700 disabled:opacity-40"
|
||||||
|
title="Move down"
|
||||||
|
aria-label="Move down"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
className="h-4 w-4"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M19 9l-7 7-7-7"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => remove(index)}
|
||||||
|
className="rounded p-1 text-red-600 hover:bg-red-50 hover:text-red-700"
|
||||||
|
title="Remove"
|
||||||
|
aria-label="Remove"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
className="h-4 w-4"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M6 18L18 6M6 6l12 12"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{/* Without schema collection: choose component type first */}
|
||||||
|
{!singleCollection &&
|
||||||
|
schemaCollections.length === 0 &&
|
||||||
|
availableCollections.length > 0 ? (
|
||||||
|
<div className="mb-2">
|
||||||
|
<label className="mb-1 block text-xs font-medium text-gray-500">
|
||||||
|
Component type
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
value={pickedCollection}
|
||||||
|
onChange={(e) => setPickedCollection(e.target.value)}
|
||||||
|
className="block w-full rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900"
|
||||||
|
>
|
||||||
|
<option value="">— Select type —</option>
|
||||||
|
{availableCollections.map((c) => (
|
||||||
|
<option key={c} value={c}>
|
||||||
|
{c}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{/* Add: select from existing + create new component */}
|
||||||
|
{effectiveCollection || multipleCollections.length > 1 ? (
|
||||||
|
<div className="flex flex-col gap-2 sm:flex-row sm:items-start">
|
||||||
|
<select
|
||||||
|
value=""
|
||||||
|
onChange={(e) => {
|
||||||
|
const v = e.target.value;
|
||||||
|
if (v) addFromOption(v);
|
||||||
|
e.target.value = "";
|
||||||
|
}}
|
||||||
|
className="block flex-1 rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900"
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
<option value="">— Select from existing —</option>
|
||||||
|
{options.map((item) => {
|
||||||
|
const key =
|
||||||
|
multipleCollections.length > 1
|
||||||
|
? `${item.collection}:${item.slug}`
|
||||||
|
: item.slug;
|
||||||
|
const alreadySelected = valueList.includes(item.slug);
|
||||||
|
const label =
|
||||||
|
multipleCollections.length > 1
|
||||||
|
? `${item.slug} (${item.collection})`
|
||||||
|
: item.slug;
|
||||||
|
return (
|
||||||
|
<option key={key} value={key} disabled={alreadySelected}>
|
||||||
|
{alreadySelected ? `${label} (already selected)` : label}
|
||||||
|
</option>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</select>
|
||||||
|
{collectionsForNew.length > 0 ? (
|
||||||
|
<span className="flex shrink-0 flex-col gap-0.5">
|
||||||
|
{collectionsForNew.length === 1 ? (
|
||||||
|
<Link
|
||||||
|
href={
|
||||||
|
collectionsForNew[0]
|
||||||
|
? `/content/${collectionsForNew[0]}/new${locale ? `?_locale=${locale}` : ""}`
|
||||||
|
: "#"
|
||||||
|
}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="inline-flex items-center justify-center gap-1 rounded border border-gray-300 bg-white px-3 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50"
|
||||||
|
>
|
||||||
|
<span aria-hidden>+</span> New {collectionsForNew[0]} component
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<select
|
||||||
|
className="rounded border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900"
|
||||||
|
value=""
|
||||||
|
onChange={(e) => {
|
||||||
|
const c = e.target.value;
|
||||||
|
if (c)
|
||||||
|
window.open(
|
||||||
|
`/content/${c}/new${locale ? `?_locale=${locale}` : ""}`,
|
||||||
|
"_blank",
|
||||||
|
);
|
||||||
|
e.target.value = "";
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="">+ Create new component…</option>
|
||||||
|
{collectionsForNew.map((c) => (
|
||||||
|
<option key={c} value={c}>
|
||||||
|
{c}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
)}
|
||||||
|
<span className="text-xs text-gray-500">
|
||||||
|
Open in new tab; then reload this page.
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{schemaCollections.length === 0 && availableCollections.length === 0 ? (
|
||||||
|
<p className="text-xs text-amber-600">
|
||||||
|
No reference collection in schema. Set{" "}
|
||||||
|
<code className="rounded bg-gray-100 px-1">items.collection</code> or{" "}
|
||||||
|
<code className="rounded bg-gray-100 px-1">items.collections</code>{" "}
|
||||||
|
in the type, or start the API and reload the page.
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{error ? (
|
||||||
|
<p className="mt-1 text-sm text-red-600">
|
||||||
|
{String((error as { message?: string })?.message ?? error)}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
125
admin-ui/src/components/Sidebar.tsx
Normal file
125
admin-ui/src/components/Sidebar.tsx
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState, useMemo } from "react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
|
import { useQueries, useQuery } from "@tanstack/react-query";
|
||||||
|
import { fetchCollections, fetchContentList } from "@/lib/api";
|
||||||
|
|
||||||
|
export function Sidebar() {
|
||||||
|
const pathname = usePathname();
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
|
const { data, isLoading, error } = useQuery({
|
||||||
|
queryKey: ["collections"],
|
||||||
|
queryFn: fetchCollections,
|
||||||
|
});
|
||||||
|
|
||||||
|
const filteredCollections = useMemo(() => {
|
||||||
|
const list = data?.collections ?? [];
|
||||||
|
if (!search.trim()) return list;
|
||||||
|
const q = search.trim().toLowerCase();
|
||||||
|
return list.filter(
|
||||||
|
(c) =>
|
||||||
|
c.name.toLowerCase().includes(q) ||
|
||||||
|
(c.category?.toLowerCase().includes(q) ?? false) ||
|
||||||
|
(c.tags?.some((t) => t.toLowerCase().includes(q)) ?? false) ||
|
||||||
|
(c.description?.toLowerCase().includes(q) ?? false)
|
||||||
|
);
|
||||||
|
}, [data?.collections, search]);
|
||||||
|
|
||||||
|
const countQueries = useQueries({
|
||||||
|
queries: filteredCollections.map((c) => ({
|
||||||
|
queryKey: ["contentCount", c.name],
|
||||||
|
queryFn: () =>
|
||||||
|
fetchContentList(c.name, { _per_page: 1 }).then((r) => r.total),
|
||||||
|
staleTime: 60_000,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
|
const formatCount = (n: number) => (n >= 100 ? "99+" : String(n));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<aside className="flex h-full w-56 shrink-0 flex-col overflow-y-auto border-r border-gray-200 bg-gray-50 p-4">
|
||||||
|
<nav className="flex flex-col gap-1">
|
||||||
|
<Link
|
||||||
|
href="/"
|
||||||
|
className={`rounded px-3 py-2 text-sm font-bold ${pathname === "/" ? "bg-gray-200 text-gray-900" : "text-gray-600 hover:bg-gray-100 hover:text-gray-900"}`}
|
||||||
|
>
|
||||||
|
Dashboard
|
||||||
|
</Link>
|
||||||
|
<hr />
|
||||||
|
<div className="px-1 py-2">
|
||||||
|
<input
|
||||||
|
type="search"
|
||||||
|
placeholder="Search collections…"
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
|
className="w-full rounded border border-gray-200 bg-white px-2 py-1.5 text-sm text-gray-900 placeholder:text-gray-400 focus:border-gray-300 focus:outline-none focus:ring-1 focus:ring-gray-300"
|
||||||
|
aria-label="Search collections"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{isLoading && (
|
||||||
|
<div className="px-3 py-2 text-sm text-gray-400">Loading…</div>
|
||||||
|
)}
|
||||||
|
{error && (
|
||||||
|
<div className="px-3 py-2 text-sm text-red-600">
|
||||||
|
Error loading collections
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{!isLoading && !error && search.trim() && filteredCollections.length === 0 && (
|
||||||
|
<div className="px-3 py-2 text-sm text-gray-500">
|
||||||
|
No results for "{search.trim()}"
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{filteredCollections.map((c, i) => {
|
||||||
|
const href = `/content/${c.name}`;
|
||||||
|
const active = pathname === href || pathname.startsWith(href + "/");
|
||||||
|
const hasMeta =
|
||||||
|
c.description || (c.tags?.length ?? 0) > 0 || c.category;
|
||||||
|
const countResult = countQueries[i];
|
||||||
|
const count =
|
||||||
|
countResult?.data !== undefined ? countResult.data : null;
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={c.name}
|
||||||
|
href={href}
|
||||||
|
title={c.description ?? undefined}
|
||||||
|
className={`rounded px-3 py-2 text-sm font-medium ${active ? "bg-gray-200 text-gray-900" : "text-gray-600 hover:bg-gray-100 hover:text-gray-900"}`}
|
||||||
|
>
|
||||||
|
<span className="flex items-center justify-between gap-2">
|
||||||
|
<span className="min-w-0 truncate">{c.name}</span>
|
||||||
|
{count !== null && (
|
||||||
|
<span className="shrink-0 text-xs font-normal text-gray-500 tabular-nums">
|
||||||
|
{formatCount(count)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
{hasMeta && (
|
||||||
|
<span className="mt-0.5 block text-xs font-normal text-gray-500">
|
||||||
|
{c.category && (
|
||||||
|
<span className="rounded bg-gray-200 px-1">
|
||||||
|
{c.category}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{c.tags?.length ? (
|
||||||
|
<span className="ml-1">
|
||||||
|
{c.tags.slice(0, 2).join(", ")}
|
||||||
|
{c.tags.length > 2 ? " …" : ""}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
<hr className="my-2" />
|
||||||
|
<Link
|
||||||
|
href="/admin/new-type"
|
||||||
|
className="rounded px-3 py-2 text-sm font-medium text-gray-600 hover:bg-gray-100 hover:text-gray-900"
|
||||||
|
>
|
||||||
|
+ Add new type…
|
||||||
|
</Link>
|
||||||
|
</nav>
|
||||||
|
</aside>
|
||||||
|
);
|
||||||
|
}
|
||||||
222
admin-ui/src/lib/api.ts
Normal file
222
admin-ui/src/lib/api.ts
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
/**
|
||||||
|
* RustyCMS API client. Base URL from NEXT_PUBLIC_RUSTYCMS_API_URL.
|
||||||
|
* Optional RUSTYCMS_API_KEY for write operations (sent as X-API-Key).
|
||||||
|
*/
|
||||||
|
|
||||||
|
const getBaseUrl = () =>
|
||||||
|
process.env.NEXT_PUBLIC_RUSTYCMS_API_URL || "http://127.0.0.1:3000";
|
||||||
|
|
||||||
|
const getHeaders = (): HeadersInit => {
|
||||||
|
const headers: HeadersInit = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
};
|
||||||
|
const key =
|
||||||
|
typeof window !== "undefined"
|
||||||
|
? process.env.NEXT_PUBLIC_RUSTYCMS_API_KEY ?? null
|
||||||
|
: process.env.RUSTYCMS_API_KEY ?? process.env.NEXT_PUBLIC_RUSTYCMS_API_KEY ?? null;
|
||||||
|
if (key) headers["X-API-Key"] = key;
|
||||||
|
return headers;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CollectionMeta = {
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
tags?: string[];
|
||||||
|
category?: string;
|
||||||
|
field_count?: number;
|
||||||
|
extends?: string | string[];
|
||||||
|
strict?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CollectionsResponse = {
|
||||||
|
collections: CollectionMeta[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type FieldDefinition = {
|
||||||
|
type: string;
|
||||||
|
required?: boolean;
|
||||||
|
description?: string;
|
||||||
|
collection?: string;
|
||||||
|
collections?: string[];
|
||||||
|
enum?: unknown[];
|
||||||
|
default?: unknown;
|
||||||
|
items?: FieldDefinition;
|
||||||
|
[key: string]: unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SchemaDefinition = {
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
tags?: string[];
|
||||||
|
category?: string;
|
||||||
|
fields: Record<string, FieldDefinition>;
|
||||||
|
extends?: string | string[];
|
||||||
|
reusable?: boolean;
|
||||||
|
[key: string]: unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ListResponse<T = Record<string, unknown>> = {
|
||||||
|
items: T[];
|
||||||
|
total: number;
|
||||||
|
page: number;
|
||||||
|
per_page: number;
|
||||||
|
total_pages: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function fetchCollections(): Promise<CollectionsResponse> {
|
||||||
|
const res = await fetch(`${getBaseUrl()}/api/collections`, {
|
||||||
|
headers: getHeaders(),
|
||||||
|
});
|
||||||
|
if (!res.ok) throw new Error(`Collections: ${res.status}`);
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchSchema(
|
||||||
|
collection: string
|
||||||
|
): Promise<SchemaDefinition> {
|
||||||
|
const res = await fetch(
|
||||||
|
`${getBaseUrl()}/api/collections/${encodeURIComponent(collection)}`,
|
||||||
|
{ headers: getHeaders() }
|
||||||
|
);
|
||||||
|
if (!res.ok) throw new Error(`Schema ${collection}: ${res.status}`);
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createSchema(
|
||||||
|
schema: SchemaDefinition
|
||||||
|
): Promise<SchemaDefinition> {
|
||||||
|
const res = await fetch(`${getBaseUrl()}/api/schemas`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: getHeaders(),
|
||||||
|
body: JSON.stringify(schema),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
const err = await res.json().catch(() => ({}));
|
||||||
|
const msg = (err as { error?: string }).error ?? (err as { errors?: string[] }).errors?.join(", ") ?? `Schema: ${res.status}`;
|
||||||
|
throw new Error(msg);
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SlugCheckResponse = {
|
||||||
|
valid: boolean;
|
||||||
|
normalized: string;
|
||||||
|
available: boolean;
|
||||||
|
error?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function checkSlug(
|
||||||
|
collection: string,
|
||||||
|
slug: string,
|
||||||
|
params: { exclude?: string; _locale?: string } = {}
|
||||||
|
): Promise<SlugCheckResponse> {
|
||||||
|
const sp = new URLSearchParams({ slug: slug.trim() });
|
||||||
|
if (params.exclude) sp.set("exclude", params.exclude);
|
||||||
|
if (params._locale) sp.set("_locale", params._locale);
|
||||||
|
const res = await fetch(
|
||||||
|
`${getBaseUrl()}/api/collections/${encodeURIComponent(collection)}/slug-check?${sp}`,
|
||||||
|
{ headers: getHeaders() }
|
||||||
|
);
|
||||||
|
if (!res.ok) throw new Error(`Slug-Check: ${res.status}`);
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ContentListParams = {
|
||||||
|
_page?: number;
|
||||||
|
_per_page?: number;
|
||||||
|
_sort?: string;
|
||||||
|
_order?: "asc" | "desc";
|
||||||
|
_resolve?: string;
|
||||||
|
_locale?: string;
|
||||||
|
[key: string]: string | number | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function fetchContentList<T = Record<string, unknown>>(
|
||||||
|
collection: string,
|
||||||
|
params: ContentListParams = {}
|
||||||
|
): Promise<ListResponse<T>> {
|
||||||
|
const sp = new URLSearchParams();
|
||||||
|
Object.entries(params).forEach(([k, v]) => {
|
||||||
|
if (v !== undefined && v !== "") sp.set(k, String(v));
|
||||||
|
});
|
||||||
|
const qs = sp.toString();
|
||||||
|
const url = `${getBaseUrl()}/api/content/${encodeURIComponent(collection)}${qs ? `?${qs}` : ""}`;
|
||||||
|
const res = await fetch(url, { headers: getHeaders() });
|
||||||
|
if (!res.ok) throw new Error(`List ${collection}: ${res.status}`);
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchEntry<T = Record<string, unknown>>(
|
||||||
|
collection: string,
|
||||||
|
slug: string,
|
||||||
|
params: { _resolve?: string; _locale?: string } = {}
|
||||||
|
): Promise<T> {
|
||||||
|
const sp = new URLSearchParams();
|
||||||
|
if (params._resolve) sp.set("_resolve", params._resolve);
|
||||||
|
if (params._locale) sp.set("_locale", params._locale);
|
||||||
|
const qs = sp.toString();
|
||||||
|
const url = `${getBaseUrl()}/api/content/${encodeURIComponent(collection)}/${encodeURIComponent(slug)}${qs ? `?${qs}` : ""}`;
|
||||||
|
const res = await fetch(url, { headers: getHeaders() });
|
||||||
|
if (!res.ok) throw new Error(`Entry ${collection}/${slug}: ${res.status}`);
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createEntry(
|
||||||
|
collection: string,
|
||||||
|
data: Record<string, unknown>,
|
||||||
|
params: { _locale?: string } = {}
|
||||||
|
): Promise<Record<string, unknown>> {
|
||||||
|
const sp = new URLSearchParams();
|
||||||
|
if (params._locale) sp.set("_locale", params._locale);
|
||||||
|
const qs = sp.toString();
|
||||||
|
const url = `${getBaseUrl()}/api/content/${encodeURIComponent(collection)}${qs ? `?${qs}` : ""}`;
|
||||||
|
const res = await fetch(url, {
|
||||||
|
method: "POST",
|
||||||
|
headers: getHeaders(),
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
const err = await res.json().catch(() => ({}));
|
||||||
|
throw new Error((err as { message?: string }).message || `Create: ${res.status}`);
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateEntry(
|
||||||
|
collection: string,
|
||||||
|
slug: string,
|
||||||
|
data: Record<string, unknown>,
|
||||||
|
params: { _locale?: string } = {}
|
||||||
|
): Promise<Record<string, unknown>> {
|
||||||
|
const sp = new URLSearchParams();
|
||||||
|
if (params._locale) sp.set("_locale", params._locale);
|
||||||
|
const qs = sp.toString();
|
||||||
|
const url = `${getBaseUrl()}/api/content/${encodeURIComponent(collection)}/${encodeURIComponent(slug)}${qs ? `?${qs}` : ""}`;
|
||||||
|
const res = await fetch(url, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: getHeaders(),
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
const err = await res.json().catch(() => ({}));
|
||||||
|
throw new Error((err as { message?: string }).message || `Update: ${res.status}`);
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteEntry(
|
||||||
|
collection: string,
|
||||||
|
slug: string,
|
||||||
|
params: { _locale?: string } = {}
|
||||||
|
): Promise<void> {
|
||||||
|
const sp = new URLSearchParams();
|
||||||
|
if (params._locale) sp.set("_locale", params._locale);
|
||||||
|
const qs = sp.toString();
|
||||||
|
const url = `${getBaseUrl()}/api/content/${encodeURIComponent(collection)}/${encodeURIComponent(slug)}${qs ? `?${qs}` : ""}`;
|
||||||
|
const res = await fetch(url, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: getHeaders(),
|
||||||
|
});
|
||||||
|
if (!res.ok) throw new Error(`Delete: ${res.status}`);
|
||||||
|
}
|
||||||
34
admin-ui/tsconfig.json
Normal file
34
admin-ui/tsconfig.json
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2017",
|
||||||
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
|
"allowJs": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"incremental": true,
|
||||||
|
"plugins": [
|
||||||
|
{
|
||||||
|
"name": "next"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./src/*"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"next-env.d.ts",
|
||||||
|
"**/*.ts",
|
||||||
|
"**/*.tsx",
|
||||||
|
".next/types/**/*.ts",
|
||||||
|
".next/dev/types/**/*.ts",
|
||||||
|
"**/*.mts"
|
||||||
|
],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|
||||||
9
content/de/blog_post/mein-erster-post.json5
Normal file
9
content/de/blog_post/mein-erster-post.json5
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
title: "Mein erster Post",
|
||||||
|
body: "Hallo Welt! Das ist **RustyCMS** – ein file-basiertes Headless CMS geschrieben in Rust.",
|
||||||
|
excerpt: "Ein Einstieg in RustyCMS",
|
||||||
|
author: "Peter",
|
||||||
|
tags: ["rust", "cms", "open-source"],
|
||||||
|
published: true,
|
||||||
|
created_at: "2026-02-12T10:00:00Z",
|
||||||
|
}
|
||||||
9
content/de/blog_post/rust-ist-toll.json5
Normal file
9
content/de/blog_post/rust-ist-toll.json5
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
title: "Warum Rust so toll ist",
|
||||||
|
body: "Rust bietet Memory Safety ohne Garbage Collector, ein starkes Typsystem und exzellente Performance.",
|
||||||
|
excerpt: "Eine Liebeserklaerung an Rust",
|
||||||
|
author: "Peter",
|
||||||
|
tags: ["rust", "programming"],
|
||||||
|
published: true,
|
||||||
|
created_at: "2026-02-12T14:30:00Z",
|
||||||
|
}
|
||||||
11
content/de/blog_post/string.json5
Normal file
11
content/de/blog_post/string.json5
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"author": "string",
|
||||||
|
"body": "string",
|
||||||
|
"created_at": "2026-02-12T14:54:13.233374+00:00",
|
||||||
|
"excerpt": "string",
|
||||||
|
"published": false,
|
||||||
|
"tags": [
|
||||||
|
"string"
|
||||||
|
],
|
||||||
|
"title": "string"
|
||||||
|
}
|
||||||
13
content/de/footer/default.json5
Normal file
13
content/de/footer/default.json5
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
_slug: "default",
|
||||||
|
id: "navigation-footer",
|
||||||
|
row1JustifyContent: "center",
|
||||||
|
row1AlignItems: "stretch",
|
||||||
|
row1Content: [],
|
||||||
|
row2JustifyContent: "start",
|
||||||
|
row2AlignItems: "stretch",
|
||||||
|
row2Content: [],
|
||||||
|
row3JustifyContent: "start",
|
||||||
|
row3AlignItems: "stretch",
|
||||||
|
row3Content: [],
|
||||||
|
}
|
||||||
8
content/de/fullwidth_banner/about-hero.json5
Normal file
8
content/de/fullwidth_banner/about-hero.json5
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
name: "Hero Banner About",
|
||||||
|
variant: "light",
|
||||||
|
headline: "Ueber uns",
|
||||||
|
subheadline: "Open Source seit 2026",
|
||||||
|
text: "RustyCMS ist ein Open-Source-Projekt.",
|
||||||
|
image: [],
|
||||||
|
}
|
||||||
8
content/de/fullwidth_banner/hero.json5
Normal file
8
content/de/fullwidth_banner/hero.json5
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
name: "Hero Banner Startseite",
|
||||||
|
variant: "dark",
|
||||||
|
headline: "RustyCMS",
|
||||||
|
subheadline: "Das file-basierte Headless CMS",
|
||||||
|
text: "Typen definieren. Content ablegen. API nutzen.",
|
||||||
|
image: ["https://example.com/images/hero-bg.jpg"],
|
||||||
|
}
|
||||||
13
content/de/headline/headline-referenz.json5
Normal file
13
content/de/headline/headline-referenz.json5
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
_slug: "headline-referenz",
|
||||||
|
internal: "headline-ref",
|
||||||
|
text: "Headline-Komponente (Referenz)",
|
||||||
|
tag: "h2",
|
||||||
|
align: "center",
|
||||||
|
layout: {
|
||||||
|
mobile: "12",
|
||||||
|
tablet: "10",
|
||||||
|
desktop: "8",
|
||||||
|
spaceBottom: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
11
content/de/html/html-referenz.json5
Normal file
11
content/de/html/html-referenz.json5
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
_slug: "html-referenz",
|
||||||
|
id: "html-component-referenz",
|
||||||
|
html: "<p>CF_HTML – <strong>HTML</strong>-Block mit Layout.</p>",
|
||||||
|
layout: {
|
||||||
|
mobile: "12",
|
||||||
|
tablet: "10",
|
||||||
|
desktop: "8",
|
||||||
|
spaceBottom: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
13
content/de/iframe/iframe-referenz.json5
Normal file
13
content/de/iframe/iframe-referenz.json5
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
_slug: "iframe-referenz",
|
||||||
|
name: "Iframe-Komponente (Referenz)",
|
||||||
|
content: "Eingebetteter Inhalt von einer externen URL – z. B. Karte, Formular oder Video.",
|
||||||
|
iframe: "https://example.com/embed",
|
||||||
|
overlayImage: "",
|
||||||
|
layout: {
|
||||||
|
mobile: "12",
|
||||||
|
tablet: "10",
|
||||||
|
desktop: "8",
|
||||||
|
spaceBottom: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
14
content/de/image/image-referenz.json5
Normal file
14
content/de/image/image-referenz.json5
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
_slug: "image-referenz",
|
||||||
|
name: "Bild-Komponente (Referenz)",
|
||||||
|
image: "referenz-bild",
|
||||||
|
caption: "Bildunterschrift: CF_ComponentImage mit Layout und optionaler Caption.",
|
||||||
|
layout: {
|
||||||
|
mobile: "12",
|
||||||
|
tablet: "8",
|
||||||
|
desktop: "6",
|
||||||
|
spaceBottom: 1,
|
||||||
|
},
|
||||||
|
maxWidth: 800,
|
||||||
|
aspectRatio: 1.333,
|
||||||
|
}
|
||||||
12
content/de/image_gallery/gallery-referenz.json5
Normal file
12
content/de/image_gallery/gallery-referenz.json5
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
_slug: "gallery-referenz",
|
||||||
|
name: "Bildgalerie (Referenz)",
|
||||||
|
images: ["referenz-bild"],
|
||||||
|
layout: {
|
||||||
|
mobile: "12",
|
||||||
|
tablet: "12",
|
||||||
|
desktop: "12",
|
||||||
|
spaceBottom: 1.5,
|
||||||
|
},
|
||||||
|
description: "CF_ImageGallery – mehrere Bilder mit gemeinsamem Layout.",
|
||||||
|
}
|
||||||
16
content/de/img/referenz-bild.json5
Normal file
16
content/de/img/referenz-bild.json5
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"description": "Platzhalter für Bild-Komponenten und Galerien",
|
||||||
|
"file": {
|
||||||
|
"contentType": "image/jpeg",
|
||||||
|
"details": {
|
||||||
|
"image": {
|
||||||
|
"height": 600,
|
||||||
|
"width": 800
|
||||||
|
},
|
||||||
|
"size": 12345
|
||||||
|
},
|
||||||
|
"fileName": "referenz-bild.jpg",
|
||||||
|
"url": "https://placehold.co/800x600?text=Referenzbild"
|
||||||
|
},
|
||||||
|
"title": "Referenzbild für Komponenten-Test"
|
||||||
|
}
|
||||||
13
content/de/link/docs.json5
Normal file
13
content/de/link/docs.json5
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
_slug: "docs",
|
||||||
|
name: "Dokumentation",
|
||||||
|
internal: "link-docs",
|
||||||
|
linkName: "Dokumentation",
|
||||||
|
url: "https://example.com/docs",
|
||||||
|
icon: "book",
|
||||||
|
external: false,
|
||||||
|
newTab: false,
|
||||||
|
author: "RustyCMS",
|
||||||
|
date: "2026-02-01",
|
||||||
|
source: "RustyCMS",
|
||||||
|
}
|
||||||
14
content/de/link/gitlab.json5
Normal file
14
content/de/link/gitlab.json5
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
_slug: "gitlab",
|
||||||
|
name: "GitLab",
|
||||||
|
internal: "link-gitlab",
|
||||||
|
linkName: "GitLab",
|
||||||
|
url: "https://gitlab.com/example/rustycms",
|
||||||
|
icon: "gitlab",
|
||||||
|
external: true,
|
||||||
|
newTab: true,
|
||||||
|
description: "Projekt-Repository auf GitLab",
|
||||||
|
author: "RustyCMS",
|
||||||
|
date: "2026-02-01",
|
||||||
|
source: "GitLab",
|
||||||
|
}
|
||||||
5
content/de/link_list/link-list-referenz.json5
Normal file
5
content/de/link_list/link-list-referenz.json5
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
_slug: "link-list-referenz",
|
||||||
|
headline: "Weitere Links",
|
||||||
|
links: ["gitlab", "docs"],
|
||||||
|
}
|
||||||
9
content/de/list/list-referenz.json5
Normal file
9
content/de/list/list-referenz.json5
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
_slug: "list-referenz",
|
||||||
|
internal: "list-ref",
|
||||||
|
item: [
|
||||||
|
"Erster Punkt",
|
||||||
|
"Zweiter Punkt",
|
||||||
|
"Dritter Punkt",
|
||||||
|
],
|
||||||
|
}
|
||||||
11
content/de/markdown/intro.json5
Normal file
11
content/de/markdown/intro.json5
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
name: "Intro-Text Startseite",
|
||||||
|
content: "Dieser Block entspricht dem Typ **Markdown** (CF_Markdown). Du kannst hier *Markdown* oder Fließtext eingeben. Die Row auf der Page referenziert diese Komponente.",
|
||||||
|
layout: {
|
||||||
|
mobile: "12",
|
||||||
|
tablet: "10",
|
||||||
|
desktop: "8",
|
||||||
|
spaceBottom: 1,
|
||||||
|
},
|
||||||
|
alignment: "center",
|
||||||
|
}
|
||||||
12
content/de/markdown/komponenten-referenz-intro.json5
Normal file
12
content/de/markdown/komponenten-referenz-intro.json5
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
_slug: "komponenten-referenz-intro",
|
||||||
|
name: "Komponenten-Referenz (Intro)",
|
||||||
|
content: "Diese Seite bindet **jede verfügbare Komponente** einmal ein – als Referenz und zum Testen. Enthalten: Fullwidth-Banner (oben), Markdown, Iframe, Bild, Bildgalerie.",
|
||||||
|
layout: {
|
||||||
|
mobile: "12",
|
||||||
|
tablet: "10",
|
||||||
|
desktop: "8",
|
||||||
|
spaceBottom: 1.5,
|
||||||
|
},
|
||||||
|
alignment: "center",
|
||||||
|
}
|
||||||
11
content/de/markdown/kontakt-text.json5
Normal file
11
content/de/markdown/kontakt-text.json5
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
name: "Kontakt-Text",
|
||||||
|
content: "Schreib uns eine E-Mail oder nutze das Projekt auf GitLab. RustyCMS ist Open Source – Beiträge und Ideen sind willkommen.",
|
||||||
|
layout: {
|
||||||
|
mobile: "12",
|
||||||
|
tablet: "8",
|
||||||
|
desktop: "6",
|
||||||
|
spaceBottom: 1.5,
|
||||||
|
},
|
||||||
|
alignment: "center",
|
||||||
|
}
|
||||||
12
content/de/navigation/header.json5
Normal file
12
content/de/navigation/header.json5
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"internal": "navigation-header",
|
||||||
|
"links": [
|
||||||
|
"about",
|
||||||
|
"home",
|
||||||
|
"kontakt",
|
||||||
|
"docs",
|
||||||
|
"komponenten-referenz",
|
||||||
|
"gitlab"
|
||||||
|
],
|
||||||
|
"name": "Hauptnavigation"
|
||||||
|
}
|
||||||
20
content/de/page/about.json5
Normal file
20
content/de/page/about.json5
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
slug: "about",
|
||||||
|
name: "Ueber uns",
|
||||||
|
linkName: "About",
|
||||||
|
headline: "Ueber RustyCMS",
|
||||||
|
subheadline: "Open Source. File-basiert. Schnell.",
|
||||||
|
topFullwidthBanner: "about-hero",
|
||||||
|
seoTitle: "Ueber uns – RustyCMS",
|
||||||
|
seoMetaRobots: "index, follow",
|
||||||
|
seoDescription: "Erfahre mehr ueber das RustyCMS-Projekt.",
|
||||||
|
row1JustifyContent: "start",
|
||||||
|
row1AlignItems: "stretch",
|
||||||
|
row1Content: [],
|
||||||
|
row2JustifyContent: "start",
|
||||||
|
row2AlignItems: "stretch",
|
||||||
|
row2Content: [],
|
||||||
|
row3JustifyContent: "start",
|
||||||
|
row3AlignItems: "stretch",
|
||||||
|
row3Content: [],
|
||||||
|
}
|
||||||
26
content/de/page/home.json5
Normal file
26
content/de/page/home.json5
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
// ── Page-eigene Felder ─────────────────────────────────
|
||||||
|
slug: "home",
|
||||||
|
name: "Startseite",
|
||||||
|
linkName: "Home",
|
||||||
|
icon: "home",
|
||||||
|
headline: "Willkommen bei RustyCMS",
|
||||||
|
subheadline: "Das file-basierte Headless CMS geschrieben in Rust",
|
||||||
|
topFullwidthBanner: "hero", // → referenziert fullwidth_banner/hero.json5
|
||||||
|
// ── SEO-Felder (geerbt von seo) ───────────────────────
|
||||||
|
seoTitle: "RustyCMS – Startseite",
|
||||||
|
seoMetaRobots: "index, follow",
|
||||||
|
seoDescription: "Willkommen bei RustyCMS, dem file-basierten Headless CMS.",
|
||||||
|
// ── Content-Layout (geerbt von content_layout) ────────
|
||||||
|
row1JustifyContent: "center",
|
||||||
|
row1AlignItems: "center",
|
||||||
|
row1Content: [
|
||||||
|
"intro"
|
||||||
|
],
|
||||||
|
row2JustifyContent: "start",
|
||||||
|
row2AlignItems: "stretch",
|
||||||
|
row2Content: [],
|
||||||
|
row3JustifyContent: "start",
|
||||||
|
row3AlignItems: "start",
|
||||||
|
row3Content: [],
|
||||||
|
}
|
||||||
44
content/de/page/komponenten-referenz.json5
Normal file
44
content/de/page/komponenten-referenz.json5
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
// ── Testseite: jede Komponente eingebunden (Referenz) ───
|
||||||
|
_slug: "komponenten-referenz",
|
||||||
|
slug: "komponenten-referenz",
|
||||||
|
name: "Komponenten-Referenz",
|
||||||
|
linkName: "Komponenten",
|
||||||
|
icon: "grid",
|
||||||
|
headline: "Komponenten-Referenz",
|
||||||
|
subheadline: "Alle Komponenten auf einer Seite zum Testen und als Referenz",
|
||||||
|
// Fullwidth-Banner (oben)
|
||||||
|
topFullwidthBanner: "hero",
|
||||||
|
// ── SEO ───────────────────────────────────────────────
|
||||||
|
seoTitle: "Komponenten-Referenz – RustyCMS",
|
||||||
|
seoMetaRobots: "index, follow",
|
||||||
|
seoDescription: "Übersicht aller Komponenten: Banner, Headline, List, Link-Liste, Markdown, Iframe, Bild, YouTube, Quote, HTML, Galerie, SearchableText.",
|
||||||
|
// ── Row 1: Markdown-Komponenten ──────────────────────
|
||||||
|
row1JustifyContent: "center",
|
||||||
|
row1AlignItems: "stretch",
|
||||||
|
row1Content: [
|
||||||
|
"komponenten-referenz-intro",
|
||||||
|
"headline-referenz",
|
||||||
|
"intro",
|
||||||
|
"kontakt-text",
|
||||||
|
"list-referenz",
|
||||||
|
"link-list-referenz",
|
||||||
|
],
|
||||||
|
// ── Row 2: Iframe + Bild + YouTube ─────────────────────
|
||||||
|
row2JustifyContent: "start",
|
||||||
|
row2AlignItems: "stretch",
|
||||||
|
row2Content: [
|
||||||
|
"iframe-referenz",
|
||||||
|
"image-referenz",
|
||||||
|
"youtube-referenz",
|
||||||
|
"quote-referenz",
|
||||||
|
"html-referenz",
|
||||||
|
],
|
||||||
|
// ── Row 3: Bildgalerie + SearchableText ─────────────────
|
||||||
|
row3JustifyContent: "start",
|
||||||
|
row3AlignItems: "stretch",
|
||||||
|
row3Content: [
|
||||||
|
"gallery-referenz",
|
||||||
|
"search-referenz",
|
||||||
|
],
|
||||||
|
}
|
||||||
23
content/de/page/kontakt.json5
Normal file
23
content/de/page/kontakt.json5
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
slug: "kontakt",
|
||||||
|
name: "Kontakt",
|
||||||
|
linkName: "Kontakt",
|
||||||
|
icon: "mail",
|
||||||
|
headline: "Kontakt",
|
||||||
|
subheadline: "So erreichst du uns.",
|
||||||
|
topFullwidthBanner: "about-hero",
|
||||||
|
seoTitle: "Kontakt – RustyCMS",
|
||||||
|
seoMetaRobots: "index, follow",
|
||||||
|
seoDescription: "Kontakt und Ansprechpartner für RustyCMS.",
|
||||||
|
row1JustifyContent: "center",
|
||||||
|
row1AlignItems: "stretch",
|
||||||
|
row1Content: [
|
||||||
|
"kontakt-text"
|
||||||
|
],
|
||||||
|
row2JustifyContent: "start",
|
||||||
|
row2AlignItems: "stretch",
|
||||||
|
row2Content: [],
|
||||||
|
row3JustifyContent: "start",
|
||||||
|
row3AlignItems: "stretch",
|
||||||
|
row3Content: [],
|
||||||
|
}
|
||||||
11
content/de/page_config/default.json5
Normal file
11
content/de/page_config/default.json5
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
_slug: "default",
|
||||||
|
logo: "referenz-bild",
|
||||||
|
footerText1: "© 2026 RustyCMS. Open Source.",
|
||||||
|
seoTitle: "RustyCMS – File-basiertes Headless CMS",
|
||||||
|
seoDescription: "RustyCMS: Typen definieren, Content ablegen, API nutzen.",
|
||||||
|
blogTagPageHeadline: "Beiträge zum Tag",
|
||||||
|
blogPostsPageHeadline: "Blog",
|
||||||
|
blogPostsPageSubHeadline: "Alle Beiträge im Überblick",
|
||||||
|
website: "https://example.com",
|
||||||
|
}
|
||||||
34
content/de/post/beispielpost.json5
Normal file
34
content/de/post/beispielpost.json5
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
// Entry identifier (URL slug / filename without extension)
|
||||||
|
_slug: "beispielpost",
|
||||||
|
// ── Post-eigene Felder ─────────────────────────────────
|
||||||
|
slug: "beispielpost",
|
||||||
|
linkName: "Beispielpost",
|
||||||
|
icon: "article",
|
||||||
|
headline: "Ein Beispielpost",
|
||||||
|
subheadline: "Mit allen erweiterten Feldern",
|
||||||
|
excerpt: "Kurze Vorschau für Listen und Teaser.",
|
||||||
|
postImage: "", // Referenz auf img-Entry (Slug)
|
||||||
|
postTag: [
|
||||||
|
"rust",
|
||||||
|
"cms"
|
||||||
|
],
|
||||||
|
important: false,
|
||||||
|
date: "2026-02-15",
|
||||||
|
content: "# Einleitung\n\nHier steht der **Hauptinhalt** des Posts in Markdown. Absätze und _Formatierung_ werden unterstützt.\n\n## Überschriften und Listen\n\n- Erster Listenpunkt\n- Zweiter mit **Fett** und _Kursiv_\n- Dritter Punkt\n\n## Code und Zitate\n\n`Rust` eignet sich gut für sichere Systeme. Ein kurzer Code-Schnipsel:\n\n```\nfn main() {\n println!(\"Hallo von RustyCMS!\");\n}\n```\n\n> Ein Blockzitat passt gut für Hervorhebungen oder Zitate aus anderen Quellen.\n\n## Abschluss\n\nWeitere Absätze mit normalem Fließtext. [Links](https://example.com) und Bilder sind ebenfalls möglich.",
|
||||||
|
showCommentSection: true,
|
||||||
|
// ── SEO (geerbt von seo) ──────────────────────────────
|
||||||
|
seoTitle: "Beispielpost – RustyCMS",
|
||||||
|
seoMetaRobots: "index, follow",
|
||||||
|
seoDescription: "Ein Beispielpost mit allen Feldern des erweiterten Post-Schemas.",
|
||||||
|
// ── Content-Layout (geerbt von content_layout) ────────
|
||||||
|
row1JustifyContent: "start",
|
||||||
|
row1AlignItems: "stretch",
|
||||||
|
row1Content: [],
|
||||||
|
row2JustifyContent: "start",
|
||||||
|
row2AlignItems: "stretch",
|
||||||
|
row2Content: [],
|
||||||
|
row3JustifyContent: "start",
|
||||||
|
row3AlignItems: "stretch",
|
||||||
|
row3Content: [],
|
||||||
|
}
|
||||||
10
content/de/product/laptop-pro.json5
Normal file
10
content/de/product/laptop-pro.json5
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"category": "electronics",
|
||||||
|
"created_at": "2026-02-12T10:00:00Z",
|
||||||
|
"images": [
|
||||||
|
"img.jpg"
|
||||||
|
],
|
||||||
|
"price": 1299,
|
||||||
|
"sku": "EL-1001",
|
||||||
|
"title": "Laptop Pro 16 (Updated)"
|
||||||
|
}
|
||||||
12
content/de/quote/quote-referenz.json5
Normal file
12
content/de/quote/quote-referenz.json5
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
_slug: "quote-referenz",
|
||||||
|
quote: "Dies ist ein Beispielzitat für die Komponenten-Referenz. CF_Quote mit variant left/right.",
|
||||||
|
author: "RustyCMS",
|
||||||
|
variant: "left",
|
||||||
|
layout: {
|
||||||
|
mobile: "12",
|
||||||
|
tablet: "8",
|
||||||
|
desktop: "6",
|
||||||
|
spaceBottom: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user