1
0

config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const util = require('util')
  2. const path = require("path");
  3. const dirTree = require("directory-tree");
  4. const tree = dirTree("docs");
  5. const fs = require("fs");
  6. console.log("Current directory:", __dirname);
  7. /*
  8. This transform the node from dirTree into a form acceptable by Vuepress sidebar
  9. a.name becomes a.text
  10. a.path becomes a.link , and remove this field if there is children and set collapsible to true
  11. recursively do the same operator for each a.children
  12. */
  13. function transform_sidebar(child) {
  14. child.title = child.name.replace(".md", "");;
  15. child.link = child.path.replace("docs", "");
  16. if (child.link == "/README.md") {
  17. child.link = "/"; /* special case */
  18. child.title = "Home";
  19. }
  20. /* no children , return array of link/text */
  21. if (!child.children) {
  22. return [child.link, child.title];
  23. }
  24. /* return as a hash record with title/children */
  25. if (child.children) {
  26. let rec = { title: child.title, collapsible: true, children: [] };
  27. child.children.forEach(children => {
  28. /* bad child if this is a terminating node */
  29. if (!children.name.endsWith(".md") && !children.children) {
  30. // console.log("Ignoring : " + children.name)
  31. return;
  32. }
  33. rec.children.push(transform_sidebar(children));
  34. });
  35. return rec;
  36. }
  37. }
  38. // comment
  39. let sidebar = [];
  40. tree.children.forEach(child => {
  41. if (child.name == ".vuepress") return;
  42. if (child.name == ".npmignore") return;
  43. if (child.name.endsWith(".swp") ) return;
  44. sidebar.push(transform_sidebar(child));
  45. });
  46. console.log("SIDEBAR", sidebar[8]);
  47. module.exports = {
  48. title: 'Kinisi-User-Guide',
  49. description: 'Just playing around',
  50. head: [
  51. ['link', { rel: 'icon', href: '/favicon.ico' }]
  52. ],
  53. server: {
  54. hmr: { port: 8080 },
  55. },
  56. // sidebar
  57. themeConfig: {
  58. sidebar: sidebar,
  59. searchMaxSuggestions: 10,
  60. lastUpdated: 'Last Updated' // string | boolean
  61. },
  62. plugins: [
  63. ["vuepress-plugin-code-copy", { staticIcon: true, align: 'top' }],
  64. ['@vuepress/plugin-register-components', { componentsDir: "/vp/docs/.vuepress/compdir" }],
  65. ['tabs'],
  66. // ["demo", { car: 'mercedes' }],
  67. ["pagedata", { car: 'mercedes' }]
  68. // ['vuepress-plugin-graphviz']
  69. ],
  70. // add javascript to header
  71. head: [
  72. // ['script', { src: 'https://cdnjs.cloudflare.com/ajax/libs/viz.js/1.3.0/viz123.js' }]
  73. ['script', { src: '/viz.js' }]
  74. ],
  75. /*
  76. markdown: {
  77. extendMarkdown: md => {
  78. md.use(require('markdown-it-html5-embed'), {
  79. html5embed: {
  80. useImageSyntax: true,
  81. useLinkSyntax: false
  82. }
  83. })
  84. }
  85. }
  86. */
  87. }