valaxy 0.3.11 → 0.6.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 (150) hide show
  1. package/README.md +0 -4
  2. package/{src/client → client}/App.vue +0 -0
  3. package/{src/client/composables/search/index.ts → client/app/data.ts} +0 -0
  4. package/{src/client → client}/components/AppLink.vue +0 -0
  5. package/client/components/PostCard.vue +84 -0
  6. package/{src/client → client}/components/PostList.vue +0 -0
  7. package/{src/client → client}/components/README.md +0 -0
  8. package/{src/client → client}/components/ValaxyBg.vue +0 -0
  9. package/{src/client → client}/components/ValaxyCopyright.vue +0 -0
  10. package/{src/client → client}/components/ValaxyFooter.vue +1 -1
  11. package/{src/client → client}/components/ValaxyHamburger.vue +0 -0
  12. package/{src/client → client}/components/ValaxyMd.vue +1 -5
  13. package/{src/client → client}/components/ValaxyOverlay.vue +0 -0
  14. package/{src/client → client}/components/ValaxyPagination.vue +0 -0
  15. package/{src/client → client}/components/ValaxyRightSidebar.vue +0 -0
  16. package/{src/client → client}/components/ValaxySidebar.vue +0 -0
  17. package/{src/client → client}/components/ValaxyToc.vue +3 -3
  18. package/{src/client → client}/composables/category.ts +0 -0
  19. package/{src/client → client}/composables/comments/index.ts +0 -0
  20. package/{src/client → client}/composables/comments/twikoo.ts +0 -0
  21. package/{src/client → client}/composables/comments/waline.ts +0 -0
  22. package/{src/client → client}/composables/common.ts +0 -0
  23. package/{src/client → client}/composables/dark.ts +0 -0
  24. package/client/composables/features/index.ts +0 -0
  25. package/{src/client → client}/composables/helper.ts +0 -0
  26. package/{src/client → client}/composables/index.ts +1 -1
  27. package/{src/client → client}/composables/layout.ts +0 -0
  28. package/client/composables/outline.ts +181 -0
  29. package/{src/client → client}/composables/post.ts +0 -0
  30. package/client/composables/search/index.ts +0 -0
  31. package/{src/client → client}/composables/sidebar.ts +68 -9
  32. package/{src/client → client}/composables/tag.ts +0 -0
  33. package/{src/client → client}/composables/widgets/aplayer.ts +0 -0
  34. package/{src/client → client}/composables/widgets/backToTop.ts +0 -0
  35. package/{src/client → client}/composables/widgets/codepen.ts +0 -0
  36. package/{src/client → client}/composables/widgets/index.ts +0 -0
  37. package/client/config.ts +75 -0
  38. package/{src/client → client}/index.html +0 -0
  39. package/{src/client → client}/index.ts +0 -0
  40. package/{src/client → client}/layouts/404.vue +0 -0
  41. package/{src/client → client}/layouts/README.md +0 -0
  42. package/{src/client → client}/locales/README.md +0 -0
  43. package/{src/client → client}/locales/en.yml +1 -0
  44. package/{src/client → client}/locales/zh-CN.yml +4 -3
  45. package/{src/client → client}/main.ts +8 -1
  46. package/{src/client → client}/modules/README.md +0 -0
  47. package/{src/client → client}/modules/nprogress.ts +0 -0
  48. package/{src/client → client}/modules/pinia.ts +0 -0
  49. package/{src/client → client}/modules/valaxy.ts +34 -9
  50. package/{src/client → client}/pages/README.md +0 -0
  51. package/{src/client → client}/pages/[...all].vue +0 -0
  52. package/{src/client → client}/pages/hi/[name].vue +0 -0
  53. package/{src/client → client}/pages/index.vue +0 -0
  54. package/{src/client → client}/pages/page/[page].vue +0 -0
  55. package/{src/client → client}/shims.d.ts +7 -1
  56. package/{src/client → client}/stores/app.ts +0 -0
  57. package/{src/client → client}/stores/user.ts +0 -0
  58. package/{src/client → client}/styles/common/button.scss +0 -0
  59. package/{src/client → client}/styles/common/code.scss +0 -0
  60. package/{src/client → client}/styles/common/custom-blocks.scss +0 -0
  61. package/{src/client → client}/styles/common/hamburger.scss +0 -0
  62. package/{src/client → client}/styles/common/markdown.scss +5 -1
  63. package/client/styles/common/scrollbar.scss +28 -0
  64. package/{src/client → client}/styles/common/sidebar.scss +0 -0
  65. package/{src/client → client}/styles/common/transition.scss +0 -0
  66. package/{src/client → client}/styles/css-vars.scss +0 -0
  67. package/{src/client → client}/styles/global/helper.scss +0 -0
  68. package/{src/client → client}/styles/global/i18n.scss +0 -0
  69. package/{src/client → client}/styles/global/index.scss +0 -0
  70. package/{src/client → client}/styles/global/nprogress.scss +0 -0
  71. package/{src/client → client}/styles/global/reset.scss +0 -0
  72. package/{src/client → client}/styles/index.scss +0 -0
  73. package/{src/client → client}/styles/mixins/config.scss +0 -0
  74. package/{src/client → client}/styles/mixins/index.scss +0 -0
  75. package/{src/client → client}/styles/mixins/size.scss +0 -0
  76. package/{src/client → client}/styles/mixins/variable.scss +0 -0
  77. package/{src/client → client}/styles/palette.scss +6 -2
  78. package/client/styles/third/katex.scss +3 -0
  79. package/{src/client → client}/styles/vars.scss +0 -0
  80. package/{src/client → client}/styles/widgets/banner.scss +0 -0
  81. package/{src/client → client}/types.ts +0 -0
  82. package/{src/client → client}/utils/helper.ts +22 -0
  83. package/{src/client → client}/utils/index.ts +0 -0
  84. package/client/utils/sidebar.ts +26 -0
  85. package/{src/client → client}/utils/time.ts +0 -0
  86. package/config/index.ts +18 -0
  87. package/dist/chunk-CP3UCJ2D.js +34 -0
  88. package/dist/chunk-EAN2KU6W.mjs +1 -0
  89. package/dist/chunk-HCVZ2UUO.mjs +34 -0
  90. package/dist/chunk-U5OMNIOK.js +1 -0
  91. package/dist/{config-de04677b.d.ts → config-ad23e743.d.ts} +28 -14
  92. package/dist/index.d.ts +67 -111
  93. package/dist/index.js +1 -1
  94. package/dist/index.mjs +1 -1
  95. package/dist/node/cli.js +7 -11
  96. package/dist/node/cli.mjs +7 -11
  97. package/dist/node/index.d.ts +2 -2
  98. package/dist/node/index.js +1 -1
  99. package/dist/node/index.mjs +1 -1
  100. package/{src/index.ts → index.ts} +1 -0
  101. package/{src/node → node}/build.ts +0 -0
  102. package/{src/node → node}/cli.ts +3 -2
  103. package/node/config.ts +156 -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 +21 -13
  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/node/markdown/markdownToVue.ts +253 -0
  114. package/{src/node → node}/markdown/slugify.ts +0 -0
  115. package/{src/node → node}/options.ts +18 -2
  116. package/{src/node → node}/plugins/extendConfig.ts +6 -3
  117. package/node/plugins/index.ts +224 -0
  118. package/{src/node → node}/plugins/preset.ts +6 -36
  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 +1 -1
  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/getGitTimestamp.ts +13 -0
  126. package/node/utils/index.ts +59 -0
  127. package/node/utils/net.ts +20 -0
  128. package/{src/node → node}/vite.ts +5 -1
  129. package/package.json +33 -13
  130. package/shared/index.ts +1 -0
  131. package/tsup.config.ts +7 -4
  132. package/{src/types → types}/config.ts +31 -108
  133. package/types/data.ts +31 -0
  134. package/{src/types → types}/index.ts +1 -0
  135. package/{src/types → types}/posts.ts +6 -1
  136. package/dist/chunk-6LIOFBAA.mjs +0 -1
  137. package/dist/chunk-ABPVSNYI.js +0 -83
  138. package/dist/chunk-QOANGHSR.mjs +0 -83
  139. package/dist/chunk-V3BMKLEW.js +0 -1
  140. package/src/client/components/PostCard.vue +0 -68
  141. package/src/client/composables/features/index.ts +0 -1
  142. package/src/client/composables/features/katex.ts +0 -15
  143. package/src/client/composables/search/algolia.ts +0 -115
  144. package/src/client/config.ts +0 -51
  145. package/src/client/modules/pwa.ts +0 -12
  146. package/src/client/styles/common/scrollbar.scss +0 -34
  147. package/src/node/config.ts +0 -52
  148. package/src/node/plugins/index.ts +0 -120
  149. package/src/node/plugins/markdown.ts +0 -57
  150. package/src/node/utils/index.ts +0 -26
