valaxy 0.3.10 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +4 -0
  2. package/{src/client → client}/App.vue +0 -0
  3. package/{src/client → client}/components/AppLink.vue +0 -0
  4. package/{src/client → client}/components/PostCard.vue +37 -23
  5. package/{src/client → client}/components/PostList.vue +0 -0
  6. package/{src/client → client}/components/README.md +0 -0
  7. package/{src/client → client}/components/ValaxyBg.vue +1 -1
  8. package/{src/client → client}/components/ValaxyCopyright.vue +0 -0
  9. package/{src/client → client}/components/ValaxyFooter.vue +2 -2
  10. package/{src/client → client}/components/ValaxyHamburger.vue +0 -0
  11. package/{src/client → client}/components/ValaxyMd.vue +1 -5
  12. package/{src/client → client}/components/ValaxyOverlay.vue +0 -0
  13. package/{src/client → client}/components/ValaxyPagination.vue +0 -0
  14. package/{src/client → client}/components/ValaxyRightSidebar.vue +0 -0
  15. package/{src/client → client}/components/ValaxySidebar.vue +0 -0
  16. package/{src/client → client}/components/ValaxyToc.vue +0 -0
  17. package/{src/client → client}/composables/category.ts +0 -0
  18. package/{src/client → client}/composables/comments/index.ts +0 -0
  19. package/{src/client → client}/composables/comments/twikoo.ts +0 -0
  20. package/{src/client → client}/composables/comments/waline.ts +0 -0
  21. package/{src/client → client}/composables/common.ts +0 -0
  22. package/{src/client → client}/composables/dark.ts +0 -0
  23. package/{src/client/composables/search → client/composables/features}/index.ts +0 -0
  24. package/{src/client → client}/composables/helper.ts +0 -0
  25. package/{src/client → client}/composables/index.ts +1 -1
  26. package/{src/client → client}/composables/layout.ts +0 -0
  27. package/{src/client → client}/composables/post.ts +0 -0
  28. package/client/composables/search/index.ts +0 -0
  29. package/{src/client → client}/composables/sidebar.ts +10 -8
  30. package/{src/client → client}/composables/tag.ts +0 -0
  31. package/{src/client → client}/composables/widgets/aplayer.ts +0 -0
  32. package/{src/client → client}/composables/widgets/backToTop.ts +0 -0
  33. package/{src/client → client}/composables/widgets/codepen.ts +0 -0
  34. package/{src/client → client}/composables/widgets/index.ts +0 -0
  35. package/{src/client → client}/config.ts +2 -1
  36. package/{src/client → client}/index.html +0 -0
  37. package/{src/client → client}/index.ts +0 -0
  38. package/{src/client → client}/layouts/404.vue +0 -0
  39. package/{src/client → client}/layouts/README.md +0 -0
  40. package/{src/client → client}/locales/README.md +0 -0
  41. package/{src/client → client}/locales/en.yml +1 -0
  42. package/{src/client → client}/locales/zh-CN.yml +4 -3
  43. package/{src/client → client}/main.ts +5 -1
  44. package/{src/client → client}/modules/README.md +0 -0
  45. package/{src/client → client}/modules/nprogress.ts +0 -0
  46. package/{src/client → client}/modules/pinia.ts +0 -0
  47. package/{src/client → client}/modules/valaxy.ts +1 -1
  48. package/{src/client → client}/pages/README.md +0 -0
  49. package/{src/client → client}/pages/[...all].vue +0 -0
  50. package/{src/client → client}/pages/hi/[name].vue +0 -0
  51. package/{src/client → client}/pages/index.vue +0 -0
  52. package/{src/client → client}/pages/page/[page].vue +0 -0
  53. package/{src/client → client}/shims.d.ts +1 -0
  54. package/{src/client → client}/stores/app.ts +0 -0
  55. package/{src/client → client}/stores/user.ts +0 -0
  56. package/{src/client → client}/styles/common/button.scss +0 -0
  57. package/{src/client → client}/styles/common/code.scss +0 -0
  58. package/{src/client → client}/styles/common/custom-blocks.scss +0 -0
  59. package/{src/client → client}/styles/common/hamburger.scss +0 -0
  60. package/{src/client → client}/styles/common/markdown.scss +5 -1
  61. package/client/styles/common/scrollbar.scss +28 -0
  62. package/{src/client → client}/styles/common/sidebar.scss +0 -0
  63. package/{src/client → client}/styles/common/transition.scss +0 -0
  64. package/{src/client → client}/styles/css-vars.scss +0 -0
  65. package/{src/client → client}/styles/global/helper.scss +0 -0
  66. package/{src/client → client}/styles/global/i18n.scss +0 -0
  67. package/{src/client → client}/styles/global/index.scss +0 -0
  68. package/{src/client → client}/styles/global/nprogress.scss +0 -0
  69. package/{src/client → client}/styles/global/reset.scss +0 -0
  70. package/{src/client → client}/styles/index.scss +0 -0
  71. package/{src/client → client}/styles/mixins/config.scss +0 -0
  72. package/{src/client → client}/styles/mixins/index.scss +0 -0
  73. package/{src/client → client}/styles/mixins/size.scss +0 -0
  74. package/{src/client → client}/styles/mixins/variable.scss +0 -0
  75. package/{src/client → client}/styles/palette.scss +0 -0
  76. package/client/styles/third/katex.scss +3 -0
  77. package/{src/client → client}/styles/vars.scss +0 -0
  78. package/{src/client → client}/styles/widgets/banner.scss +0 -0
  79. package/{src/client → client}/types.ts +0 -0
  80. package/{src/client → client}/utils/helper.ts +0 -0
  81. package/{src/client → client}/utils/index.ts +0 -0
  82. package/{src/client → client}/utils/time.ts +0 -0
  83. package/dist/chunk-EAN2KU6W.mjs +1 -0
  84. package/dist/chunk-RSQONJW3.mjs +86 -0
  85. package/dist/chunk-U5OMNIOK.js +1 -0
  86. package/dist/chunk-XQIGHIAX.js +86 -0
  87. package/dist/client/index.d.ts +188 -0
  88. package/dist/client/index.js +1 -0
  89. package/dist/client/index.mjs +1 -0
  90. package/dist/{config-de04677b.d.ts → config-7bd43d41.d.ts} +24 -12
  91. package/dist/node/cli.js +10 -10
  92. package/dist/node/cli.mjs +10 -10
  93. package/dist/node/index.d.ts +2 -2
  94. package/dist/node/index.js +1 -1
  95. package/dist/node/index.mjs +1 -1
  96. package/dist/posts-32f55e33.d.ts +117 -0
  97. package/dist/types/index.d.ts +8 -0
  98. package/dist/types/index.js +1 -0
  99. package/dist/types/index.mjs +0 -0
  100. package/index.d.ts +3 -0
  101. package/{src/node → node}/build.ts +0 -0
  102. package/{src/node → node}/cli.ts +3 -2
  103. package/node/config.ts +170 -0
  104. package/{src/node → node}/index.ts +0 -0
  105. package/{src/node → node}/markdown/check.ts +0 -0
  106. package/{src/node → node}/markdown/highlight.ts +0 -0
  107. package/{src/node → node}/markdown/index.ts +0 -0
  108. package/{src/node → node}/markdown/markdown-it/container.ts +0 -0
  109. package/{src/node → node}/markdown/markdown-it/headings.ts +0 -0
  110. package/{src/node → node}/markdown/markdown-it/highlightLines.ts +0 -0
  111. package/{src/node → node}/markdown/markdown-it/katex.ts +0 -0
  112. package/{src/node → node}/markdown/markdown-it/parseHeader.ts +0 -0
  113. package/{src/node → node}/markdown/slugify.ts +0 -0
  114. package/{src/node → node}/options.ts +2 -2
  115. package/{src/node → node}/plugins/extendConfig.ts +3 -1
  116. package/{src/node → node}/plugins/index.ts +10 -3
  117. package/{src/node → node}/plugins/markdown.ts +3 -6
  118. package/{src/node → node}/plugins/preset.ts +0 -30
  119. package/{src/node → node}/plugins/unocss.ts +0 -0
  120. package/{src/node → node}/plugins/valaxy.ts +0 -0
  121. package/{src/node → node}/rss.ts +0 -0
  122. package/{src/node → node}/server.ts +6 -4
  123. package/{src/node → node}/shims.d.ts +0 -0
  124. package/{src/node → node}/utils/cli.ts +1 -1
  125. package/node/utils/index.ts +48 -0
  126. package/node/utils/net.ts +20 -0
  127. package/{src/node → node}/vite.ts +5 -1
  128. package/package.json +21 -16
  129. package/tsup.config.ts +4 -3
  130. package/{src/types → types}/config.ts +27 -107
  131. package/{src/types → types}/index.ts +0 -0
  132. package/{src/types → types}/posts.ts +5 -0
  133. package/dist/chunk-6QPICP7C.mjs +0 -1
  134. package/dist/chunk-PICIUZML.js +0 -83
  135. package/dist/chunk-S2VGPR56.mjs +0 -83
  136. package/dist/chunk-ZP4HS4GX.js +0 -1
  137. package/dist/index.d.ts +0 -407
  138. package/dist/index.js +0 -1
  139. package/dist/index.mjs +0 -1
  140. package/src/client/composables/features/index.ts +0 -1
  141. package/src/client/composables/features/katex.ts +0 -15
  142. package/src/client/composables/search/algolia.ts +0 -115
  143. package/src/client/modules/pwa.ts +0 -12
  144. package/src/client/styles/common/scrollbar.scss +0 -34
  145. package/src/index.ts +0 -2
  146. package/src/node/config.ts +0 -52
  147. package/src/node/utils/index.ts +0 -26
