Rename YamlFrontmatter to just Frontmatter
This commit is contained in:
parent
a2e8602fdd
commit
dc313d157b
@ -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', () => {
|
it('should parse YAML with --- delimiters', () => {
|
||||||
expect(
|
expect(
|
||||||
YamlFrontmatterFormatter.fromFile('---\ntitle: YAML\ndescription: Something longer\n---\nContent')
|
FrontmatterFormatter.fromFile('---\ntitle: YAML\ndescription: Something longer\n---\nContent')
|
||||||
).toEqual(
|
).toEqual(
|
||||||
{
|
{
|
||||||
title: 'YAML',
|
title: 'YAML',
|
||||||
@ -17,7 +17,7 @@ describe('YAMLFrontmatter', () => {
|
|||||||
|
|
||||||
it('should parse YAML with ---yaml delimiters', () => {
|
it('should parse YAML with ---yaml delimiters', () => {
|
||||||
expect(
|
expect(
|
||||||
YamlFrontmatterFormatter.fromFile('---yaml\ntitle: YAML\ndescription: Something longer\n---\nContent')
|
FrontmatterFormatter.fromFile('---yaml\ntitle: YAML\ndescription: Something longer\n---\nContent')
|
||||||
).toEqual(
|
).toEqual(
|
||||||
{
|
{
|
||||||
title: 'YAML',
|
title: 'YAML',
|
||||||
@ -29,7 +29,7 @@ describe('YAMLFrontmatter', () => {
|
|||||||
|
|
||||||
it('should overwrite any body param in the front matter', () => {
|
it('should overwrite any body param in the front matter', () => {
|
||||||
expect(
|
expect(
|
||||||
YamlFrontmatterFormatter.fromFile('---\ntitle: The Title\nbody: Something longer\n---\nContent')
|
FrontmatterFormatter.fromFile('---\ntitle: The Title\nbody: Something longer\n---\nContent')
|
||||||
).toEqual(
|
).toEqual(
|
||||||
{
|
{
|
||||||
title: 'The Title',
|
title: 'The Title',
|
||||||
@ -40,7 +40,7 @@ describe('YAMLFrontmatter', () => {
|
|||||||
|
|
||||||
it('should parse TOML with +++ delimiters', () => {
|
it('should parse TOML with +++ delimiters', () => {
|
||||||
expect(
|
expect(
|
||||||
YamlFrontmatterFormatter.fromFile('+++\ntitle = "TOML"\ndescription = "Front matter"\n+++\nContent')
|
FrontmatterFormatter.fromFile('+++\ntitle = "TOML"\ndescription = "Front matter"\n+++\nContent')
|
||||||
).toEqual(
|
).toEqual(
|
||||||
{
|
{
|
||||||
title: 'TOML',
|
title: 'TOML',
|
||||||
@ -52,7 +52,7 @@ describe('YAMLFrontmatter', () => {
|
|||||||
|
|
||||||
it('should parse TOML with ---toml delimiters', () => {
|
it('should parse TOML with ---toml delimiters', () => {
|
||||||
expect(
|
expect(
|
||||||
YamlFrontmatterFormatter.fromFile('---toml\ntitle = "TOML"\ndescription = "Something longer"\n---\nContent')
|
FrontmatterFormatter.fromFile('---toml\ntitle = "TOML"\ndescription = "Something longer"\n---\nContent')
|
||||||
).toEqual(
|
).toEqual(
|
||||||
{
|
{
|
||||||
title: 'TOML',
|
title: 'TOML',
|
||||||
@ -64,7 +64,7 @@ describe('YAMLFrontmatter', () => {
|
|||||||
|
|
||||||
it('should parse JSON with { } delimiters', () => {
|
it('should parse JSON with { } delimiters', () => {
|
||||||
expect(
|
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(
|
).toEqual(
|
||||||
{
|
{
|
||||||
title: 'The Title',
|
title: 'The Title',
|
||||||
@ -76,7 +76,7 @@ describe('YAMLFrontmatter', () => {
|
|||||||
|
|
||||||
it('should parse JSON with ---json delimiters', () => {
|
it('should parse JSON with ---json delimiters', () => {
|
||||||
expect(
|
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(
|
).toEqual(
|
||||||
{
|
{
|
||||||
title: 'The Title',
|
title: 'The Title',
|
||||||
@ -88,7 +88,7 @@ describe('YAMLFrontmatter', () => {
|
|||||||
|
|
||||||
it('should stringify YAML with --- delimiters', () => {
|
it('should stringify YAML with --- delimiters', () => {
|
||||||
expect(
|
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(
|
).toEqual(
|
||||||
[
|
[
|
||||||
'---',
|
'---',
|
@ -1,32 +1,32 @@
|
|||||||
import YAML from './yaml';
|
import YAML from './yaml';
|
||||||
import JSONFormatter from './json';
|
import JSONFormatter from './json';
|
||||||
import YAMLFrontmatter from './yaml-frontmatter';
|
import Frontmatter from './frontmatter';
|
||||||
|
|
||||||
const yamlFormatter = new YAML();
|
const yamlFormatter = new YAML();
|
||||||
const jsonFormatter = new JSONFormatter();
|
const jsonFormatter = new JSONFormatter();
|
||||||
const YamlFrontmatterFormatter = new YAMLFrontmatter();
|
const FrontmatterFormatter = new Frontmatter();
|
||||||
|
|
||||||
function formatByType(type) {
|
function formatByType(type) {
|
||||||
// Right now the only type is "editorialWorkflow" and
|
// Right now the only type is "editorialWorkflow" and
|
||||||
// we always returns the same format
|
// we always returns the same format
|
||||||
return YamlFrontmatterFormatter;
|
return FrontmatterFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatByExtension(extension) {
|
export function formatByExtension(extension) {
|
||||||
return {
|
return {
|
||||||
yml: yamlFormatter,
|
yml: yamlFormatter,
|
||||||
json: jsonFormatter,
|
json: jsonFormatter,
|
||||||
md: YamlFrontmatterFormatter,
|
md: FrontmatterFormatter,
|
||||||
markdown: YamlFrontmatterFormatter,
|
markdown: FrontmatterFormatter,
|
||||||
html: YamlFrontmatterFormatter,
|
html: FrontmatterFormatter,
|
||||||
}[extension] || YamlFrontmatterFormatter;
|
}[extension] || FrontmatterFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatByName(name) {
|
function formatByName(name) {
|
||||||
return {
|
return {
|
||||||
yaml: yamlFormatter,
|
yaml: yamlFormatter,
|
||||||
frontmatter: YamlFrontmatterFormatter,
|
frontmatter: FrontmatterFormatter,
|
||||||
}[name] || YamlFrontmatterFormatter;
|
}[name] || FrontmatterFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveFormat(collectionOrEntity, entry) {
|
export function resolveFormat(collectionOrEntity, entry) {
|
||||||
|
@ -7,7 +7,7 @@ preliminaries(true);
|
|||||||
yamlParser(true);
|
yamlParser(true);
|
||||||
tomlParser(true);
|
tomlParser(true);
|
||||||
|
|
||||||
export default class YAMLFrontmatter {
|
export default class Frontmatter {
|
||||||
fromFile(content) {
|
fromFile(content) {
|
||||||
const result = preliminaries.parse(content);
|
const result = preliminaries.parse(content);
|
||||||
const data = result.data;
|
const data = result.data;
|
Loading…
x
Reference in New Issue
Block a user