37a36ffed4
When entries were loaded for the editorial workflow dashboard, they were all assumed to be FrontMatter/MarkDown files. This PR allows them to be any supported format.
42 lines
1014 B
JavaScript
42 lines
1014 B
JavaScript
import yamlFormatter from './yaml';
|
|
import tomlFormatter from './toml';
|
|
import jsonFormatter from './json';
|
|
import FrontmatterFormatter from './frontmatter';
|
|
|
|
export const formatToExtension = format => ({
|
|
markdown: 'md',
|
|
yaml: 'yml',
|
|
toml: 'toml',
|
|
json: 'json',
|
|
html: 'html',
|
|
}[format]);
|
|
|
|
export function formatByExtension(extension) {
|
|
return {
|
|
yml: yamlFormatter,
|
|
yaml: yamlFormatter,
|
|
toml: tomlFormatter,
|
|
json: jsonFormatter,
|
|
md: FrontmatterFormatter,
|
|
markdown: FrontmatterFormatter,
|
|
html: FrontmatterFormatter,
|
|
}[extension] || FrontmatterFormatter;
|
|
}
|
|
|
|
function formatByName(name) {
|
|
return {
|
|
yml: yamlFormatter,
|
|
yaml: yamlFormatter,
|
|
toml: tomlFormatter,
|
|
frontmatter: FrontmatterFormatter,
|
|
}[name] || FrontmatterFormatter;
|
|
}
|
|
|
|
export function resolveFormat(collectionOrEntity, entry) {
|
|
const path = entry && entry.path;
|
|
if (path) {
|
|
return formatByExtension(path.split('.').pop());
|
|
}
|
|
return formatByName(collectionOrEntity.get('format'));
|
|
}
|