mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-03 19:32:35 +02:00
feat: add blog loader
This commit is contained in:
parent
94c45e36cb
commit
d2e12a8e61
13 changed files with 633 additions and 25 deletions
6
test/loader/__fixtures__/custom/foo/bar.md
Normal file
6
test/loader/__fixtures__/custom/foo/bar.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
title: Lorem ipsum
|
||||
date: 2018-06-20
|
||||
---
|
||||
|
||||
Lorem ipsum
|
5
test/loader/__fixtures__/custom/foo/baz.md
Normal file
5
test/loader/__fixtures__/custom/foo/baz.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Baz
|
||||
date: 2018-05-20
|
||||
---
|
||||
Life is so good
|
|
@ -1,5 +1,6 @@
|
|||
---
|
||||
title: Hello, World !
|
||||
date: 2018-07-28
|
||||
---
|
||||
|
||||
Hello World
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
---
|
||||
title: Hello, World !
|
||||
date: 2018-07-28
|
||||
---
|
||||
|
||||
Hello World
|
||||
|
|
46
test/loader/__snapshots__/blog.test.js.snap
Normal file
46
test/loader/__snapshots__/blog.test.js.snap
Normal 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 !",
|
||||
},
|
||||
]
|
||||
`;
|
17
test/loader/__snapshots__/config.test.js.snap
Normal file
17
test/loader/__snapshots__/config.test.js.snap
Normal 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
18
test/loader/blog.test.js
Normal 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();
|
||||
});
|
||||
});
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue