diff --git a/src/formats/formats.js b/src/formats/formats.js index be48fa28..81566148 100644 --- a/src/formats/formats.js +++ b/src/formats/formats.js @@ -3,6 +3,14 @@ import tomlFormatter from './toml'; import jsonFormatter from './json'; import FrontmatterFormatter from './frontmatter'; +export const supportedFormats = [ + 'markdown', + 'yaml', + 'toml', + 'json', + 'html', +]; + export const formatToExtension = format => ({ markdown: 'md', yaml: 'yml', @@ -29,8 +37,11 @@ function formatByName(name) { yaml: yamlFormatter, toml: tomlFormatter, json: jsonFormatter, + md: FrontmatterFormatter, + markdown: FrontmatterFormatter, + html: FrontmatterFormatter, frontmatter: FrontmatterFormatter, - }[name] || FrontmatterFormatter; + }[name]; } export function resolveFormat(collectionOrEntity, entry) { @@ -55,5 +66,5 @@ export function resolveFormat(collectionOrEntity, entry) { } // If no format is specified and it cannot be inferred, return the default. - return formatByName(); + return formatByName('frontmatter'); } diff --git a/src/reducers/collections.js b/src/reducers/collections.js index 01257c4e..e983312d 100644 --- a/src/reducers/collections.js +++ b/src/reducers/collections.js @@ -1,10 +1,10 @@ import { OrderedMap, fromJS } from 'immutable'; -import { has } from 'lodash'; +import { has, get } from 'lodash'; import consoleError from '../lib/consoleError'; import { CONFIG_SUCCESS } from '../actions/config'; import { FILES, FOLDER } from '../constants/collectionTypes'; import { INFERABLE_FIELDS } from '../constants/fieldInference'; -import { formatToExtension } from '../formats/formats'; +import { formatToExtension, supportedFormats } from '../formats/formats'; const collections = (state = null, action) => { const configCollections = action.payload && action.payload.collections; @@ -31,6 +31,9 @@ function validateCollection(configCollection) { if (!has(configCollection, 'folder') && !has(configCollection, 'files')) { throw new Error(`Unknown collection type for collection "${ collectionName }". Collections can be either Folder based or File based.`); } + if (has(configCollection, 'format') && !supportedFormats.includes(get(configCollection, 'format'))) { + throw new Error(`Unknown collection format for collection "${ collectionName }". Supported formats are ${ supportedFormats.join(',') }`); + } } const selectors = {