diff --git a/src/formats/__tests__/yaml-frontmatter.spec.js b/src/formats/__tests__/frontmatter.spec.js similarity index 63% rename from src/formats/__tests__/yaml-frontmatter.spec.js rename to src/formats/__tests__/frontmatter.spec.js index 11e827f4..000653e3 100644 --- a/src/formats/__tests__/yaml-frontmatter.spec.js +++ b/src/formats/__tests__/frontmatter.spec.js @@ -1,11 +1,11 @@ -import YAMLFrontmatter from '../yaml-frontmatter'; +import Frontmatter from '../frontmatter'; -const YamlFrontmatterFormatter = new YAMLFrontmatter(); +const FrontmatterFormatter = new Frontmatter(); -describe('YAMLFrontmatter', () => { +describe('Frontmatter', () => { it('should parse YAML with --- delimiters', () => { expect( - YamlFrontmatterFormatter.fromFile('---\ntitle: YAML\ndescription: Something longer\n---\nContent') + FrontmatterFormatter.fromFile('---\ntitle: YAML\ndescription: Something longer\n---\nContent') ).toEqual( { title: 'YAML', @@ -17,7 +17,7 @@ describe('YAMLFrontmatter', () => { it('should parse YAML with ---yaml delimiters', () => { expect( - YamlFrontmatterFormatter.fromFile('---yaml\ntitle: YAML\ndescription: Something longer\n---\nContent') + FrontmatterFormatter.fromFile('---yaml\ntitle: YAML\ndescription: Something longer\n---\nContent') ).toEqual( { title: 'YAML', @@ -29,7 +29,7 @@ describe('YAMLFrontmatter', () => { it('should overwrite any body param in the front matter', () => { expect( - YamlFrontmatterFormatter.fromFile('---\ntitle: The Title\nbody: Something longer\n---\nContent') + FrontmatterFormatter.fromFile('---\ntitle: The Title\nbody: Something longer\n---\nContent') ).toEqual( { title: 'The Title', @@ -40,7 +40,7 @@ describe('YAMLFrontmatter', () => { it('should parse TOML with +++ delimiters', () => { expect( - YamlFrontmatterFormatter.fromFile('+++\ntitle = "TOML"\ndescription = "Front matter"\n+++\nContent') + FrontmatterFormatter.fromFile('+++\ntitle = "TOML"\ndescription = "Front matter"\n+++\nContent') ).toEqual( { title: 'TOML', @@ -52,7 +52,7 @@ describe('YAMLFrontmatter', () => { it('should parse TOML with ---toml delimiters', () => { expect( - YamlFrontmatterFormatter.fromFile('---toml\ntitle = "TOML"\ndescription = "Something longer"\n---\nContent') + FrontmatterFormatter.fromFile('---toml\ntitle = "TOML"\ndescription = "Something longer"\n---\nContent') ).toEqual( { title: 'TOML', @@ -64,7 +64,7 @@ describe('YAMLFrontmatter', () => { it('should parse JSON with { } delimiters', () => { expect( - YamlFrontmatterFormatter.fromFile('{\n"title": "The Title",\n"description": "Something longer"\n}\nContent') + FrontmatterFormatter.fromFile('{\n"title": "The Title",\n"description": "Something longer"\n}\nContent') ).toEqual( { title: 'The Title', @@ -76,7 +76,7 @@ describe('YAMLFrontmatter', () => { it('should parse JSON with ---json delimiters', () => { expect( - YamlFrontmatterFormatter.fromFile('---json\n{\n"title": "The Title",\n"description": "Something longer"\n}\n---\nContent') + FrontmatterFormatter.fromFile('---json\n{\n"title": "The Title",\n"description": "Something longer"\n}\n---\nContent') ).toEqual( { title: 'The Title', @@ -88,7 +88,7 @@ describe('YAMLFrontmatter', () => { it('should stringify YAML with --- delimiters', () => { expect( - YamlFrontmatterFormatter.toFile({ body: 'Some content\nOn another line', tags: ['front matter', 'yaml'], title: 'YAML' }) + FrontmatterFormatter.toFile({ body: 'Some content\nOn another line', tags: ['front matter', 'yaml'], title: 'YAML' }) ).toEqual( [ '---', diff --git a/src/formats/formats.js b/src/formats/formats.js index de357e8a..6eafb5d9 100644 --- a/src/formats/formats.js +++ b/src/formats/formats.js @@ -1,32 +1,32 @@ import YAML from './yaml'; import JSONFormatter from './json'; -import YAMLFrontmatter from './yaml-frontmatter'; +import Frontmatter from './frontmatter'; const yamlFormatter = new YAML(); const jsonFormatter = new JSONFormatter(); -const YamlFrontmatterFormatter = new YAMLFrontmatter(); +const FrontmatterFormatter = new Frontmatter(); function formatByType(type) { // Right now the only type is "editorialWorkflow" and // we always returns the same format - return YamlFrontmatterFormatter; + return FrontmatterFormatter; } export function formatByExtension(extension) { return { yml: yamlFormatter, json: jsonFormatter, - md: YamlFrontmatterFormatter, - markdown: YamlFrontmatterFormatter, - html: YamlFrontmatterFormatter, - }[extension] || YamlFrontmatterFormatter; + md: FrontmatterFormatter, + markdown: FrontmatterFormatter, + html: FrontmatterFormatter, + }[extension] || FrontmatterFormatter; } function formatByName(name) { return { yaml: yamlFormatter, - frontmatter: YamlFrontmatterFormatter, - }[name] || YamlFrontmatterFormatter; + frontmatter: FrontmatterFormatter, + }[name] || FrontmatterFormatter; } export function resolveFormat(collectionOrEntity, entry) { diff --git a/src/formats/yaml-frontmatter.js b/src/formats/frontmatter.js similarity index 94% rename from src/formats/yaml-frontmatter.js rename to src/formats/frontmatter.js index 3d2eb175..a469810c 100644 --- a/src/formats/yaml-frontmatter.js +++ b/src/formats/frontmatter.js @@ -7,7 +7,7 @@ preliminaries(true); yamlParser(true); tomlParser(true); -export default class YAMLFrontmatter { +export default class Frontmatter { fromFile(content) { const result = preliminaries.parse(content); const data = result.data;