@@ -0,0 +1,224 @@
1
+ import fs from 'fs'
2
+
3
+ import { join, relative } from 'path'
4
+ import type { Plugin, ResolvedConfig } from 'vite'
5
+ // import consola from 'consola'
6
+ import { resolveConfig } from '../config'
7
+ import type { ResolvedValaxyOptions, ValaxyServerOptions } from '../options'
8
+ import { resolveImportPath, slash, toAtFS } from '../utils'
9
+ import { createMarkdownToVueRenderFn } from '../markdown/markdownToVue'
10
+ import type { PageDataPayload } from '../../types'
11
+ import { checkMd } from '../markdown/check'
12
+ import { VALAXY_CONFIG_ID } from './valaxy'
13
+
14
+ /**
15
+ * for /@valaxyjs/styles
16
+ * @param roots
17
+ * @returns
18
+ */
19
+ function generateStyles(roots: string[], options: ResolvedValaxyOptions) {
20
+ const imports: string[] = []
21
+
22
+ // katex
23
+ if (options.config.features.katex) {
24
+ imports.push(`import "${toAtFS(resolveImportPath('katex/dist/katex.min.css', true))}"`)
25
+ imports.push(`import "${join(options.clientRoot, 'styles/third/katex.scss')}"`)
26
+ }
27
+
28
+ for (const root of roots) {
29
+ const styles: string[] = []
30
+
31
+ const autoloadNames = ['index', 'css-vars']
32
+ autoloadNames.forEach((name) => {
33
+ styles.push(join(root, 'styles', `${name}.css`))
34
+ styles.push(join(root, 'styles', `${name}.scss`))
35
+ })
36
+
37
+ for (const style of styles) {
38
+ if (fs.existsSync(style))
39
+ imports.push(`import "${toAtFS(style)}"`)
40
+ }
41
+ }
42
+
43
+ return imports.join('\n')
44
+ }
45
+
46
+ function generateLocales(roots: string[]) {
47
+ const imports: string[] = [
48
+ 'const messages = { "zh-CN": {}, en: {} }',
49
+ ]
50
+ const languages = ['zh-CN', 'en']
51
+
52
+ roots.forEach((root, i) => {
53
+ languages.forEach((lang) => {
54
+ const langYml = `${root}/locales/${lang}.yml`
55
+ if (fs.existsSync(langYml) && fs.readFileSync(langYml, 'utf-8')) {
56
+ const varName = lang.replace('-', '') + i
57
+ imports.push(`import ${varName} from "${toAtFS(langYml)}"`)
58
+ imports.push(`Object.assign(messages['${lang}'], ${varName})`)
59
+ }
60
+ })
61
+ })
62
+
63
+ imports.push('export default messages')
64
+ return imports.join('\n')
65
+ }
66
+
67
+ export function createValaxyPlugin(options: ResolvedValaxyOptions, serverOptions: ValaxyServerOptions = {}): Plugin {
68
+ const valaxyPrefix = '/@valaxy'
69
+
70
+ let valaxyConfig = options.config
71
+
72
+ const roots = [options.clientRoot, options.themeRoot, options.userRoot]
73
+
74
+ let markdownToVue: Awaited<ReturnType<typeof createMarkdownToVueRenderFn>>
75
+ let hasDeadLinks = false
76
+ let config: ResolvedConfig
77
+
78
+ return {
79
+ name: 'valaxy',
80
+ enforce: 'pre',
81
+
82
+ async configResolved(resolvedConfig) {
83
+ config = resolvedConfig
84
+ markdownToVue = await createMarkdownToVueRenderFn(
85
+ options.userRoot,
86
+ options.config.markdownIt,
87
+ options.pages,
88
+ config.define,
89
+ config.command === 'build',
90
+ config.base,
91
+ options.config.lastUpdated,
92
+ )
93
+ },
94
+
95
+ configureServer(server) {
96
+ server.watcher.add([
97
+ options.configFile,
98
+ options.userRoot,
99
+ options.themeRoot,
100
+ ])
101
+ },
102
+
103
+ resolveId(id) {
104
+ if (id.startsWith(valaxyPrefix))
105
+ return id
106
+ return null
107
+ },
108
+
109
+ load(id) {
110
+ if (id === `/${VALAXY_CONFIG_ID}`)
111
+ // stringify twice for \"
112
+ return `export default ${JSON.stringify(JSON.stringify(valaxyConfig))}`
113
+
114
+ if (id === '/@valaxyjs/context') {
115
+ return `export default ${JSON.stringify(JSON.stringify({
116
+ userRoot: options.userRoot,
117
+ // clientRoot: options.clientRoot,
118
+ }))}`
119
+ }
120
+
121
+ // generate styles
122
+ if (id === '/@valaxyjs/styles')
123
+ return generateStyles(roots, options)
124
+
125
+ if (id === '/@valaxyjs/locales')
126
+ return generateLocales(roots)
127
+
128
+ if (id.startsWith(valaxyPrefix))
129
+ return ''
130
+ },
131
+
132
+ async transform(code, id) {
133
+ if (id.endsWith('.md')) {
134
+ checkMd(code, id)
135
+ code.replace('{%', '\{\%')
136
+ code.replace('%}', '\%\}')
137
+
138
+ // const scripts = [
139
+ // '<script setup>',
140
+ // 'import { useRoute } from "vue-router"',
141
+ // 'const route = useRoute()',
142
+ // `route.meta.headers = ${JSON.stringify(_md.__data)}`,
143
+ // `export const data = JSON.parse(${JSON.stringify(JSON.stringify(pageData))})`,
144
+ // `frontmatter.data = JSON.parse(${JSON.stringify(JSON.stringify(pageData))})`,
145
+ // '</script>',
146
+ // ]
147
+
148
+ // const li = code.lastIndexOf('</script>')
149
+ // code = code.slice(0, li) + scripts.join('\n') + code.slice(li + 9)
150
+
151
+ // transform .md files into vueSrc so plugin-vue can handle it
152
+ const { vueSrc, deadLinks, includes } = await markdownToVue(
153
+ code,
154
+ id,
155
+ config.publicDir,
156
+ )
157
+ if (deadLinks.length)
158
+ hasDeadLinks = true
159
+
160
+ if (includes.length) {
161
+ includes.forEach((i) => {
162
+ this.addWatchFile(i)
163
+ })
164
+ }
165
+
166
+ return vueSrc
167
+ }
168
+ },
169
+
170
+ renderStart() {
171
+ if (hasDeadLinks)
172
+ throw new Error('One or more pages contain dead links.')
173
+ },
174
+
175
+ async handleHotUpdate(ctx) {
176
+ // handle valaxy.config.ts hmr
177
+ const { file, server, read } = ctx
178
+ if (file !== options.configFile)
179
+ return
180
+
181
+ // send headers
182
+ if (file.endsWith('.md')) {
183
+ const content = await read()
184
+ const { pageData, vueSrc } = await markdownToVue(
185
+ content,
186
+ file,
187
+ join(options.userRoot, 'public'),
188
+ )
189
+
190
+ const path = `/${slash(relative(`${options.userRoot}/pages`, file))}`
191
+ const payload: PageDataPayload = {
192
+ // path: `/${slash(relative(srcDir, file))}`,
193
+ path,
194
+ pageData,
195
+ }
196
+
197
+ server.ws.send({
198
+ type: 'custom',
199
+ event: 'valaxy:pageData',
200
+ data: payload,
201
+ })
202
+
203
+ // overwrite src so vue plugin can handle the HMR
204
+ ctx.read = () => vueSrc
205
+ }
206
+
207
+ const { config } = await resolveConfig()
208
+
209
+ serverOptions.onConfigReload?.(config, options.config)
210
+ Object.assign(options.config, config)
211
+
212
+ // if (config.base !== options.config.base)
213
+ // consola.warn('[valaxy]: config.base has changed. Please restart the dev server.')
214
+ valaxyConfig = config
215
+
216
+ const moduleIds = [`/${VALAXY_CONFIG_ID}`, '/@valaxyjs/context']
217
+ const moduleEntries = [
218
+ ...Array.from(moduleIds).map(id => server.moduleGraph.getModuleById(id)),
219
+ ].filter(<T>(item: T): item is NonNullable<T> => !!item)
220
+
221
+ return moduleEntries
222
+ },
223
+ }
224
+ }
@@ -10,14 +10,13 @@ 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
 
