backroad
backroad copied to clipboard
Help developers with configuration string formatting in content API
Consider the following example of adding a content type:
const app = backroad();
app.content.add({
id: 'blog_post', // Singular, snake-cased.
name: 'Blog Post', // Singular, human-readable.
endpoint: 'blog-posts', // Plural, hyphenated URL slug.
pluralName: 'Movies', // Plural, human-readable.
fields: []
});
There's quite a bit going on there in terms of knowing how to format each string. We can definitely add some formatting functions to /lib/utils/formattings.js
that will help with ensuring these strings are passed to the content API in the correct format.
Some helper methods might include:
-
toSlug()
- Likeblog-posts
, Already exists! -
toSnakeCase()
- Likeblog_post
. -
toTitle()
- Capitalize first letter of any words likeblog post
toBlog Post
.
And then we can better utilize these within the content API to ensure things are formatted properly with the content types that are registered.