order.js 4.6 KB

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