config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. sidebar.push(transform_sidebar(child));
  44. });
  45. console.log("SIDEBAR", sidebar[8]);
  46. module.exports = {
  47. title: 'Kinisi-User-Guide',
  48. description: 'Just playing around',
  49. head: [
  50. ['link', { rel: 'icon', href: '/favicon.ico' }]
  51. ],
  52. server: {
  53. hmr: { port: 8080 },
  54. },
  55. // sidebar
  56. themeConfig: {
  57. sidebar: sidebar,
  58. searchMaxSuggestions: 10,
  59. lastUpdated: 'Last Updated' // string | boolean
  60. },
  61. plugins: [
  62. ["vuepress-plugin-code-copy", { staticIcon: true, align: 'top' }],
  63. ['@vuepress/plugin-register-components', { componentsDir: "/vp/docs/.vuepress/compdir" }],
  64. ['tabs'],
  65. // ["demo", { car: 'mercedes' }],
  66. ["pagedata", { car: 'mercedes' }]
  67. // ['vuepress-plugin-graphviz']
  68. ],
  69. // add javascript to header
  70. head: [
  71. // ['script', { src: 'https://cdnjs.cloudflare.com/ajax/libs/viz.js/1.3.0/viz123.js' }]
  72. ['script', { src: '/viz.js' }]
  73. ],
  74. /*
  75. markdown: {
  76. extendMarkdown: md => {
  77. md.use(require('markdown-it-html5-embed'), {
  78. html5embed: {
  79. useImageSyntax: true,
  80. useLinkSyntax: false
  81. }
  82. })
  83. }
  84. }
  85. */
  86. }