Created
June 14, 2023 01:51
-
-
Save scottgallant/702b50eb2f473c47ce905aa531a106e5 to your computer and use it in GitHub Desktop.
TinaCMS: prepend filename with date upon creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const schema = defineSchema({ | |
collections: [ | |
{ | |
name: "post", | |
label: "Posts", | |
path: "site/content/posts", | |
ui: { | |
filename: { | |
slugify: values => { | |
const postDate = values.date ? new Date(values.date) : new Date(); | |
return `${postDate.toISOString().split("T")[0]}-${(values.slug || "") | |
.toLowerCase() | |
.replace(/ /g, "-")}`.replace(/[^\w\.\/-\s]/gi, ""); | |
} | |
} | |
}, | |
fields: [ | |
{ | |
type: "string", | |
name: "title", | |
label: "Title", | |
isTitle: true, | |
required: true, | |
}, | |
{ | |
type: "string", | |
name: "slug", | |
label: "Slug", | |
required: true | |
}, | |
{ | |
type: "datetime", | |
name: "date", | |
label: "Date", | |
description: | |
"Publish date and time (in your local time). You can change this later", | |
ui: { | |
timeFormat: "HH:mm" | |
}, | |
required: true | |
}, | |
{ | |
type: "string", | |
list: true, | |
name: "categories", | |
label: "Categories", | |
ui: { | |
component: "tags" | |
} | |
}, | |
{ | |
type: "rich-text", | |
name: "body", | |
label: "Body", | |
isBody: true, | |
} | |
] | |
} | |
] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment