By default, Tina does not enforce strict filename constraints, as operating systems support a wide variety of formats. However, you can enforce custom constraints at the collection level if needed.
a-z, A-Z, 0-9 , -, _, ., or /./, it will be treated as an absolute path relative to the collection root/foo/bar/blog-post will be saved as <MyCollectionPath>/post/blog-post.md/, it will be treated as relative to the current folderbar/blog-post will be saved as <MyCollectionPath>/<CurrentDirectory>/bar/blog-post.mdProperty | Description |
|---|---|
| Prevents the user from editing the filename |
| A function that generates the filename based on form values |
| A function that sanitizes the filename input as the user types |
parseThe parse function allows you to enforce filename constraints within the editor. The provided callback function sanitizes user input in real-time.
export default defineConfig({//...schema: {collections: [{label: "Blog Posts",ui: {filename: {parse: (filename) => filename.replaceAll(" ","_"),}},name: "post",path: "content/post",format: "mdx",fields: [//...]}],},});
slugifyUse the slugify function to automatically generate filenames based on other fields in the collection.
The
slugifyfunction only applies constraints when the user creates new files. Users can still rename files freely after creation.
export default defineConfig({//...schema: {collections: [{label: 'Blog Posts',name: 'post',path: 'content/post',format: 'md',ui: {filename: {// if disabled, the editor can not edit the filenamereadonly: true,// Example of using a custom slugify functionslugify: (values) => {// Values is an object containing all the values of the form. In this case it is {title?: string, topic?: string}return `${values?.topic || 'no-topic'}-${values?.title?.toLowerCase().replace(/ /g, '-')}`},},},fields: [{type: 'string',label: 'Title',name: 'title',},{type: 'string',label: 'Topic',name: 'topic',options: ['programming', 'blacksmithing'],},],},],},})
If no slugify function is provided and a field has isTitle: true, Tina uses a default slugify function. This removes non-alphanumeric characters and replaces spaces with dashes.
export default defineConfig({//...schema: {collections: [{label: 'Blog Posts',name: 'post',path: 'content/post',format: 'md',fields: [{type: 'string',label: 'Title',name: 'title',// If no slugify function is provided, then by default the "title" field will be used to generate the filenameisTitle: true,required: true,},{type: 'string',label: 'Topic',name: 'topic',options: ['programming', 'blacksmithing'],},],},],},})