Skip to content

Commit

Permalink
feat(core): add support of default docs directory
Browse files Browse the repository at this point in the history
This update allows you to pass `serve` and `build`
commands without specifying a directory.
In this case, the `<project>/docs` directory will be
used by default
  • Loading branch information
bandantonio committed Dec 23, 2021
1 parent 4bcb35b commit 2ad2cb0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!!! info "Test"
Empty file to test default folder
2 changes: 1 addition & 1 deletion src/commands/build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
let { buildStaticFiles } = require('../common/prepare-content')

buildStaticFiles();
buildStaticFiles(process.argv[2]);
16 changes: 8 additions & 8 deletions src/common/prepare-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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 => {
Expand Down

0 comments on commit 2ad2cb0

Please sign in to comment.