order.js 4.6 KB

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