17
16
  import { dim, yellow } from 'kolorist'
18
17
  import type { ResolvedValaxyOptions, ValaxyServerOptions } from '../options'
19
18
  import { setupMarkdownPlugins } from '../markdown'
20
- import { createMarkdownPlugin, excerpt_separator } from './markdown'
19
+ // import { createMarkdownPlugin, excerpt_separator } from './markdown'
21
20
  import { createUnocssPlugin } from './unocss'
22
21
  import { createConfigPlugin } from './extendConfig'
23
22
  import { createValaxyPlugin } from '.'
@@ -33,7 +32,7 @@ export async function ViteValaxyPlugins(
33
32
  ): Promise<(PluginOption | PluginOption[])[] | undefined> {
34
33
  const { clientRoot, themeRoot, userRoot } = options
35
34
 
36
- const MarkdownPlugin = createMarkdownPlugin(options)
35
+ // const MarkdownPlugin = createMarkdownPlugin(options)
37
36
  const UnocssPlugin = await createUnocssPlugin(options)
38
37
 
39
38
  const ValaxyPlugin = createValaxyPlugin(options, serverOptions)
@@ -43,7 +42,7 @@ export async function ViteValaxyPlugins(
43
42
 
44
43
  const roots = [clientRoot, themeRoot, userRoot]
45
44
 
46
- const { default: ThemePlugin } = await import(`valaxy-theme-${options.theme}`)
45
+ const { default: ThemePlugin } = (await import(`valaxy-theme-${options.theme}`))
47
46
 
48
47
  const customElements = new Set([
49
48
  // katex
@@ -91,8 +90,8 @@ export async function ViteValaxyPlugins(
91
90
  },
92
91
  }),
93
92
 
94
- ValaxyPlugin,
95
93
  createConfigPlugin(options),
94
+ ValaxyPlugin,
96
95
 
97
96
  ThemePlugin(options.config.themeConfig),
98
97
 
@@ -119,7 +118,7 @@ export async function ViteValaxyPlugins(
119
118
  })
120
119
 
121
120
  const md = fs.readFileSync(path, 'utf-8')
122
- const { data, excerpt } = matter(md, { excerpt_separator })
121
+ const { data, excerpt } = matter(md, { excerpt_separator: '<!-- more -->' })
123
122
 
124
123
  // warn for post frontmatter
125
124
  if (route.path.startsWith('/posts/')) {
@@ -171,36 +170,7 @@ export async function ViteValaxyPlugins(
171
170
  // UnocssPlugin,
172
171
  UnocssPlugin,
173
172
 
174
- ...MarkdownPlugin,
175
-
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
- }),
173
+ // ...MarkdownPlugin,
204
174
 
205
175
  // https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n
206
176
  VueI18n({
File without changes
File without changes
@@ -24,7 +24,7 @@ const markdown = MarkdownIt({
24
24
  export async function build(options: ResolvedValaxyOptions) {
25
25
  const { config } = options
26
26
 
27
- if (!config.url) {
27
+ if (!config.url || config.url === '/') {
28
28
  consola.error('You must set "config.url" to generate rss.')
29
29
  return
30
30
  }
@@ -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,13 @@
1
+ import { spawn } from 'cross-spawn'
2
+
3
+ export function getGitTimestamp(file: string) {
4
+ return new Promise<number>((resolve, reject) => {
5
+ const child = spawn('git', ['log', '-1', '--pretty="%ci"', file])
6
+ let output = ''
7
+ child.stdout.on('data', d => (output += String(d)))
8
+ child.on('close', () => {
9
+ resolve(+new Date(output))
10
+ })
11
+ child.on('error', reject)
12
+ })
13
+ }
@@ -0,0 +1,59 @@
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 * from './getGitTimestamp'
8
+
9
+ /**
10
+ * transform obj for vite cde
11
+ * @param obj
12
+ * @returns
13
+ */
14
+ export const transformObject = (obj: any) => {
15
+ return `JSON.parse(${JSON.stringify(JSON.stringify(obj))})`
16
+ }
17
+
18
+ export function slash(str: string) {
19
+ return str.replace(/\\/g, '/')
20
+ }
21
+
22
+ export function ensurePrefix(prefix: string, str: string) {
23
+ if (!str.startsWith(prefix))
24
+ return prefix + str
25
+ return str
26
+ }
27
+
28
+ export function toAtFS(path: string) {
29
+ return `/@fs${ensurePrefix('/', slash(path))}`
30
+ }
31
+
32
+ export function resolveImportPath(importName: string, ensure: true): string
33
+ export function resolveImportPath(importName: string, ensure?: boolean): string | undefined
34
+ export function resolveImportPath(importName: string, ensure = false) {
35
+ try {
36
+ return resolve(importName, {
37
+ preserveSymlinks: false,
38
+ })
39
+ }
40
+ catch {}
41
+
42
+ if (isInstalledGlobally) {
43
+ try {
44
+ return require.resolve(join(globalDirs.yarn.packages, importName))
45
+ }
46
+ catch {}
47
+
48
+ try {
49
+ return require.resolve(join(globalDirs.npm.packages, importName))
50
+ }
51
+ catch {}
52
+ }
53
+
54
+ if (ensure)
55
+ throw new Error(`Failed to resolve package ${importName}`)
56
+
57
+ consola.error(`Failed to resolve package ${importName}`)
58
+ return undefined
59
+ }
@@ -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
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valaxy",
3
- "version": "0.3.11",
3
+ "version": "0.6.0",
4
4
  "description": "📄 Vite & Vue powered static blog generator.",
5
5
  "author": {
6
6
  "email": "me@yunyoujun.cn",
@@ -16,10 +16,22 @@
16
16
  "blog"
17
17
  ],
18
18
  "exports": {
19
- ".": "./src/index.ts",
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "require": "./dist/index.js",
22
+ "import": "./dist/index.mjs"
23
+ },
24
+ "./client": "./dist/client.d.ts",
25
+ "./client/*": "./client/*",
26
+ "./node": {
27
+ "types": "./dist/node/index.d.ts",
28
+ "require": "./dist/node/index.js",
29
+ "import": "./dist/node/index.mjs"
30
+ },
20
31
  "./*": "./*"
21
32
  },
22
33
  "main": "dist/index.js",
34
+ "module": "dist/index.mjs",
23
35
  "types": "dist/index.d.ts",
24
36
  "bin": {
25
37
  "vala": "./bin/valaxy.js",
@@ -29,20 +41,27 @@
29
41
  "node": ">=14.0.0"
30
42
  },
31
43
  "dependencies": {
44
+ "@antfu/utils": "^0.5.2",
32
45
  "@ctrl/tinycolor": "^3.4.1",
46
+ "@docsearch/css": "^3.1.0",
47
+ "@docsearch/js": "^3.1.0",
33
48
  "@iconify-json/carbon": "^1.1.5",
34
49
  "@iconify-json/ri": "^1.1.2",
35
50
  "@intlify/vite-plugin-vue-i18n": "^3.4.0",
36
51
  "@vitejs/plugin-vue": "^2.3.3",
37
- "@vueuse/core": "^8.6.0",
52
+ "@vueuse/core": "^8.7.4",
38
53
  "@vueuse/head": "^0.7.6",
39
54
  "consola": "^2.15.3",
40
55
  "critters": "^0.0.16",
56
+ "cross-spawn": "^7.0.3",
41
57
  "dayjs": "^1.11.3",
42
58
  "escape-html": "^1.0.3",
43
59
  "feed": "^4.2.2",
60
+ "gray-matter": "^4.0.3",
44
61
  "katex": "^0.16.0",
45
62
  "kolorist": "^1.5.1",
63
+ "lru-cache": "^7.10.1",
64
+ "markdown-it": "^13.0.1",
46
65
  "markdown-it-anchor": "^8.6.4",
47
66
  "markdown-it-attrs": "^4.1.4",
48
67
  "markdown-it-container": "^3.0.0",
@@ -55,37 +74,38 @@
55
74
  "pinia": "^2.0.14",
56
75
  "prism-theme-vars": "^0.2.3",
57
76
  "prismjs": "^1.28.0",
58
- "sass": "^1.52.2",
77
+ "sass": "^1.52.3",
78
+ "shiki": "^0.10.1",
59
79
  "star-markdown-css": "^0.3.3",
60
80
  "unconfig": "^0.3.4",
61
- "unocss": "^0.38.0",
81
+ "unocss": "^0.39.3",
62
82
  "unplugin-vue-components": "^0.19.6",
63
- "vite": "^2.9.10",
83
+ "vite": "^2.9.12",
64
84
  "vite-plugin-inspect": "^0.5.0",
65
- "vite-plugin-md": "^0.13.1",
66
- "vite-plugin-pages": "^0.23.0",
67
- "vite-plugin-pwa": "^0.12.0",
85
+ "vite-plugin-pages": "^0.24.2",
68
86
  "vite-plugin-vue-layouts": "^0.6.0",
69
- "vite-ssg": "0.20.1",
87
+ "vite-ssg": "0.19.2",
70
88
  "vite-ssg-sitemap": "0.2.7",
71
89
  "vue": "^3.2.37",
72
90
  "vue-i18n": "^9.1.10",
73
- "vue-router": "^4.0.15",
91
+ "vue-router": "^4.0.16",
74
92
  "yargs": "^17.5.1"
75
93
  },
76
94
  "devDependencies": {
95
+ "@types/cross-spawn": "^6.0.2",
77
96
  "@types/katex": "^0.14.0",
97
+ "@types/lru-cache": "^7.10.10",
78
98
  "@types/markdown-it-link-attributes": "^3.0.1",
79
99
  "@types/nprogress": "^0.2.0",
80
100
  "@types/yargs": "^17.0.10",
81
101
  "debug": "^4.3.4",
82
102
  "diacritics": "^1.3.0",
83
103
  "https-localhost": "^4.7.1",
84
- "type-fest": "^2.13.0"
104
+ "type-fest": "^2.13.1"
85
105
  },
86
106
  "scripts": {
87
107
  "build": "rimraf dist && tsup --splitting",
88
- "dev": "tsup --watch --splitting",
108
+ "dev": "tsup --splitting --watch",
89
109
  "lint": "eslint \"**/*.{vue,ts,js}\"",
90
110
  "preview": "vite preview",
91
111
  "preview-https": "serve dist"
@@ -0,0 +1 @@
1
+ export const EXTERNAL_URL_RE = /^https?:/i
package/tsup.config.ts CHANGED
@@ -3,19 +3,22 @@ import { defineConfig } from 'tsup'
3
3
  export default defineConfig((options) => {
4
4
  return {
5
5
  entry: [
6
- 'src/index.ts',
7
- 'src/node/index.ts',
8
- 'src/node/cli.ts',
6
+ 'index.ts',
7
+ // 'client/index.ts',
8
+ 'node/index.ts',
9
+ 'node/cli.ts',
10
+ // 'types/index.ts',
9
11
  ],
10
12
  // https://tsup.egoist.sh/#code-splitting
11
13
  // Code splitting currently only works with the esm output format, and it's enabled by default. If you want code splitting for cjs output format as well, try using --splitting flag which is an experimental feature to get rid of the limitation in esbuild.
12
- splitting: true,
14
+ // splitting: true,
13
15
  clean: true,
14
16
  dts: true,
15
17
  format: ['cjs', 'esm'],
16
18
  minify: !options.watch,
17
19
  external: [
18
20
  '@valaxyjs/config',
21
+ '@valaxyjs/context',
19
22
  'valaxy-theme-yun',
20
23
  ],
21
24
  }