-
I don't remember if this is the case as I could not find it in the docs, but I don't remember Decap CMS storing in the files in json format...instead it was frontmatter and markdown... Is it possible is Sveltia CMS to store data as JSON? The user would input content into form fields, but instead of YAML/Frontmatter and markdown the content could be stored as JSON? Also, can YAML/Frontmatter in sveltia-cms allow for creating and editing nested arrays of objects? Basically I need to be able to offer the following kind of data structure to a client: {
show: {
vi: `Thời Sự Thế Giới`,
en: `Morning News`,
},
show_id: 1,
date: `2023-08-09 8:00:00.000+00`,
title: {
vi: `Các tiêu đề mới nhất của hôm nay và xa hơn`,
en: `The Latest headlines of today and beyond`
},
image: `/shows/thoi-su-the-gioi-images/2023-08-09-cover.jpg`,
alt: `Cover image of todays episode of morning news.`,
video_id: `OpjGwOvtkU8`,
parts: [
{
order: 1,
title: `Specific Headline One`,
image: `/shows/thoi-su-the-gioi-images/2023-08-09-cover-part-1.jpg`,
alt: `Cover image of todays episode of morning news.`,
video_id: `qs5eoL0E3Ls`
},
{
order: 2,
title: `Specific Headline Two`,
image: `/shows/thoi-su-the-gioi-images/2023-08-09-cover-part-2.jpg`,
alt: `Cover image of todays episode of morning news.`,
video_id: `3CA2VFVNZh0`
},
{
order: 3,
title: `Specific Headline Three`,
image: `/shows/thoi-su-the-gioi-images/2023-08-09-cover-part-3.jpg`,
alt: `Cover image of todays episode of morning news.`,
video_id: `FN28ln-pBWg`
},
{
order: 4,
title: `Specific Headline Four`,
image: `/shows/thoi-su-the-gioi-images/2023-08-09-cover-part-4.jpg`,
alt: `Cover image of todays episode of morning news.`,
video_id: `m5rVUIm3TDk`
},
]
}, ...where I have translations of some of the fields into two languages, and nested arrays of objects for related content that should ideally be associated in this kind of manner together. So, I guess what I am asking is can Sveltia CMS handle this kind of data structure as is using the schema system and YAML/Frontmatter, or do i need JSON for something like this and can this even be defined in the config file to begin with Thanks! ありがとう |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
The JSON format is supported in Sveltia CMS for sure! The Object and List widgets can be used to nest the fields. You can also use the built-in internationalization support as well or simply have nested fields for those two languages. Most of my own clients use the i18n support to have both Japanese and English in one single file, like this:
A config example if you use the i18n support: backend:
name: github
repo: org/repo
branch: main
media_folder: static/images
public_folder: /images
i18n:
structure: single_file
locales: [en, vi]
collections:
- name: videos
label: Videos
label_singular: video
create: true
icon: movie
folder: src/lib/data/videos/
media_folder: '/static/images/shows'
public_folder: '/images/shows'
slug: '{{uuid_short}}'
extension: json
i18n: true
fields:
- name: show
label: Show
widget: string
i18n: true
- name: show_id
label: Show ID
widget: number # or `relation` to use an ID from another collection
value_type: int
min: 1
i18n: duplicate
- name: date
label: Date
widget: datetime
i18n: duplicate
- name: title
label: Title
widget: string
i18n: true
- name: image
label: Image
widget: image
i18n: duplicate
- name: alt
label: Image Alt
widget: string
i18n: duplicate # or `true` to translate the text
- name: video_id
label: Video ID
widget: string # or `relation` to use an ID from another collection
i18n: duplicate
- name: parts
label: Parts
label_singular: Part
widget: list
i18n: duplicate
fields:
- name: order
label: Order
value_type: int
min: 1
i18n: duplicate
- name: title
label: Title
widget: string
i18n: duplicate # or `true` to translate the text
- name: image
label: Image
widget: image
i18n: duplicate
- name: alt
label: Image Alt
widget: string
i18n: duplicate # or `true` to translate the text
- name: video_id
label: Video ID
widget: string # or `relation` to use an ID from another collection
i18n: duplicate Or without i18n: backend:
name: github
repo: org/repo
branch: main
media_folder: static/images
public_folder: /images
collections:
- name: videos
label: Videos
label_singular: video
create: true
icon: movie
folder: src/lib/data/videos/
media_folder: '/static/images/shows'
public_folder: '/images/shows'
slug: '{{uuid_short}}'
identifier_field: '{{fields.title.en}}' # This actually doesn’t work; a bug in Sveltia CMS
extension: json
fields:
- name: show
label: Show
widget: object
fields:
- name: vi
label: Vietnamese
widget: string
- name: en
label: English
widget: string
- name: show_id
label: Show ID
widget: number # or `relation` to use an ID from another collection
value_type: int
min: 1
- name: date
label: Date
widget: datetime
- name: title
label: Title
widget: object
fields:
- name: vi
label: Vietnamese
widget: string
- name: en
label: English
widget: string
- name: image
label: Image
widget: image
- name: alt
label: Image Alt
widget: string
- name: video_id
label: Video ID
widget: string # or `relation` to use an ID from another collection
- name: parts
label: Parts
label_singular: Part
widget: list
fields:
- name: order
label: Order
value_type: int
min: 1
- name: title
label: Title
widget: string
- name: image
label: Image
widget: image
- name: alt
label: Image Alt
widget: string
- name: video_id
label: Video ID
widget: string # or `relation` to use an ID from another collection Note: Sveltia CMS offers a handy DeepL Translator integration, but unfortunately Vietnamese is not yet supported by DeepL. Maybe I could add support for Google Cloud Translation as an alternative service that supports Vietnamese. |
Beta Was this translation helpful? Give feedback.
-
I made a convertToSlug function for Vietnamese titles recently: import unorm from 'unorm';
export function convertToSlug(text) {
const normalizedText = unorm.nfd(text) // Normalize to handle diacritics
.replace(/[\u0300-\u036f]/g, ''); // Remove diacritics
const convertedText = normalizedText
.replace(/Đ/g, 'D') // Convert Đ to D (uppercase)
.replace(/đ/g, 'd') // Convert đ to d (lowercase)
.toLowerCase()
.replace(/[^\w\s-]/g, '') // Remove all non-alphanumeric characters except hyphens and spaces
.replace(/\s+/g, '-') // Replace multiple spaces with a single hyphens
.replace(/^-+|-+$/g, ''); // Trim leading and trailing hyphens
return convertedText;
} ...maybe that helps something like this maybe?
|
Beta Was this translation helpful? Give feedback.
The JSON format is supported in Sveltia CMS for sure! The Object and List widgets can be used to nest the fields. You can also use the built-in internationalization support as well or simply have nested fields for those two languages. Most of my own clients use the i18n support to have both Japanese and English in one single file, like this:
A config example if you use the i18n support: