You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changes:
Enable setting the output folder as second argument (first is the input folder).
Line 17: const [docsFolder, outputFolder, ...argsRest] = process.argv.slice(2);
Line 22: const output = (outputFolder) ? outputFolder : `_${folder}`;
When using current folder as source folder (Like: markdown-folder-to-html ./)' the output folder is _. and is located inside the current folder. It causes problem with the recursive copy (cp -R . ./).
The solution is to ignore the output directory. In my case it caused problem because of coping folder node_modules too. I do not want it in the project and it could not be renamed.
Solution line 52: sh.cp("-R", folder + `/!(node_modules|${output})`, output);
Source: (cli.ts)
#! /usr/bin/env node
importfsfrom"fs";importpathfrom"path";importshfrom"shelljs";importgroupByPathfrom"./lib/group-by-path";importsortByPreferencesfrom"./lib/sort-by-preferences";importmdUrlfrom"./lib/markdown-url-to-html";importmd2htmlfrom"./lib/markdown-to-html";importrenderNavfrom"./lib/render-nav";importgenerateIndexInfofrom"./lib/generate-index-info";importpagefrom"./lib/render-page";importmdRfrom"./lib/markdown-regex";import{FileTree,StringFile}from"./lib/types";const[docsFolder,outputFolder, ...argsRest]=process.argv.slice(2);// Default parametersconstdefaultFolder="docs";constfolder=docsFolder||defaultFolder;constoutput=(outputFolder) ? outputFolder : `_${folder}`;consttemplateFilename="template.html";constcontentsFilename="contents.json";constpreferences=["index.md","README.md"];// Guards// Bail out if more than 1 argsif(argsRest&&argsRest.length>0){console.error("Too may arguments");usage(true);}// Bail out if the folder doesn't existif(!sh.test("-e",folder)){console.error(`Folder ${folder} not found at ${path.join(process.cwd(),folder)}`);usage(true);}// Define template html, user's first, otherwise defaultlettemplate=path.join(folder,templateFilename);if(!sh.test("-e",template)){template=path.join(__dirname,defaultFolder,templateFilename);}consttpl=sh.cat(template);// Prepare output folder (create, clean, copy sources)sh.mkdir("-p",output);sh.rm("-rf",output+"/*");sh.cp("-R",folder+`/!(node_modules|${output})`,output);// Start processing. Outline://// 1. Get all files// 2. Sort them// 3. Group them hierachically// 4. Parse files and generate output html filessh.cd(output);constall=sh.find("*");constmds=all.filter(file=>file.match(mdR)).sort(sortByPreferences.bind(null,preferences)).map(file=>{constcontent=sh.cat(file).toString();// The result is a weird not-stringreturn{path: file,url: mdUrl(file),
content,html: md2html(content)};});constgroupedMds: FileTree<StringFile>=mds.reduce((grouped: FileTree<StringFile>,value)=>groupByPath(grouped,value.path),[]);mds.forEach(({ path, url, html })=>{constnavHtml=renderNav(generateIndexInfo(path,groupedMds));constpageHtml=page(tpl,navHtml,html);fs.writeFileSync(url,pageHtml);});constcontentsJSON={paths: groupedMds,contents: mds.map((md,i)=>({ ...md,id: i}))};fs.writeFileSync(contentsFilename,JSON.stringify(contentsJSON,null,2));sh.rm("-r","**/*.md");functionusage(error: boolean){console.log(`Usage: markdown-folder-to-html [input-folder] input-folder [optional] defaults to \`docs\` `);process.exit(error ? 1 : 0);}
The text was updated successfully, but these errors were encountered:
What are you trying to do? This tool doesn't make sense to be run on a root directory. It is made to take a directory of markdown files and other assets and give you back another one with the HTML and those assets. It is not meant to be run in the root of the documents folder as you have experienced.
I don't want to add special casing to the copying, because it will get out of hand. This tool will give you a folder like the one you specified, but with the HTMLs added.
Maybe if you really want to run it that way you can rm the folder after generation, but I'd suggest moving the documents to a folder, and calling the command with that folder.
I want to create a self contained documentation project. Installation of markdown-folder-to-htmland running it are included in the project package.json. The package.json includes the markdown-folder-to-html package. The problem is that in this case markdown-folder-to-html will look for MD files in node_modules too. The output folder is a subfolder of the project.
My changes enables creating an online GIT-BOOK, where all the MD files are located somewhere in your server and the output HTML is the website public_html folder.
Changes:
Enable setting the output folder as second argument (first is the input folder).
Line 17: const [docsFolder, outputFolder, ...argsRest] = process.argv.slice(2);
Line 22: const output = (outputFolder) ? outputFolder : `_${folder}`;
When using current folder as source folder (Like: markdown-folder-to-html ./)' the output folder is _. and is located inside the current folder. It causes problem with the recursive copy (
cp -R . ./
).The solution is to ignore the output directory. In my case it caused problem because of coping folder
node_modules
too. I do not want it in the project and it could not be renamed.Solution line 52: sh.cp("-R", folder + `/!(node_modules|${output})`, output);
Source: (cli.ts)
The text was updated successfully, but these errors were encountered: