order.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. 'aiChatInput',
  102. 'aiChatDialogue',
  103. ];
  104. let { exec } = require('child_process');
  105. let fs = require('fs');
  106. const executeShell = (command, callback) => {
  107. exec(command, (error, stdout, stderr) => {
  108. callback(stdout);
  109. });
  110. };
  111. module.exports = () => {
  112. const reOrderSingleMdx = (mdxPath, order) => {
  113. let data = fs.readFileSync(mdxPath, { encoding: 'utf-8' });
  114. let dataArray = data.split('---');
  115. let yaml = dataArray[1];
  116. const yamlArray = yaml.split('\n');
  117. let done = false;
  118. let localeDone = false;
  119. // let title=null;
  120. // let titleIndex=null;
  121. for (let index in yamlArray) {
  122. let info = yamlArray[index];
  123. // //
  124. // if(info.indexOf('subTitle')!==-1){
  125. // title=info.split(':')[1];
  126. // if(titleIndex){
  127. // yamlArray[titleIndex]=`title: ${title}`;
  128. // }
  129. // }
  130. // if(info.match(/title: /)){
  131. // if(title){
  132. // yamlArray[index]=`title: ${title}`;
  133. // }else{
  134. // titleIndex=index;
  135. // }
  136. // }
  137. // //
  138. let localeResult = info.match(/localeCode: /);
  139. if (localeResult) {
  140. localeDone = true;
  141. }
  142. let result = info.match(/order: \d/);
  143. if (result) {
  144. yamlArray[index] = `order: ${order}`;
  145. done = true;
  146. }
  147. }
  148. if (!done) {
  149. yamlArray.splice(1, 0, `order: ${order}`);
  150. }
  151. if (!localeDone) {
  152. const localCode = mdxPath.indexOf('en-US') !== -1 ? 'en-US' : 'zh-CN';
  153. yamlArray.splice(1, 0, `localeCode: ${localCode}`);
  154. console.log(`add localCode ${localCode} into ${mdxPath}'s yaml.`);
  155. }
  156. dataArray[1] = yamlArray.join('\n');
  157. const orderedData = dataArray.join('---');
  158. fs.writeFileSync(mdxPath, orderedData);
  159. };
  160. executeShell(`find ${process.cwd()}/content/* | grep index`, fileListStr => {
  161. let mdxFileList = fileListStr.split('\n').filter(filePath => {
  162. let res = filePath && fs.existsSync(filePath) && fs.statSync(filePath).isFile();
  163. if (!res && filePath) {
  164. console.error(`ERROR: ${filePath} not found or it's not a file.`);
  165. }
  166. return res;
  167. });
  168. mdxFileList.map(filePath => {
  169. const pathArray = filePath.split('/');
  170. const itemName = pathArray[pathArray.length - 2];
  171. const newOrder = order.indexOf(itemName) + 1;
  172. if (newOrder !== -1) {
  173. reOrderSingleMdx(filePath, newOrder);
  174. } else {
  175. console.error(`${itenName} not in order Array. Check your order.js or markdown folder name.`);
  176. }
  177. // console.log(`set ${itemName} to order ${newOrder}`)
  178. });
  179. console.log('ordered mdx');
  180. });
  181. };