sidebar.js 494 B

12345678910111213141516171819
  1. const fs = require('fs');
  2. const path = require('path');
  3. const root = path.join(__dirname);
  4. const result = {};
  5. function readDirSync(p) {
  6. const dir = fs.readdirSync(p);
  7. dir.forEach((file) => {
  8. const info = fs.statSync(`${p}/${file}`);
  9. if (info.isDirectory() && file.indexOf('.') !== 0 && file.indexOf('_') !== 0) {
  10. result[`${p.replace(root, '')}/${file}/_sidebar.md`] = '/_sidebar.md';
  11. readDirSync(`${p}/${file}`);
  12. }
  13. });
  14. }
  15. readDirSync(root);
  16. console.log(result);