mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-06 19:37:52 +02:00
chore(loader): prettier & eslint
This commit is contained in:
parent
d2e12a8e61
commit
7116374adf
5 changed files with 108 additions and 118 deletions
|
@ -3,18 +3,13 @@ const path = require('path');
|
||||||
const fm = require('front-matter');
|
const fm = require('front-matter');
|
||||||
const globby = require('globby');
|
const globby = require('globby');
|
||||||
const indexRE = /(^|.*\/)index\.md$/i;
|
const indexRE = /(^|.*\/)index\.md$/i;
|
||||||
const extRE = /\.md$/;
|
const mdRE = /\.md$/;
|
||||||
|
|
||||||
function fileToPath(file) {
|
function fileToPath(file) {
|
||||||
if (indexRE.test(file)) {
|
if (indexRE.test(file)) {
|
||||||
// index.md -> /
|
|
||||||
// foo/index.md -> /foo/
|
|
||||||
return file.replace(indexRE, '/$1');
|
return file.replace(indexRE, '/$1');
|
||||||
} else {
|
|
||||||
// foo.md -> /foo.html
|
|
||||||
// foo/bar.md -> /foo/bar.html
|
|
||||||
return `/${file.replace(extRE, '').replace(/\\/g, '/')}.html`;
|
|
||||||
}
|
}
|
||||||
|
return `/${file.replace(mdRE, '').replace(/\\/g, '/')}.html`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse(fileString) {
|
function parse(fileString) {
|
||||||
|
@ -39,7 +34,7 @@ async function loadBlog(sourceDir) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path: fileToPath(file),
|
path: fileToPath(file),
|
||||||
content: content,
|
content,
|
||||||
title: metadata.title,
|
title: metadata.title,
|
||||||
date: metadata.date
|
date: metadata.date
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@ module.exports = function loadConfig(sourceDir, deleteCache = true) {
|
||||||
}
|
}
|
||||||
let config = {};
|
let config = {};
|
||||||
if (fs.existsSync(configPath)) {
|
if (fs.existsSync(configPath)) {
|
||||||
config = require(configPath);
|
config = require(configPath); // eslint-disable-line
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
const path = require('path');
|
|
||||||
const loadConfig = require('./config');
|
const loadConfig = require('./config');
|
||||||
const loadBlog = require('./blog');
|
const loadBlog = require('./blog');
|
||||||
|
|
||||||
|
@ -9,8 +8,6 @@ module.exports = async function load(sourceDir) {
|
||||||
// 2. extract data from all blog files
|
// 2. extract data from all blog files
|
||||||
const blogDatas = await loadBlog(sourceDir);
|
const blogDatas = await loadBlog(sourceDir);
|
||||||
|
|
||||||
// 3. TODO
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
siteConfig,
|
siteConfig,
|
||||||
blogDatas
|
blogDatas
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
|
||||||
const loadBlog = require('../../lib/loader/blog');
|
const loadBlog = require('../../lib/loader/blog');
|
||||||
|
|
||||||
describe('loadBlog', () => {
|
describe('loadBlog', () => {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
|
||||||
const loadConfig = require('../../lib/loader/config');
|
const loadConfig = require('../../lib/loader/config');
|
||||||
|
|
||||||
describe('loadConfig', () => {
|
describe('loadConfig', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue