Guide.svelte 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <script>
  2. // @ts-nocheck
  3. import { onMount } from 'svelte';
  4. import Router, { querystring, push, location } from 'svelte-spa-router';
  5. import { isShowNavStore, isWideScreenStore } from '../../store';
  6. import Menu from '../../components/menu/Menu.svelte';
  7. import QuickStart from './QuickStart.svelte';
  8. import Theme from './Theme.svelte';
  9. import Faq from './Faq.svelte';
  10. import Color from './Color.svelte';
  11. import Color_en from './Color_en.svelte';
  12. import Icon from './Icon.svelte';
  13. import Internation from './Internation.svelte';
  14. import Compatibility from './Compatibility.svelte';
  15. import Logo from './Logo.svelte';
  16. import About from './About.svelte';
  17. import Changelog from './Changelog.svelte';
  18. import Future from './Future.svelte';
  19. import Shortkey from './Shortkey.svelte';
  20. import Contribution from './Contribution.svelte';
  21. import Milestone from './Milestone.svelte';
  22. import Vscode from './Vscode.svelte';
  23. import Generator from './Generator.svelte';
  24. import Create from './Create.svelte';
  25. import IconPlugin from './IconPlugin.svelte';
  26. const isZh = localStorage.getItem('lang') === 'zh_CN';
  27. const guideRoutes = {
  28. '/quick-start': QuickStart,
  29. '/theme': Theme,
  30. '/faq': Faq,
  31. '/color': isZh ? Color : Color_en,
  32. '/icon': Icon,
  33. '/internation': Internation,
  34. '/compatibility': Compatibility,
  35. '/logo': Logo,
  36. '/about': About,
  37. '/changelog': Changelog,
  38. '/future': Future,
  39. '/shortkey': Shortkey,
  40. '/contribution': Contribution,
  41. '/milestone': Milestone,
  42. '/vscode': Vscode,
  43. '/generator': Generator,
  44. '/create': Create,
  45. '/icon-plugin': IconPlugin,
  46. '/': QuickStart,
  47. };
  48. let params = new URLSearchParams('?' + $querystring);
  49. const menuList = [
  50. {
  51. class: '常规',
  52. class_en: 'General',
  53. childs: [
  54. { title: '快速上手', title_en: 'Quick start', nav: 'quick-start', doc: 'quickStart' },
  55. { title: '主题配置', title_en: 'Theme', nav: 'theme', doc: 'theme' },
  56. { title: '图标', title_en: 'Icon', nav: 'icon', doc: 'icon' },
  57. { title: '国际化', title_en: 'Internationalization', nav: 'internation', doc: 'internation' },
  58. { title: '更新日志', title_en: 'Changelog', nav: 'changelog', doc: 'changelog' },
  59. { title: '常见问题', title_en: 'FAQ', nav: 'faq', doc: 'faq' },
  60. { title: '贡献指南', title_en: 'Contribution Guide', nav: 'contribution', doc: 'contribution' },
  61. { title: '兼容性', title_en: 'Compatibility', nav: 'compatibility', doc: 'compatibility' },
  62. ],
  63. },
  64. {
  65. class: '设计',
  66. class_en: 'Design',
  67. childs: [
  68. { title: '色彩', title_en: 'Color', nav: 'color' },
  69. { title: 'LOGO', title_en: 'LOGO', nav: 'logo' },
  70. ],
  71. },
  72. {
  73. class: '工具',
  74. class_en: 'Tools',
  75. childs: [
  76. { title: '主题生成器', title_en: 'Theme generator', nav: 'generator' },
  77. { title: 'IDE 插件', title_en: 'IDE plugin', nav: 'vscode', doc: 'vscode' },
  78. { title: '脚手架', title_en: 'Create cli', nav: 'create' },
  79. { title: '图标插件', title_en: 'Icon plugin', nav: 'icon-plugin' },
  80. { title: '快捷键', title_en: 'Shortcut key', nav: 'shortkey' },
  81. ],
  82. },
  83. {
  84. class: '其他',
  85. class_en: 'Other',
  86. childs: [
  87. { title: '关于', title_en: 'About', nav: 'about', doc: 'about' },
  88. { title: '里程碑', title_en: 'Milestone', nav: 'milestone', doc: 'milestone' },
  89. { title: '计划', title_en: 'Future', nav: 'future', doc: 'future' },
  90. ],
  91. },
  92. ];
  93. //扁平 menuList
  94. const flatMenuList = [];
  95. for (let e = 0; e < menuList.length; e++) {
  96. flatMenuList.push(...menuList[e].childs);
  97. }
  98. let currentNav = menuList[0].childs[0];
  99. let menuHeight = 0;
  100. const getMenuHeightFun = () => {
  101. menuHeight = document.documentElement.clientHeight - 56;
  102. };
  103. const menuClickFun = currentMenu => {
  104. if ($isShowNavStore) {
  105. isShowNavStore.set;
  106. }
  107. currentNav = currentMenu.detail;
  108. params.set('com', currentMenu.detail.nav);
  109. // push(`/guide?nav=${currentMenu.detail.nav}`);
  110. push(`/guide/${currentMenu.detail.nav}`);
  111. };
  112. onMount(() => {
  113. menuHeight = document.documentElement.clientHeight - 56;
  114. window.addEventListener('resize', getMenuHeightFun);
  115. // @ts-ignore
  116. hljs.highlightAll();
  117. // 获取路由
  118. // const currentRoute = window.location.href.split('#')[1];
  119. // 如果 $location 以 /guide 开头,去掉 /guide 保存到 location
  120. const locationNoGuide = $location.startsWith('/guide') ? $location.replace('/guide', '') : $location;
  121. // locationNoGuide 是否在 guideRoutes 中
  122. let isHave = false;
  123. for (let key in guideRoutes) {
  124. if (key === locationNoGuide) {
  125. isHave = true;
  126. break;
  127. }
  128. }
  129. if (isHave) {
  130. let arr = [];
  131. for (let e = 0; e < menuList.length; e++) {
  132. arr.push(...menuList[e].childs);
  133. }
  134. // 去掉 locationNoGuide 开头的 /
  135. const locationNoGuideNoSlash = locationNoGuide.replace('/', '');
  136. currentNav = arr.filter(item => item.nav === locationNoGuideNoSlash)[0];
  137. }
  138. return () => {
  139. window.removeEventListener('resize', getMenuHeightFun);
  140. };
  141. });
  142. // 全屏
  143. const changeFullFunc = () => {
  144. if ($isWideScreenStore) {
  145. isWideScreenStore.set(false);
  146. localStorage.setItem('isFull', 'notFull');
  147. } else {
  148. isWideScreenStore.set(true);
  149. localStorage.setItem('isFull', 'full');
  150. }
  151. };
  152. // 编辑地址处理
  153. const editUrlFn = nav => {
  154. if (nav === 'create') {
  155. return 'https://github.com/any-tdf/stdf/edit/main/packages/create-stdf/README' + (isZh ? '_CN' : '') + '.md';
  156. }
  157. if (nav === 'icon-plugin') {
  158. return 'https://github.com/any-tdf/stdf/edit/main/packages/rollup-plugin-stdf-icon/README' + (isZh ? '_CN' : '') + '.md';
  159. }
  160. return `https://github.com/any-tdf/stdf/edit/main/doc/guide/${flatMenuList.filter(item => item.nav === nav)[0]?.doc}${
  161. isZh ? '' : '_en'
  162. }.md`;
  163. };
  164. </script>
  165. <div class="flex">
  166. <div
  167. class="fixed -left-52 md:left-0 top-14 w-48 overflow-y-scroll transition-all duration-300 z-[100] bg-white dark:bg-black md:bg-transparent dark:md:bg-transparent border-r border-black/10 dark:border-white/20"
  168. class:left-0={$isShowNavStore}
  169. class:-left-52={!$isShowNavStore}
  170. style="height:{menuHeight + 'px'}"
  171. >
  172. <Menu {menuList} currentNav={currentNav.nav} on:MenuClick={menuClickFun} showNum={false} />
  173. </div>
  174. <div class="md:pl-48 w-screen">
  175. {#if currentNav.nav !== 'generator'}
  176. <div class="px-4 py-12 md:px-8 md:py-4">
  177. <div class="font-bold text-4xl">
  178. {isZh ? currentNav.title : currentNav.title_en}
  179. </div>
  180. </div>
  181. <div class="h-px bg-black/10 dark:bg-white/20"></div>
  182. {/if}
  183. <div class="px-4 pt-4 {currentNav.nav === 'generator' ? 'md:pt-4 md:px-4' : 'md:pt-12 md:px-8'}">
  184. <Router routes={guideRoutes} prefix="/guide" />
  185. </div>
  186. {#if currentNav.nav != 'color' && currentNav.nav != 'logo' && currentNav.nav != 'shortkey' && currentNav.nav != 'generator'}
  187. <div class="px-4 md:px-8 pb-8 text-xs flex gap-2">
  188. <a href={editUrlFn(currentNav.nav)} class="flex text-primary dark:text-dark w-full" target="_blank">
  189. <span class="h-4 w-4 mr-1">
  190. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="w-4 h-4" style="fill: currentColor;">
  191. <path
  192. d="M12.8995 6.85431L17.1421 11.0969L7.24264 20.9964H3V16.7538L12.8995 6.85431ZM14.3137 5.44009L16.435 3.31877C16.8256 2.92825 17.4587 2.92825 17.8492 3.31877L20.6777 6.1472C21.0682 6.53772 21.0682 7.17089 20.6777 7.56141L18.5563 9.68273L14.3137 5.44009Z"
  193. />
  194. </svg>
  195. </span>
  196. {isZh ? '在 GitHub 上编辑' : 'Edit on GitHub'}
  197. </a>
  198. </div>
  199. {/if}
  200. </div>
  201. </div>
  202. {#if !$location.includes('generator')}
  203. <button
  204. class="hidden md:block fixed right-2 bottom-4 z-50 p-1.5 w-8 h-8 rounded-full bg-primary dark:bg-dark text-white dark:text-black shadow-md shadow-primary/50 dark:shadow-dark/50"
  205. on:click={changeFullFunc}
  206. >
  207. {#if $isWideScreenStore}
  208. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
  209. ><path
  210. d="M20 3C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3H20ZM11 5H5V19H11V15H13V19H19V5H13V9H11V5ZM15 9L18 12L15 15V13H9V15L6 12L9 9V11H15V9Z"
  211. fill="currentColor"
  212. ></path></svg
  213. >
  214. {:else}
  215. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
  216. ><path
  217. d="M20 3C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3H20ZM11 5H5V10.999H7V9L10 12L7 15V13H5V19H11V17H13V19H19V13H17V15L14 12L17 9V10.999H19V5H13V7H11V5ZM13 13V15H11V13H13ZM13 9V11H11V9H13Z"
  218. fill="currentColor"
  219. ></path></svg
  220. >
  221. {/if}
  222. </button>
  223. {/if}
  224. <!-- 为 code-groups 预先编译 tailwind -->
  225. <div
  226. class="hidden dark:bg-[#202020] border-b-2 peer-checked/tab-0-0:border-primary dark:peer-checked/tab-0-0:border-dark peer-checked/tab-0-0:block
  227. peer-checked/tab-0-1:border-primary dark:peer-checked/tab-0-1:border-dark peer-checked/tab-0-1:block
  228. peer-checked/tab-0-2:border-primary dark:peer-checked/tab-0-2:border-dark peer-checked/tab-0-2:block
  229. peer-checked/tab-0-3:border-primary dark:peer-checked/tab-0-3:border-dark peer-checked/tab-0-3:block
  230. peer-checked/tab-0-4:border-primary dark:peer-checked/tab-0-4:border-dark peer-checked/tab-0-4:block
  231. peer-checked/tab-0-5:border-primary dark:peer-checked/tab-0-5:border-dark peer-checked/tab-0-5:block
  232. peer-checked/tab-1-0:border-primary dark:peer-checked/tab-1-0:border-dark peer-checked/tab-1-0:block
  233. peer-checked/tab-1-1:border-primary dark:peer-checked/tab-1-1:border-dark peer-checked/tab-1-1:block
  234. peer-checked/tab-1-2:border-primary dark:peer-checked/tab-1-2:border-dark peer-checked/tab-1-2:block
  235. peer-checked/tab-1-3:border-primary dark:peer-checked/tab-1-3:border-dark peer-checked/tab-1-3:block
  236. peer-checked/tab-1-4:border-primary dark:peer-checked/tab-1-4:border-dark peer-checked/tab-1-4:block
  237. peer-checked/tab-1-5:border-primary dark:peer-checked/tab-1-5:border-dark peer-checked/tab-1-5:block
  238. peer-checked/tab-2-0:border-primary dark:peer-checked/tab-2-0:border-dark peer-checked/tab-2-0:block
  239. peer-checked/tab-2-1:border-primary dark:peer-checked/tab-2-1:border-dark peer-checked/tab-2-1:block
  240. peer-checked/tab-2-2:border-primary dark:peer-checked/tab-2-2:border-dark peer-checked/tab-2-2:block
  241. peer-checked/tab-2-3:border-primary dark:peer-checked/tab-2-3:border-dark peer-checked/tab-2-3:block
  242. peer-checked/tab-2-4:border-primary dark:peer-checked/tab-2-4:border-dark peer-checked/tab-2-4:block
  243. peer-checked/tab-2-5:border-primary dark:peer-checked/tab-2-5:border-dark peer-checked/tab-2-5:block
  244. peer-checked/tab-3-0:border-primary dark:peer-checked/tab-3-0:border-dark peer-checked/tab-3-0:block
  245. peer-checked/tab-3-1:border-primary dark:peer-checked/tab-3-1:border-dark peer-checked/tab-3-1:block
  246. peer-checked/tab-3-2:border-primary dark:peer-checked/tab-3-2:border-dark peer-checked/tab-3-2:block
  247. peer-checked/tab-3-3:border-primary dark:peer-checked/tab-3-3:border-dark peer-checked/tab-3-3:block
  248. peer-checked/tab-3-4:border-primary dark:peer-checked/tab-3-4:border-dark peer-checked/tab-3-4:block
  249. peer-checked/tab-3-5:border-primary dark:peer-checked/tab-3-5:border-dark peer-checked/tab-3-5:block"
  250. ></div>