diff --git a/docs/test.md b/docs/test.md new file mode 100644 index 0000000..99be510 --- /dev/null +++ b/docs/test.md @@ -0,0 +1,2 @@ +!!! info "Test" +Empty file to test default folder \ No newline at end of file diff --git a/src/commands/build.js b/src/commands/build.js index 130a046..72a8e8a 100644 --- a/src/commands/build.js +++ b/src/commands/build.js @@ -1,3 +1,3 @@ let { buildStaticFiles } = require('../common/prepare-content') -buildStaticFiles(); \ No newline at end of file +buildStaticFiles(process.argv[2]); \ No newline at end of file diff --git a/src/common/prepare-content.js b/src/common/prepare-content.js index cf81959..4127d38 100644 --- a/src/common/prepare-content.js +++ b/src/common/prepare-content.js @@ -8,14 +8,15 @@ let { buildToc } = require('../toc'); let { errorPage } = require('../data/defaults'); // LOCATE MARKDOWN FILES -let findMdFiles = async () => { - const directoryPath = path.join(process.cwd()); +let findMdFiles = async (docsDir = 'docs') => { + const directoryPath = (docsDir) ? path.join(process.cwd() + `/${docsDir}`) : path.join(process.cwd()); try { let files = await fsp.readdir(directoryPath); return files.filter(file => path.extname(file) == '.md').map(mdFile => { + let filePath = path.resolve(`${directoryPath}/${mdFile}`) return { name: mdFile.substring(0, mdFile.lastIndexOf('.')), - path: path.resolve(mdFile) + path: filePath } }); } catch (err) { @@ -61,8 +62,8 @@ let saveHtmlContent = (filename, htmlContent) => { fs.writeFileSync(`${basePath}/${filename}`, htmlContent); } -let buildContent = async () => { - let locatedMdFiles = await findMdFiles(); +let buildContent = async (docsDir) => { + let locatedMdFiles = await findMdFiles(docsDir); let allPages = locatedMdFiles; let filesMdContent = await getFilesContent(locatedMdFiles); let htmlContent = convertMdToHtml(filesMdContent); @@ -88,12 +89,11 @@ let copyStaticAssets = (staticFolder = 'src/assets') => { fse.copySync(path.resolve(staticFolder), path.resolve('public')); } -let buildStaticFiles = async () => { +let buildStaticFiles = async (docsDir) => { removeOutputDirectory(); const templatesPath = path.join(process.cwd() + '/views'); - let generatedContent = await buildContent(); + let generatedContent = await buildContent(docsDir); let sidebarListOfPages = generatedContent.allPages.filter(page => page.name !== 'README'); - console.log(sidebarListOfPages); try { let items = await fsp.readdir(templatesPath); items.filter(item => path.extname(item) == '.ejs').forEach(template => {