backroad icon indicating copy to clipboard operation
backroad copied to clipboard

Help developers with configuration string formatting in content API

Open themeblvd opened this issue 6 years ago • 0 comments

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() - Like blog-posts, Already exists!
  • toSnakeCase() - Like blog_post.
  • toTitle() - Capitalize first letter of any words like blog post to Blog 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.

themeblvd avatar Jul 01 '18 15:07 themeblvd