feat: add blog loader

This commit is contained in:
endiliey 2018-07-28 18:04:56 +08:00
parent 94c45e36cb
commit d2e12a8e61
13 changed files with 633 additions and 25 deletions

View file

@ -0,0 +1,6 @@
---
title: Lorem ipsum
date: 2018-06-20
---
Lorem ipsum

View file

@ -0,0 +1,5 @@
---
title: Baz
date: 2018-05-20
---
Life is so good

View file

@ -1,5 +1,6 @@
---
title: Hello, World !
date: 2018-07-28
---
Hello World

View file

@ -1,5 +1,6 @@
---
title: Hello, World !
date: 2018-07-28
---
Hello World

View file

@ -0,0 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`loadBlog custom 1`] = `
Array [
Object {
"content": "
Hello World
",
"date": 2018-07-28T00:00:00.000Z,
"path": "/hello.html",
"title": "Hello, World !",
},
Object {
"content": "
Lorem ipsum
",
"date": 2018-06-20T00:00:00.000Z,
"path": "/foo/bar.html",
"title": "Lorem ipsum",
},
Object {
"content": "
Life is so good
",
"date": 2018-05-20T00:00:00.000Z,
"path": "/foo/baz.html",
"title": "Baz",
},
]
`;
exports[`loadBlog simple 1`] = `
Array [
Object {
"content": "
Hello World
",
"date": 2018-07-28T00:00:00.000Z,
"path": "/hello.html",
"title": "Hello, World !",
},
]
`;

View file

@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`loadConfig custom 1`] = `
Object {
"base": "blogi",
"description": "Hello World",
"dest": "blogi",
"title": "Hello World",
}
`;
exports[`loadConfig simple 1`] = `
Object {
"description": "Hello World",
"title": "Hello World",
}
`;

18
test/loader/blog.test.js Normal file
View file

@ -0,0 +1,18 @@
const path = require('path');
const fs = require('fs');
const loadBlog = require('../../lib/loader/blog');
describe('loadBlog', () => {
const simpleDir = path.join(__dirname, '__fixtures__', 'simple');
const customDir = path.join(__dirname, '__fixtures__', 'custom');
test('simple', async () => {
const blogDatas = await loadBlog(simpleDir);
expect(blogDatas).toMatchSnapshot();
});
test('custom', async () => {
const blogDatas = await loadBlog(customDir);
expect(blogDatas).toMatchSnapshot();
});
});

View file

@ -7,22 +7,10 @@ describe('loadConfig', () => {
const customDir = path.join(__dirname, '__fixtures__', 'custom');
test('simple', () => {
expect(loadConfig(simpleDir)).toMatchInlineSnapshot(`
Object {
"description": "Hello World",
"title": "Hello World",
}
`);
expect(loadConfig(simpleDir)).toMatchSnapshot();
});
test('custom', () => {
expect(loadConfig(customDir)).toMatchInlineSnapshot(`
Object {
"base": "blogi",
"description": "Hello World",
"dest": "blogi",
"title": "Hello World",
}
`);
expect(loadConfig(customDir)).toMatchSnapshot();
});
});