@@ -1,12 +1,12 @@
1
1
  import * as vite from 'vite';
2
2
  import { InlineConfig } from 'vite';
3
- import { V as ValaxyConfig } from '../config-de04677b.js';
3
+ import { V as ValaxyConfig } from '../config-7bd43d41.js';
4
4
  import 'type-fest';
5
5
  import 'unocss/vite';
6
+ import 'vite-plugin-md';
6
7
  import 'markdown-it';
7
8
  import 'markdown-it-anchor';
8
9
  import 'katex';
9
- import 'vite-plugin-md';
10
10
 
11
11
  interface ResolvedValaxyOptions {
12
12
  mode: 'dev' | 'build';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkPICIUZMLjs = require('../chunk-PICIUZML.js');require('../chunk-ZP4HS4GX.js');exports.createServer = _chunkPICIUZMLjs.g;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkXQIGHIAXjs = require('../chunk-XQIGHIAX.js');require('../chunk-U5OMNIOK.js');exports.createServer = _chunkXQIGHIAXjs.g;
@@ -1 +1 @@
1
- import{g as o}from"../chunk-S2VGPR56.mjs";import"../chunk-6QPICP7C.mjs";export{o as createServer};
1
+ import{g as o}from"../chunk-RSQONJW3.mjs";import"../chunk-EAN2KU6W.mjs";export{o as createServer};
@@ -0,0 +1,117 @@
1
+ interface Post extends Record<string, any> {
2
+ /**
3
+ * Path of post
4
+ * route.path
5
+ * @description 路径
6
+ */
7
+ path?: string;
8
+ /**
9
+ * Title
10
+ * @description 文章标题
11
+ */
12
+ title?: string;
13
+ date?: string | number | Date;
14
+ /**
15
+ * Updated Time
16
+ */
17
+ updated?: string | number | Date;
18
+ lang?: string;
19
+ /**
20
+ * TODO
21
+ * Read Time
22
+ * @description 阅读时长
23
+ */
24
+ duration?: string;
25
+ /**
26
+ * post card type, can be bilibili/yuque/...
27
+ */
28
+ type?: string;
29
+ /**
30
+ * override url, and jump directly
31
+ */
32
+ url?: string;
33
+ /**
34
+ * @description 摘要
35
+ */
36
+ excerpt?: string;
37
+ /**
38
+ * Display sponsor info
39
+ * @description 是否开启赞助
40
+ */
41
+ sponsor?: boolean;
42
+ /**
43
+ * Copyright
44
+ * @description 是否显示文章底部版权信息
45
+ */
46
+ copyright?: boolean;
47
+ /**
48
+ * Category
49
+ * @description 分类,若为数组,则按顺序代表多层文件夹
50
+ */
51
+ categories?: string | string[];
52
+ /**
53
+ * Tags
54
+ * @description 标签,可以有多个
55
+ */
56
+ tags?: string[];
57
+ /**
58
+ * display prev next
59
+ * @description 是否显示前一篇、后一篇导航
60
+ */
61
+ nav?: boolean;
62
+ /**
63
+ * icon before title
64
+ */
65
+ icon?: string;
66
+ /**
67
+ * title color
68
+ */
69
+ color?: string;
70
+ /**
71
+ * display comment
72
+ */
73
+ comment?: boolean;
74
+ /**
75
+ * post is end
76
+ * @description 是否完结,将在末尾添加衬线字体 Q.E.D.
77
+ */
78
+ end?: boolean;
79
+ /**
80
+ * use aplayer
81
+ */
82
+ aplayer?: boolean;
83
+ /**
84
+ * use katex
85
+ */
86
+ katex?: boolean;
87
+ /**
88
+ * use codepen
89
+ */
90
+ codepen?: boolean;
91
+ /**
92
+ * 置顶
93
+ */
94
+ top?: number;
95
+ /**
96
+ * display toc
97
+ * @description 是否显示目录
98
+ */
99
+ toc?: boolean;
100
+ /**
101
+ * is draft
102
+ * @description 是否为草稿
103
+ */
104
+ draft?: boolean;
105
+ /**
106
+ * cover
107
+ * @description 封面图片
108
+ */
109
+ cover?: string;
110
+ /**
111
+ * enable markdown-body class
112
+ * @description 是否启用默认的 markdown 样式
113
+ */
114
+ markdown: boolean;
115
+ }
116
+
117
+ export { Post as P };
@@ -0,0 +1,8 @@
1
+ export { A as AlgoliaSearchOptions, S as SocialLink, U as UserConfig, V as ValaxyConfig, a as ValaxyThemeConfig, b as ViteMdOptions } from '../config-7bd43d41.js';
2
+ export { P as Post } from '../posts-32f55e33.js';
3
+ import 'type-fest';
4
+ import 'unocss/vite';
5
+ import 'vite-plugin-md';
6
+ import 'markdown-it';
7
+ import 'markdown-it-anchor';
8
+ import 'katex';
@@ -0,0 +1 @@
1
+ "use strict";
File without changes
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ // export * from './dist/client'
2
+ export * from './dist/node'
3
+ export * from './dist/types'
File without changes
@@ -9,7 +9,8 @@ import openBrowser from 'open'
9
9
  import consola from 'consola'
10
10
 
11
11
  import { yellow } from 'kolorist'
12
- import { version } from '../../package.json'
12
+ import { version } from '../package.json'
13
+ import { findFreePort } from './utils/net'
13
14
  import { resolveOptions } from './options'
14
15
  import { bindShortcut, initServer, printInfo } from './utils/cli'
15
16
 
@@ -59,7 +60,7 @@ cli.command(
59
60
  if (!fs.existsSync(path.resolve(root, 'pages')))
60
61
  process.exit(0)
61
62
 
62
- const port = userPort || 4859
63
+ const port = await findFreePort(userPort || 4859)
63
64
  const options = await resolveOptions({ userRoot: root })
64
65
 
65
66
  const viteConfig: InlineConfig = {
package/node/config.ts ADDED
@@ -0,0 +1,170 @@
1
+ // import { loadConfig } from 'c12'
2
+ import fs from 'fs'
3
+ import { loadConfig } from 'unconfig'
4
+ import defu from 'defu'
5
+ import type { YunTheme } from 'valaxy-theme-yun'
6
+ import type { UserConfig, ValaxyConfig } from '../types'
7
+ import type { ValaxyEntryOptions } from './options'
8
+
9
+ const defaultValaxyConfig: ValaxyConfig = {
10
+ url: '',
11
+ lang: 'en',
12
+ title: 'Valaxy Blog',
13
+ description: 'A blog generated by Valaxy.',
14
+ subtitle: 'Next Generation Static Blog Framework.',
15
+ author: {
16
+ avatar: 'https://cdn.jsdelivr.net/gh/YunYouJun/yun/images/meme/yun-good-with-bg.jpg',
17
+ email: 'me@yunyoujun.cn',
18
+ link: 'https://www.yunyoujun.cn',
19
+ name: 'YunYouJun',
20
+ status: {
21
+ emoji: '😊',
22
+ message: 'All at sea.',
23
+ },
24
+ },
25
+ favicon: 'favicon.svg',
26
+ feed: {
27
+ name: '',
28
+ favicon: 'favicon.svg',
29
+ },
30
+ social: [],
31
+
32
+ license: {
33
+ enabled: true,
34
+ language: '',
35
+ type: 'by-nc-sa',
36
+ },
37
+
38
+ sponsor: {
39
+ enable: true,
40
+ title: '我很可爱,请给我钱',
41
+ methods: [
42
+ {
43
+ name: '支付宝',
44
+ url: 'https://cdn.jsdelivr.net/gh/YunYouJun/cdn/img/donate/alipay-qrcode.jpg',
45
+ color: '#00A3EE',
46
+ icon: 'i-ri-alipay-line',
47
+ },
48
+ {
49
+ name: 'QQ 支付',
50
+ url: 'https://cdn.jsdelivr.net/gh/YunYouJun/cdn/img/donate/qqpay-qrcode.png',
51
+ color: '#12B7F5',
52
+ icon: 'i-ri-qq-line',
53
+ },
54
+ {
55
+ name: '微信支付',
56
+ url: 'https://cdn.jsdelivr.net/gh/YunYouJun/cdn/img/donate/wechatpay-qrcode.jpg',
57
+ color: '#2DC100',
58
+ icon: 'i-ri-wechat-pay-line',
59
+ },
60
+
61
+ ],
62
+ },
63
+
64
+ search: {
65
+ enable: true,
66
+ algolia: {
67
+ enable: false,
68
+ appId: '',
69
+ apiKey: '',
70
+ indexName: '',
71
+ },
72
+ },
73
+
74
+ comment: {
75
+ waline: {
76
+ enable: false,
77
+ serverURL: '',
78
+ },
79
+ twikoo: {
80
+ enable: false,
81
+ envId: 'https://twikoo.vercel.app',
82
+ },
83
+ },
84
+
85
+ features: {
86
+ katex: true,
87
+ },
88
+
89
+ theme: 'yun',
90
+ themeConfig: {
91
+ pkg: {
92
+ name: '',
93
+ version: '',
94
+ },
95
+ },
96
+
97
+ unocss: {},
98
+
99
+ markdown: {
100
+ excerpt: '<!-- more -->',
101
+ },
102
+ markdownIt: {
103
+ toc: {
104
+ includeLevel: [1, 2, 3, 4],
105
+ listType: 'ol',
106
+ },
107
+ katex: {},
108
+ },
109
+ }
110
+
111
+ // for user config
112
+ export async function resolveConfig(options: ValaxyEntryOptions = {}) {
113
+ // c12 merge array twice, so i deprecated it
114
+ // const { config, configFile } = await loadConfig<ValaxyConfig>({
115
+ // name: 'valaxy',
116
+ // defaults: defaultValaxyConfig,
117
+ // })
118
+
119
+ const { config: userConfig, sources } = await loadConfig<ValaxyConfig>({
120
+ sources: [
121
+ {
122
+ files: 'valaxy.config',
123
+ extensions: ['ts', 'js', 'mjs', 'cjs', 'json'],
124
+ },
125
+ ],
126
+ merge: false,
127
+ })
128
+ const configFile = sources[0]
129
+ const config = defu(userConfig, defaultValaxyConfig)
130
+
131
+ const theme = options.theme || config.theme || 'yun'
132
+
133
+ try {
134
+ const { defaultThemeConfig } = await import(`valaxy-theme-${theme}`)
135
+ config.themeConfig = defu(config.themeConfig, defaultThemeConfig)
136
+ }
137
+ catch (e) {
138
+ console.error(`valaxy-theme-${theme} doesn't have default config`)
139
+ }
140
+
141
+ try {
142
+ const pkg = fs.readFileSync(require.resolve(`valaxy-theme-${theme}/package.json`), 'utf-8')
143
+ config.themeConfig.pkg = JSON.parse(pkg)
144
+ }
145
+ catch (e) {
146
+ console.error(`valaxy-theme-${theme} doesn't have package.json`)
147
+ }
148
+
149
+ return {
150
+ config,
151
+ configFile,
152
+ theme,
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Type config helper
158
+ */
159
+ export function defineConfig(config: UserConfig<YunTheme.Config>) {
160
+ return config
161
+ }
162
+
163
+ /**
164
+ * Type config helper for custom theme config
165
+ */
166
+ export function defineConfigWithTheme<ThemeConfig>(
167
+ config: UserConfig<ThemeConfig>,
168
+ ) {
169
+ return config
170
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -66,12 +66,12 @@ export function getThemeRoot(name: string, entry: string) {
66
66
  if (isPath(name))
67
67
  return resolve(dirname(entry), name)
68
68
  else
69
- return resolveImportPath(`valaxy-theme-${name}/package.json`)
69
+ return dirname(resolveImportPath(`valaxy-theme-${name}/package.json`) || '')
70
70
  }
71
71
 
72
72
  // for cli options
73
73
  export async function resolveOptions(options: ValaxyEntryOptions, mode: ResolvedValaxyOptions['mode'] = 'dev') {
74
- const clientRoot = resolve(resolveImportPath('valaxy/package.json'), 'src/client')
74
+ const clientRoot = resolve(dirname(resolveImportPath('valaxy/package.json', true)), 'client')
75
75
  const userRoot = resolve(options.userRoot || process.cwd())
76
76
 
77
77
  const { config: valaxyConfig, configFile, theme } = await resolveConfig(options)
@@ -13,10 +13,11 @@ export function createConfigPlugin(options: ResolvedValaxyOptions): Plugin {
13
13
  alias: {
14
14
  '@/': `${toAtFS(options.userRoot)}/`,
15
15
  '~/': `${toAtFS(options.clientRoot)}/`,
16
+ 'valaxy/client': `${toAtFS(options.clientRoot)}/`,
16
17
  '@valaxyjs/client': `${toAtFS(options.clientRoot)}/`,
17
18
  '@valaxyjs/config': '/@valaxyjs/config',
18
19
  'valaxy/package.json': toAtFS(resolve(options.clientRoot, '../../package.json')),
19
- 'valaxy/': `${toAtFS(resolve(options.clientRoot, '../..'))}/`,
20
+ 'valaxy/': `${toAtFS(resolve(options.clientRoot, '..'))}/`,
20
21
  'valaxy': toAtFS(resolve(options.clientRoot, '../index.ts')),
21
22
  [`valaxy-theme-${options.theme}/`]: `${toAtFS(resolve(options.themeRoot))}/`,
22
23
  [`valaxy-theme-${options.theme}`]: `${toAtFS(resolve(options.themeRoot))}`,
@@ -35,6 +36,7 @@ export function createConfigPlugin(options: ResolvedValaxyOptions): Plugin {
35
36
  'dayjs',
36
37
  'nprogress',
37
38
  ],
39
+
38
40
  },
39
41
  }
40
42
  return mergeConfig(config, injection)
@@ -5,7 +5,7 @@ import type { Plugin } from 'vite'
5
5
  // import consola from 'consola'
6
6
  import { resolveConfig } from '../config'
7
7
  import type { ResolvedValaxyOptions, ValaxyServerOptions } from '../options'
8
- import { toAtFS } from '../utils'
8
+ import { resolveImportPath, toAtFS } from '../utils'
9
9
  import { VALAXY_CONFIG_ID } from './valaxy'
10
10
 
11
11
  /**
@@ -13,9 +13,15 @@ import { VALAXY_CONFIG_ID } from './valaxy'
13
13
  * @param roots
14
14
  * @returns
15
15
  */
16
- function generateStyles(roots: string[]) {
16
+ function generateStyles(roots: string[], options: ResolvedValaxyOptions) {
17
17
  const imports: string[] = []
18
18
 
19
+ // katex
20
+ if (options.config.features.katex) {
21
+ imports.push(`import "${toAtFS(resolveImportPath('katex/dist/katex.min.css', true))}"`)
22
+ imports.push(`import "${join(options.clientRoot, 'styles/third/katex.scss')}"`)
23
+ }
24
+
19
25
  for (const root of roots) {
20
26
  const styles: string[] = []
21
27
 
@@ -30,6 +36,7 @@ function generateStyles(roots: string[]) {
30
36
  imports.push(`import "${toAtFS(style)}"`)
31
37
  }
32
38
  }
39
+
33
40
  return imports.join('\n')
34
41
  }
35
42
 
@@ -85,7 +92,7 @@ export function createValaxyPlugin(options: ResolvedValaxyOptions, serverOptions
85
92
 
86
93
  // generate styles
87
94
  if (id === '/@valaxyjs/styles')
88
- return generateStyles(roots)
95
+ return generateStyles(roots, options)
89
96
 
90
97
  if (id === '/@valaxyjs/locales')
91
98
  return generateLocales(roots)
@@ -6,8 +6,6 @@ import type { ResolvedValaxyOptions } from '../options'
6
6
  import { setupMarkdownPlugins } from '../markdown'
7
7
  import { checkMd } from '../markdown/check'
8
8
 
9
- export type ViteMdOptions = Parameters<typeof Markdown>[0]
10
-
11
9
  export const excerpt_separator = '<!-- more -->'
12
10
 
13
11
  // https://github.com/antfu/vite-plugin-md
@@ -15,7 +13,7 @@ export const excerpt_separator = '<!-- more -->'
15
13
  export function createMarkdownPlugin(options: ResolvedValaxyOptions): Plugin[] {
16
14
  const mdOptions = options.config.markdownIt
17
15
 
18
- const defaultOptions: ViteMdOptions = {
16
+ return [Markdown({
19
17
  wrapperComponent: 'ValaxyMd',
20
18
  wrapperClasses: '',
21
19
 
@@ -39,9 +37,8 @@ export function createMarkdownPlugin(options: ResolvedValaxyOptions): Plugin[] {
39
37
  return code
40
38
  },
41
39
  },
42
- }
43
-
44
- return [Markdown(Object.assign(defaultOptions, options.config.markdown)), {
40
+ ...options.config.markdown,
41
+ }), {
45
42
  name: 'valaxy:md',
46
43
  handleHotUpdate(ctx) {
47
44
  const { file, server } = ctx
@@ -10,7 +10,6 @@ import Vue from '@vitejs/plugin-vue'
10
10
  import Pages from 'vite-plugin-pages'
11
11
  import Layouts from 'vite-plugin-vue-layouts'
12
12
  import Components from 'unplugin-vue-components/vite'
13
- import { VitePWA } from 'vite-plugin-pwa'
14
13
  import VueI18n from '@intlify/vite-plugin-vue-i18n'
15
14
  import Inspect from 'vite-plugin-inspect'
16
15
 
@@ -173,35 +172,6 @@ export async function ViteValaxyPlugins(
173
172
 
174
173
  ...MarkdownPlugin,
175
174
 
176
- // https://github.com/antfu/vite-plugin-pwa
177
- VitePWA({
178
- registerType: 'autoUpdate',
179
- includeAssets: ['favicon.svg', 'safari-pinned-tab.svg'],
180
- manifest: {
181
- name: 'Theme Yun',
182
- short_name: 'Yun',
183
- theme_color: '#ffffff',
184
- icons: [
185
- {
186
- src: '/pwa-192x192.png',
187
- sizes: '192x192',
188
- type: 'image/png',
189
- },
190
- {
191
- src: '/pwa-512x512.png',
192
- sizes: '512x512',
193
- type: 'image/png',
194
- },
195
- {
196
- src: '/pwa-512x512.png',
197
- sizes: '512x512',
198
- type: 'image/png',
199
- purpose: 'any maskable',
200
- },
201
- ],
202
- },
203
- }),
204
-
205
175
  // https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n
206
176
  VueI18n({
207
177
  runtimeOnly: true,
File without changes
File without changes
File without changes
@@ -12,10 +12,12 @@ export async function createServer(
12
12
  // default editor vscode
13
13
  process.env.EDITOR = process.env.EDITOR || 'code'
14
14
 
15
- const server = await createViteServer(mergeConfig(
16
- viteConfig,
17
- await createViteConfig(options, serverOptions),
18
- ))
15
+ const server = await createViteServer(
16
+ mergeConfig(
17
+ viteConfig,
18
+ await createViteConfig(options, serverOptions),
19
+ ),
20
+ )
19
21
 
20
22
  return server
21
23
  }
File without changes
@@ -7,7 +7,7 @@ import consola from 'consola'
7
7
  import type { InlineConfig, ViteDevServer } from 'vite'
8
8
  import { createServer } from '../server'
9
9
  import type { ResolvedValaxyOptions } from '../options'
10
- import { version } from '../../../package.json'
10
+ import { version } from '../../package.json'
11
11
  import { createSafelist } from '../plugins/unocss'
12
12
 
13
13
  let server: ViteDevServer | undefined
@@ -0,0 +1,48 @@
1
+ import { join } from 'path'
2
+ import isInstalledGlobally from 'is-installed-globally'
3
+ import globalDirs from 'global-dirs'
4
+ import { sync as resolve } from 'resolve'
5
+ import consola from 'consola'
6
+
7
+ export function slash(str: string) {
8
+ return str.replace(/\\/g, '/')
9
+ }
10
+
11
+ export function ensurePrefix(prefix: string, str: string) {
12
+ if (!str.startsWith(prefix))
13
+ return prefix + str
14
+ return str
15
+ }
16
+
17
+ export function toAtFS(path: string) {
18
+ return `/@fs${ensurePrefix('/', slash(path))}`
19
+ }
20
+
21
+ export function resolveImportPath(importName: string, ensure: true): string
22
+ export function resolveImportPath(importName: string, ensure?: boolean): string | undefined
23
+ export function resolveImportPath(importName: string, ensure = false) {
24
+ try {
25
+ return resolve(importName, {
26
+ preserveSymlinks: false,
27
+ })
28
+ }
29
+ catch {}
30
+
31
+ if (isInstalledGlobally) {
32
+ try {
33
+ return require.resolve(join(globalDirs.yarn.packages, importName))
34
+ }
35
+ catch {}
36
+
37
+ try {
38
+ return require.resolve(join(globalDirs.npm.packages, importName))
39
+ }
40
+ catch {}
41
+ }
42
+
43
+ if (ensure)
44
+ throw new Error(`Failed to resolve package ${importName}`)
45
+
46
+ consola.error(`Failed to resolve package ${importName}`)
47
+ return undefined
48
+ }
@@ -0,0 +1,20 @@
1
+ import net from 'net'
2
+
3
+ export async function findFreePort(start: number): Promise<number> {
4
+ if (await isPortFree(start))
5
+ return start
6
+ return await findFreePort(start + 1)
7
+ }
8
+
9
+ function isPortFree(port: number): Promise<boolean> {
10
+ return new Promise((resolve) => {
11
+ const server = net.createServer()
12
+ .listen(port, () => {
13
+ server.close()
14
+ resolve(true)
15
+ })
16
+ .on('error', () => {
17
+ resolve(false)
18
+ })
19
+ })
20
+ }
@@ -1,9 +1,10 @@
1
- import { join } from 'path'
1
+ import { dirname, join } from 'path'
2
2
  import type { InlineConfig } from 'vite'
3
3
  import { splitVendorChunkPlugin } from 'vite'
4
4
  import type { ResolvedValaxyOptions, ValaxyServerOptions } from './options'
5
5
 
6
6
  import { ViteValaxyPlugins } from './plugins/preset'
7
+ import { resolveImportPath } from './utils'
7
8
 
8
9
  export type Mode = 'dev' | 'build'
9
10
 
@@ -24,6 +25,8 @@ export async function createViteConfig(options: ResolvedValaxyOptions, serverOpt
24
25
  // always string
25
26
  define: {
26
27
  __DEV__: options.mode === 'dev' ? 'true' : 'false',
28
+
29
+ __ALGOLIA__: !!options.config.search.algolia.enable,
27
30
  },
28
31
 
29
32
  root: options.clientRoot,
@@ -39,6 +42,7 @@ export async function createViteConfig(options: ResolvedValaxyOptions, serverOpt
39
42
  options.clientRoot,
40
43
  options.themeRoot,
41
44
  options.userRoot,
45
+ dirname(resolveImportPath('katex/package.json', true)),
42
46
  ],
43
47
  },
44
48
  },