Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: windows compatibility #2

Merged
merged 1 commit into from Jan 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/utils.js
Expand Up @@ -101,23 +101,23 @@ function makeContent(root, optionObj) {
// if sub directory with index.md
} else if (fs.existsSync(path.resolve(process.cwd(), optionObj.dir, root, 'index.md'))) {
optionObj.content = fs.readFileSync(
path.resolve(process.cwd(), optionObj.dir, root, 'index.md'),
path.posix.resolve(process.cwd(), optionObj.dir, root, 'index.md'),
'utf8'
);
// if sub directory without index.md
} else {
const chapters = optionObj.chapters
.filter(p => Object.keys(p)[0].indexOf(root) === 0)
.filter((p) => {
const pathArr = path.relative(root, Object.keys(p)[0]).split('/');
const pathArr = path.posix.relative(root, Object.keys(p)[0]).split('/');
if (pathArr.length > 1) return false;
if (pathArr[0] === '') return false;
return true;
});
let contentStr = '';
chapters.forEach((p) => {
const pagePath = Object.keys(p)[0];
const relativePath = path.relative(root, pagePath);
const relativePath = path.posix.relative(root, pagePath);
let pageHtml = '';
if (relativePath.substr(-3).toLowerCase() === '.md') {
pageHtml = relativePath.substr(0, relativePath.length - 3) + '.html';
Expand Down
18 changes: 15 additions & 3 deletions test/makeContent.test.js
Expand Up @@ -26,7 +26,13 @@ test(
]
};
opt = makeContent('first.md', opt);
t.equal(opt.content, 'This is a regular file.\n');
let result = '';
if (path.sep !== '/') {
result = 'This is a regular file.\r\n';
} else {
result = 'This is a regular file.\n';
}
t.equal(opt.content,result);
t.end();
}
);
Expand All @@ -47,7 +53,13 @@ test(
]
};
opt = makeContent('/', opt);
t.equal(opt.content, 'This is a README file.\n');
let result = '';
if (path.sep !== '/') {
result = 'This is a README file.\r\n';
} else {
result = 'This is a README file.\n';
}
t.equal(opt.content, result);
t.end();
}
);
Expand Down Expand Up @@ -110,7 +122,7 @@ test(
]
};
opt = makeContent('dir1/', opt);
t.equal(opt.content, '- [Title A](a.html)\n- [Title B](b.html)\n- [dir2](dir2/)\n');
t.equal(opt.content, '- [Title A](a.html)\n- [Title B](b.html)\n- [dir2](dir2/)\n');
t.end();
}
);
16 changes: 14 additions & 2 deletions test/theme.test.js
Expand Up @@ -20,7 +20,13 @@ test(
process.chdir(TEST_PATH);
const option = theme({ theme: THEME });
// const result = walkSync(path.resolve(process.cwd(), 'themes', THEME));
t.equal(option.templates.page(), 'hello world\n');
let result = '';
if (path.sep !== '/') {
result = 'hello world\r\n';
} else {
result = 'hello world\n';
}
t.equal(option.templates.page(), result);
t.end();
}
);
Expand Down Expand Up @@ -48,7 +54,13 @@ test(
process.chdir(TEST_PATH);
const option = theme({ theme: THEME });
// const result = walkSync(path.resolve(process.cwd(), 'themes', THEME));
t.equal(option.templates.page(), '<h1>Hello</h1>\n World\n\nnew\n2016\n\n');
let result = '';
if (path.sep !== '/') {
result = '<h1>Hello</h1>\r\n World\r\n\r\nnew\r\n2016\r\n\r\n';
} else {
result = '<h1>Hello</h1>\n World\n\nnew\n2016\n\n';
}
t.equal(option.templates.page(), result);
t.end();
// fs.removeSync(path.resolve(process.cwd(), 'themes', THEME));
}
Expand Down