Throw config error if unsupported format.
This commit is contained in:
parent
db14b9747a
commit
d5ff92e47e
@ -3,6 +3,14 @@ import tomlFormatter from './toml';
|
|||||||
import jsonFormatter from './json';
|
import jsonFormatter from './json';
|
||||||
import FrontmatterFormatter from './frontmatter';
|
import FrontmatterFormatter from './frontmatter';
|
||||||
|
|
||||||
|
export const supportedFormats = [
|
||||||
|
'markdown',
|
||||||
|
'yaml',
|
||||||
|
'toml',
|
||||||
|
'json',
|
||||||
|
'html',
|
||||||
|
];
|
||||||
|
|
||||||
export const formatToExtension = format => ({
|
export const formatToExtension = format => ({
|
||||||
markdown: 'md',
|
markdown: 'md',
|
||||||
yaml: 'yml',
|
yaml: 'yml',
|
||||||
@ -29,8 +37,11 @@ function formatByName(name) {
|
|||||||
yaml: yamlFormatter,
|
yaml: yamlFormatter,
|
||||||
toml: tomlFormatter,
|
toml: tomlFormatter,
|
||||||
json: jsonFormatter,
|
json: jsonFormatter,
|
||||||
|
md: FrontmatterFormatter,
|
||||||
|
markdown: FrontmatterFormatter,
|
||||||
|
html: FrontmatterFormatter,
|
||||||
frontmatter: FrontmatterFormatter,
|
frontmatter: FrontmatterFormatter,
|
||||||
}[name] || FrontmatterFormatter;
|
}[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveFormat(collectionOrEntity, entry) {
|
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.
|
// If no format is specified and it cannot be inferred, return the default.
|
||||||
return formatByName();
|
return formatByName('frontmatter');
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { OrderedMap, fromJS } from 'immutable';
|
import { OrderedMap, fromJS } from 'immutable';
|
||||||
import { has } from 'lodash';
|
import { has, get } from 'lodash';
|
||||||
import consoleError from '../lib/consoleError';
|
import consoleError from '../lib/consoleError';
|
||||||
import { CONFIG_SUCCESS } from '../actions/config';
|
import { CONFIG_SUCCESS } from '../actions/config';
|
||||||
import { FILES, FOLDER } from '../constants/collectionTypes';
|
import { FILES, FOLDER } from '../constants/collectionTypes';
|
||||||
import { INFERABLE_FIELDS } from '../constants/fieldInference';
|
import { INFERABLE_FIELDS } from '../constants/fieldInference';
|
||||||
import { formatToExtension } from '../formats/formats';
|
import { formatToExtension, supportedFormats } from '../formats/formats';
|
||||||
|
|
||||||
const collections = (state = null, action) => {
|
const collections = (state = null, action) => {
|
||||||
const configCollections = action.payload && action.payload.collections;
|
const configCollections = action.payload && action.payload.collections;
|
||||||
@ -31,6 +31,9 @@ function validateCollection(configCollection) {
|
|||||||
if (!has(configCollection, 'folder') && !has(configCollection, 'files')) {
|
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.`);
|
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 = {
|
const selectors = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user