1
0

order.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. const order = [
  2. 'introduction',
  3. 'getting-started',
  4. 'customize-theme',
  5. 'design-to-code',
  6. 'dark-mode',
  7. 'accessibility',
  8. 'internationalization',
  9. 'design-source',
  10. 'overview',
  11. 'faq',
  12. "tailwind",
  13. "web-components",
  14. 'content-guidelines',
  15. 'changelog',
  16. 'update-to-v2',
  17. 'tokens',
  18. 'layout',
  19. 'grid',
  20. 'resizable',
  21. 'button',
  22. 'typography',
  23. 'divider',
  24. 'icon',
  25. 'space',
  26. 'chat',
  27. 'codehighlight',
  28. "markdownrender",
  29. "dragMove",
  30. "jsonviewer",
  31. 'hotkeys',
  32. "lottie",
  33. 'autocomplete',
  34. 'cascader',
  35. 'checkbox',
  36. 'colorpicker',
  37. 'datepicker',
  38. 'form',
  39. 'input',
  40. 'inputnumber',
  41. 'pincode',
  42. 'radio',
  43. 'rating',
  44. 'select',
  45. 'slider',
  46. 'switch',
  47. 'taginput',
  48. 'timepicker',
  49. 'transfer',
  50. 'treeselect',
  51. 'upload',
  52. 'anchor',
  53. 'backtop',
  54. 'breadcrumb',
  55. 'navigation',
  56. 'pagination',
  57. 'steps',
  58. 'tabs',
  59. 'tree',
  60. 'avatar',
  61. 'badge',
  62. 'calendar',
  63. 'card',
  64. 'carousel',
  65. 'collapse',
  66. 'collapsible',
  67. 'descriptions',
  68. 'dropdown',
  69. 'empty',
  70. 'highlight',
  71. 'image',
  72. 'cropper',
  73. 'list',
  74. 'modal',
  75. 'overflowlist',
  76. 'popover',
  77. 'scrolllist',
  78. 'sidesheet',
  79. 'table',
  80. 'tag',
  81. 'timeline',
  82. 'tooltip',
  83. 'userGuide',
  84. 'chart',
  85. 'banner',
  86. 'notification',
  87. 'popconfirm',
  88. 'progress',
  89. 'skeleton',
  90. 'spin',
  91. 'toast',
  92. 'configprovider',
  93. 'locale',
  94. 'jsonviewer',
  95. 'audioPlayer',
  96. 'videoPlayer',
  97. 'aiChatDialogue',
  98. ];
  99. let { exec } = require('child_process');
  100. let fs = require('fs');
  101. const executeShell = (command, callback) => {
  102. exec(command, (error, stdout, stderr) => {
  103. callback(stdout);
  104. });
  105. };
  106. module.exports = () => {
  107. const reOrderSingleMdx = (mdxPath, order) => {
  108. let data = fs.readFileSync(mdxPath, { encoding: 'utf-8' });
  109. let dataArray = data.split('---');
  110. let yaml = dataArray[1];
  111. const yamlArray = yaml.split('\n');
  112. let done = false;
  113. let localeDone = false;
  114. // let title=null;
  115. // let titleIndex=null;
  116. for (let index in yamlArray) {
  117. let info = yamlArray[index];
  118. // //
  119. // if(info.indexOf('subTitle')!==-1){
  120. // title=info.split(':')[1];
  121. // if(titleIndex){
  122. // yamlArray[titleIndex]=`title: ${title}`;
  123. // }
  124. // }
  125. // if(info.match(/title: /)){
  126. // if(title){
  127. // yamlArray[index]=`title: ${title}`;
  128. // }else{
  129. // titleIndex=index;
  130. // }
  131. // }
  132. // //
  133. let localeResult = info.match(/localeCode: /);
  134. if (localeResult) {
  135. localeDone = true;
  136. }
  137. let result = info.match(/order: \d/);
  138. if (result) {
  139. yamlArray[index] = `order: ${order}`;
  140. done = true;
  141. }
  142. }
  143. if (!done) {
  144. yamlArray.splice(1, 0, `order: ${order}`);
  145. }
  146. if (!localeDone) {
  147. const localCode = mdxPath.indexOf('en-US') !== -1 ? 'en-US' : 'zh-CN';
  148. yamlArray.splice(1, 0, `localeCode: ${localCode}`);
  149. console.log(`add localCode ${localCode} into ${mdxPath}'s yaml.`);
  150. }
  151. dataArray[1] = yamlArray.join('\n');
  152. const orderedData = dataArray.join('---');
  153. fs.writeFileSync(mdxPath, orderedData);
  154. };
  155. executeShell(`find ${process.cwd()}/content/* | grep index`, fileListStr => {
  156. let mdxFileList = fileListStr.split('\n').filter(filePath => {
  157. let res = filePath && fs.existsSync(filePath) && fs.statSync(filePath).isFile();
  158. if (!res && filePath) {
  159. console.error(`ERROR: ${filePath} not found or it's not a file.`);
  160. }
  161. return res;
  162. });
  163. mdxFileList.map(filePath => {
  164. const pathArray = filePath.split('/');
  165. const itemName = pathArray[pathArray.length - 2];
  166. const newOrder = order.indexOf(itemName) + 1;
  167. if (newOrder !== -1) {
  168. reOrderSingleMdx(filePath, newOrder);
  169. } else {
  170. console.error(`${itenName} not in order Array. Check your order.js or markdown folder name.`);
  171. }
  172. // console.log(`set ${itemName} to order ${newOrder}`)
  173. });
  174. console.log('ordered mdx');
  175. });
  176. };