order.js 4.5 KB

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