valaxy 0.1.1 → 0.1.2

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 (75) hide show
  1. package/bin/valaxy.js +1 -1
  2. package/dist/chunk-5D7M5SQP.js +1 -0
  3. package/dist/{chunk-ESCOXVP6.mjs → chunk-CF6MGLH2.mjs} +42 -41
  4. package/dist/chunk-L22LX2G6.mjs +1 -0
  5. package/dist/chunk-W5MJCUNY.js +84 -0
  6. package/dist/config-d6527c8c.d.ts +174 -0
  7. package/dist/index.d.ts +309 -152
  8. package/dist/index.js +1 -1
  9. package/dist/index.mjs +1 -1
  10. package/dist/{cli.d.ts → node/cli.d.ts} +0 -0
  11. package/dist/node/cli.js +6 -0
  12. package/dist/node/cli.mjs +6 -0
  13. package/dist/node/index.d.ts +46 -0
  14. package/dist/node/index.js +1 -0
  15. package/dist/node/index.mjs +1 -0
  16. package/package.json +18 -17
  17. package/src/client/components/PostCard.vue +1 -1
  18. package/src/client/components/PostList.vue +3 -3
  19. package/src/client/components/ValaxyCopyright.vue +1 -1
  20. package/src/client/components/ValaxyFooter.vue +1 -1
  21. package/src/client/components/ValaxyOverlay.vue +4 -4
  22. package/src/client/components/ValaxyPagination.vue +14 -11
  23. package/src/client/components/ValaxyRightSidebar.vue +2 -2
  24. package/src/client/components/ValaxySidebar.vue +4 -8
  25. package/src/client/components/ValaxyToc.vue +11 -9
  26. package/src/client/composables/comments/waline.ts +8 -4
  27. package/src/client/composables/common.ts +2 -4
  28. package/src/client/composables/search/algolia.ts +2 -1
  29. package/src/client/composables/sidebar.ts +2 -2
  30. package/src/client/composables/tag.ts +1 -1
  31. package/src/client/composables/widgets/backToTop.ts +10 -4
  32. package/src/client/main.ts +1 -6
  33. package/src/client/modules/valaxy.ts +30 -13
  34. package/src/client/shims.d.ts +5 -0
  35. package/src/client/styles/common/button.scss +3 -5
  36. package/src/client/styles/common/hamburger.scss +2 -2
  37. package/src/client/styles/common/markdown.scss +4 -3
  38. package/src/client/styles/common/sidebar.scss +3 -3
  39. package/src/client/styles/common/transition.scss +2 -2
  40. package/src/client/styles/{css-vars/index.scss → css-vars.scss} +22 -8
  41. package/src/client/styles/global/helper.scss +2 -2
  42. package/src/client/styles/global/index.scss +1 -1
  43. package/src/client/styles/global/nprogress.scss +1 -1
  44. package/src/client/styles/global/reset.scss +1 -1
  45. package/src/client/styles/mixins/config.scss +1 -1
  46. package/src/client/styles/mixins/index.scss +1 -0
  47. package/src/client/styles/palette.scss +12 -7
  48. package/src/client/styles/vars.scss +1 -13
  49. package/src/client/styles/widgets/banner.scss +2 -2
  50. package/src/client/utils/index.ts +0 -2
  51. package/src/node/build.ts +20 -1
  52. package/src/node/cli.ts +17 -19
  53. package/src/node/markdown/index.ts +3 -1
  54. package/src/node/markdown/markdown-it-katex.ts +20 -10
  55. package/src/node/markdown/parseHeader.ts +4 -2
  56. package/src/node/options.ts +3 -1
  57. package/src/node/plugins/index.ts +53 -24
  58. package/src/node/plugins/markdown.ts +1 -1
  59. package/src/node/plugins/preset.ts +44 -8
  60. package/src/node/plugins/unocss.ts +12 -7
  61. package/src/node/server.ts +1 -1
  62. package/src/node/shims.d.ts +5 -0
  63. package/src/node/utils/cli.ts +0 -1
  64. package/src/node/vite.ts +7 -15
  65. package/tsup.config.ts +1 -0
  66. package/dist/build-VGAF4K5S.js +0 -1
  67. package/dist/build-Y5F7AZ2V.mjs +0 -1
  68. package/dist/chunk-5KQ3UFYI.js +0 -1
  69. package/dist/chunk-JWA76JND.mjs +0 -1
  70. package/dist/chunk-WYCH73X6.js +0 -83
  71. package/dist/cli.js +0 -6
  72. package/dist/cli.mjs +0 -6
  73. package/src/client/pages/about/index.md +0 -5
  74. package/src/client/styles/css-vars/dark.scss +0 -17
  75. package/src/client/styles/css-vars/light.scss +0 -9
@@ -16,6 +16,7 @@ export interface ValaxyEntryOptions {
16
16
  }
17
17
 
18
18
  export interface ResolvedValaxyOptions {
19
+ mode: 'dev' | 'build'
19
20
  /**
20
21
  * Client root path
21
22
  * @default 'valaxy/src/client'
@@ -69,7 +70,7 @@ export function getThemeRoot(name: string, entry: string) {
69
70
  }
70
71
 
71
72
  // for cli options
72
- export async function resolveOptions(options: ValaxyEntryOptions) {
73
+ export async function resolveOptions(options: ValaxyEntryOptions, mode: ResolvedValaxyOptions['mode'] = 'dev') {
73
74
  const clientRoot = resolve(resolveImportPath('valaxy/package.json'), 'src/client')
74
75
  const userRoot = resolve(options.userRoot || process.cwd())
75
76
 
@@ -77,6 +78,7 @@ export async function resolveOptions(options: ValaxyEntryOptions) {
77
78
  const themeRoot = getThemeRoot(theme, userRoot)
78
79
 
79
80
  const valaxyOptions: ResolvedValaxyOptions = {
81
+ mode,
80
82
  clientRoot,
81
83
  userRoot,
82
84
  themeRoot,
@@ -8,33 +8,58 @@ import type { ResolvedValaxyOptions, ValaxyServerOptions } from '../options'
8
8
  import { toAtFS } from '../utils'
9
9
  import { VALAXY_CONFIG_ID } from './valaxy'
10
10
 
11
- export function createValaxyPlugin(options: ResolvedValaxyOptions, serverOptions: ValaxyServerOptions = {}): Plugin {
12
- const valaxyPrefix = '/@valaxy'
13
-
14
- let valaxyConfig = options.config
11
+ /**
12
+ * for /@valaxyjs/styles
13
+ * @param roots
14
+ * @returns
15
+ */
16
+ function generateStyles(roots: string[]) {
17
+ const imports: string[] = []
18
+
19
+ for (const root of roots) {
20
+ const styles: string[] = []
21
+
22
+ const autoloadNames = ['index', 'css-vars']
23
+ autoloadNames.forEach((name) => {
24
+ styles.push(join(root, 'styles', `${name}.css`))
25
+ styles.push(join(root, 'styles', `${name}.scss`))
26
+ })
27
+
28
+ for (const style of styles) {
29
+ if (fs.existsSync(style))
30
+ imports.push(`import "${toAtFS(style)}"`)
31
+ }
32
+ }
33
+ return imports.join('\n')
34
+ }
15
35
 
16
- const roots = [options.userRoot, options.themeRoot]
36
+ function generateLocales(roots: string[]) {
37
+ const imports: string[] = [
38
+ 'const messages = { "zh-CN": {}, en: {} }',
39
+ ]
40
+ const languages = ['zh-CN', 'en']
41
+
42
+ roots.forEach((root, i) => {
43
+ languages.forEach((lang) => {
44
+ const langYml = `${root}/locales/${lang}.yml`
45
+ if (fs.existsSync(langYml)) {
46
+ const varName = lang.replace('-', '') + i
47
+ imports.push(`import ${varName} from "${langYml}"`)
48
+ imports.push(`Object.assign(messages['${lang}'], ${varName})`)
49
+ }
50
+ })
51
+ })
17
52
 
18
- function generateUserStyles() {
19
- const imports: string[] = []
53
+ imports.push('export default messages')
54
+ return imports.join('\n')
55
+ }
20
56
 
21
- for (const root of roots) {
22
- const styles = [
23
- join(root, 'styles', 'vars.scss'),
24
- join(root, 'styles', 'index.css'),
25
- join(root, 'styles', 'index.scss'),
26
- ]
57
+ export function createValaxyPlugin(options: ResolvedValaxyOptions, serverOptions: ValaxyServerOptions = {}): Plugin {
58
+ const valaxyPrefix = '/@valaxy'
27
59
 
28
- for (const style of styles) {
29
- if (fs.existsSync(style)) {
30
- imports.push(`import "${toAtFS(style)}"`)
31
- continue
32
- }
33
- }
34
- }
60
+ let valaxyConfig = options.config
35
61
 
36
- return imports.join('\n')
37
- }
62
+ const roots = [options.clientRoot, options.themeRoot, options.userRoot]
38
63
 
39
64
  return {
40
65
  name: 'Valaxy',
@@ -60,7 +85,10 @@ export function createValaxyPlugin(options: ResolvedValaxyOptions, serverOptions
60
85
 
61
86
  // generate styles
62
87
  if (id === '/@valaxyjs/styles')
63
- return generateUserStyles()
88
+ return generateStyles(roots)
89
+
90
+ if (id === '/@valaxyjs/locales')
91
+ return generateLocales(roots)
64
92
 
65
93
  if (id.startsWith(valaxyPrefix))
66
94
  return ''
@@ -69,7 +97,8 @@ export function createValaxyPlugin(options: ResolvedValaxyOptions, serverOptions
69
97
  async handleHotUpdate(ctx) {
70
98
  // handle valaxy.config.ts hmr
71
99
  const { file, server } = ctx
72
- if (file !== options.configFile) return
100
+ if (file !== options.configFile)
101
+ return
73
102
 
74
103
  const { config } = await resolveConfig()
75
104
 
@@ -47,7 +47,7 @@ export function createMarkdownPlugin(options: ResolvedValaxyOptions): Plugin[] {
47
47
  handleHotUpdate(ctx) {
48
48
  const { file, server } = ctx
49
49
  // send headers
50
- if (file.endsWith('.md')) {
50
+ if (file.endsWith('.md') && _md && _md.__data) {
51
51
  server.ws.send({
52
52
  type: 'custom',
53
53
  event: 'valaxy:pageHeaders',
@@ -1,4 +1,3 @@
1
-
2
1
  import fs from 'fs'
3
2
  import type { PluginOption } from 'vite'
4
3
 
@@ -17,7 +16,6 @@ import Inspect from 'vite-plugin-inspect'
17
16
 
18
17
  import chalk from 'chalk'
19
18
  import type { ResolvedValaxyOptions, ValaxyServerOptions } from '../options'
20
- import type { Mode } from '../vite'
21
19
  import { setupMarkdownPlugins } from '../markdown'
22
20
  import { createMarkdownPlugin, excerpt_separator } from './markdown'
23
21
  import { createUnocssPlugin } from './unocss'
@@ -28,12 +26,11 @@ export interface ValaxyPluginOptions {
28
26
  components?: Parameters<typeof Components>[0]
29
27
  }
30
28
 
31
- export function ViteValaxyPlugins(
29
+ export async function ViteValaxyPlugins(
32
30
  options: ResolvedValaxyOptions,
33
31
  serverOptions: ValaxyServerOptions = {},
34
32
  pluginOptions: ValaxyPluginOptions = {},
35
- mode: Mode = 'dev',
36
- ): (PluginOption | PluginOption[])[] | undefined {
33
+ ): Promise<(PluginOption | PluginOption[])[] | undefined> {
37
34
  const { clientRoot, themeRoot, userRoot } = options
38
35
 
39
36
  const MarkdownPlugin = createMarkdownPlugin(options)
@@ -46,13 +43,49 @@ export function ViteValaxyPlugins(
46
43
 
47
44
  const roots = [clientRoot, themeRoot, userRoot]
48
45
 
46
+ const { default: ThemePlugin } = await import(`valaxy-theme-${options.theme}`)
47
+
48
+ const customElements = new Set([
49
+ // katex
50
+ 'annotation',
51
+ 'math',
52
+ 'menclose',
53
+ 'mfrac',
54
+ 'mglyph',
55
+ 'mi',
56
+ 'mlabeledtr',
57
+ 'mn',
58
+ 'mo',
59
+ 'mover',
60
+ 'mpadded',
61
+ 'mphantom',
62
+ 'mroot',
63
+ 'mrow',
64
+ 'mspace',
65
+ 'msqrt',
66
+ 'mstyle',
67
+ 'msub',
68
+ 'msubsup',
69
+ 'msup',
70
+ 'mtable',
71
+ 'mtd',
72
+ 'mtext',
73
+ 'mtr',
74
+ 'munder',
75
+ 'munderover',
76
+ 'semantics',
77
+
78
+ // meting
79
+ 'meting-js',
80
+ ])
81
+
49
82
  return [
50
83
  Vue({
51
84
  include: [/\.vue$/, /\.md$/],
52
85
  template: {
53
86
  compilerOptions: {
54
87
  isCustomElement: (tag) => {
55
- return ['meting-js'].includes(tag)
88
+ return customElements.has(tag)
56
89
  },
57
90
  },
58
91
  },
@@ -62,6 +95,8 @@ export function ViteValaxyPlugins(
62
95
  MarkdownPlugin,
63
96
  createConfigPlugin(options),
64
97
 
98
+ ThemePlugin(options.config.themeConfig),
99
+
65
100
  // https://github.com/hannoeru/vite-plugin-pages
66
101
  Pages({
67
102
  extensions: ['vue', 'md'],
@@ -71,7 +106,8 @@ export function ViteValaxyPlugins(
71
106
  */
72
107
  extendRoute(route) {
73
108
  let path = route.component
74
- if (!route.meta) route.meta = {}
109
+ if (!route.meta)
110
+ route.meta = {}
75
111
 
76
112
  if (route.path === '/')
77
113
  route.meta.layout = 'home'
@@ -178,6 +214,6 @@ export function ViteValaxyPlugins(
178
214
 
179
215
  // https://github.com/antfu/vite-plugin-inspect
180
216
  // Visit http://localhost:3333/__inspect/ to see the inspector
181
- mode === 'dev' && Inspect(),
217
+ options.mode === 'dev' && Inspect(),
182
218
  ]
183
219
  }
@@ -54,7 +54,7 @@ export const createUnocssConfig = (options: ResolvedValaxyOptions) => {
54
54
  ['yun-card', 'transition yun-transition shadow hover:shadow-lg'],
55
55
  ['btn', 'px-4 py-1 rounded inline-block bg-sky-600 text-white cursor-pointer hover:bg-sky-700 disabled:cursor-default disabled:bg-gray-600 disabled:opacity-50'],
56
56
  ['icon-btn', 'inline-block cursor-pointer select-none opacity-75 transition duration-200 ease-in-out hover:opacity-100 hover:text-sky-600'],
57
- ['val-card', 'transition shadow hover:shadow-lg'],
57
+ ['va-card', 'transition shadow hover:shadow-lg'],
58
58
  ],
59
59
  presets: [
60
60
  presetUno(),
@@ -66,7 +66,12 @@ export const createUnocssConfig = (options: ResolvedValaxyOptions) => {
66
66
  presetTypography(),
67
67
  presetWebFonts({
68
68
  fonts: {
69
- serif: 'Noto Serif SC',
69
+ serif: [
70
+ {
71
+ name: 'Noto Serif SC',
72
+ weights: [900],
73
+ },
74
+ ],
70
75
  // sans: 'DM Sans',
71
76
  // mono: 'DM Mono',
72
77
  },
@@ -75,19 +80,19 @@ export const createUnocssConfig = (options: ResolvedValaxyOptions) => {
75
80
  rules: [
76
81
  // more see '~/styles/global/helper.scss'
77
82
  ['yun-transition', {
78
- 'transition-duration': 'var(--yun-transition-duration)',
83
+ 'transition-duration': 'var(--va-transition-duration)',
79
84
  }],
80
85
  ['yun-text-light', {
81
- color: 'var(--yun-c-text-light)',
86
+ color: 'var(--va-c-text-light)',
82
87
  }],
83
88
  ['font-serif', {
84
- 'font-family': 'var(--yun-font-serif)',
89
+ 'font-family': 'var(--va-font-serif)',
85
90
  }],
86
91
  ['font-sans', {
87
- 'font-family': 'var(--yun-font-sans)',
92
+ 'font-family': 'var(--va-font-sans)',
88
93
  }],
89
94
  ['font-mono', {
90
- 'font-family': 'var(--yun-font-mono)',
95
+ 'font-family': 'var(--va-font-mono)',
91
96
  }],
92
97
  ],
93
98
  transformers: [
@@ -14,7 +14,7 @@ export async function createServer(
14
14
 
15
15
  const server = await createViteServer(mergeConfig(
16
16
  viteConfig,
17
- createViteConfig(options, serverOptions),
17
+ await createViteConfig(options, serverOptions),
18
18
  ))
19
19
 
20
20
  return server
@@ -18,6 +18,11 @@ declare module 'markdown-it-container' {
18
18
  export default def
19
19
  }
20
20
 
21
+ declare module 'markdown-it-task-lists' {
22
+ const def: any
23
+ export default def
24
+ }
25
+
21
26
  declare module 'diacritics' {
22
27
  export const remove: (str: string) => string
23
28
  }
@@ -1,4 +1,3 @@
1
-
2
1
  import * as readline from 'readline'
3
2
  import path from 'path'
4
3
  import os from 'os'
package/src/node/vite.ts CHANGED
@@ -1,4 +1,3 @@
1
- import generateSitemap from 'vite-ssg-sitemap'
2
1
  import type { InlineConfig } from 'vite'
3
2
  import { searchForWorkspaceRoot } from 'vite'
4
3
  import type { ResolvedValaxyOptions, ValaxyServerOptions } from './options'
@@ -7,7 +6,7 @@ import { ViteValaxyPlugins } from './plugins/preset'
7
6
 
8
7
  export type Mode = 'dev' | 'build'
9
8
 
10
- export function createViteConfig(options: ResolvedValaxyOptions, serverOptions: ValaxyServerOptions = {}, mode: Mode = 'dev'): InlineConfig {
9
+ export async function createViteConfig(options: ResolvedValaxyOptions, serverOptions: ValaxyServerOptions = {}): Promise<InlineConfig> {
11
10
  const viteConfig: InlineConfig = {
12
11
  // remove vue-i18n warnings
13
12
  // https://vue-i18n.intlify.dev/guide/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags
@@ -21,11 +20,14 @@ export function createViteConfig(options: ResolvedValaxyOptions, serverOptions:
21
20
  // __VUE_I18N_LEGACY_API__: 'false',
22
21
  // },
23
22
 
23
+ // always string
24
+ define: {
25
+ __DEV__: options.mode === 'dev' ? 'true' : 'false',
26
+ },
27
+
24
28
  root: options.clientRoot,
25
- // todo user base
26
- // base: '/',
27
29
 
28
- plugins: ViteValaxyPlugins(options, serverOptions, {}, mode),
30
+ plugins: await ViteValaxyPlugins(options, serverOptions, {}),
29
31
 
30
32
  server: {
31
33
  fs: {
@@ -37,16 +39,6 @@ export function createViteConfig(options: ResolvedValaxyOptions, serverOptions:
37
39
  ],
38
40
  },
39
41
  },
40
-
41
- }
42
-
43
- if (mode === 'build') {
44
- // https://github.com/antfu/vite-ssg
45
- viteConfig.ssgOptions = {
46
- script: 'async',
47
- formatting: 'minify',
48
- onFinished() { generateSitemap() },
49
- }
50
42
  }
51
43
 
52
44
  return viteConfig
package/tsup.config.ts CHANGED
@@ -5,6 +5,7 @@ export default defineConfig((options) => {
5
5
  entry: [
6
6
  'src/node/index.ts',
7
7
  'src/node/cli.ts',
8
+ 'src/index.ts',
8
9
  ],
9
10
  // https://tsup.egoist.sh/#code-splitting
10
11
  // 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.
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWYCH73X6js = require('./chunk-WYCH73X6.js');_chunkWYCH73X6js.d.call(void 0, );var _vite = require('vite');async function a(n,e={}){let t=_vite.mergeConfig.call(void 0, e,_chunkWYCH73X6js.j.call(void 0, n));await _vite.build.call(void 0, t)}exports.build = a;
@@ -1 +0,0 @@
1
- import{d as i,j as o}from"./chunk-ESCOXVP6.mjs";i();import{mergeConfig as r,build as f}from"vite";async function a(n,e={}){let t=r(e,o(n));await f(t)}export{a as build};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWYCH73X6js = require('./chunk-WYCH73X6.js');_chunkWYCH73X6js.d.call(void 0, );var _vite = require('vite');async function c(o,t={},i={}){return process.env.EDITOR=process.env.EDITOR||"code",await _vite.createServer.call(void 0, _vite.mergeConfig.call(void 0, t,_chunkWYCH73X6js.j.call(void 0, o,i)))}exports.a = c;
@@ -1 +0,0 @@
1
- import{d as e,j as r}from"./chunk-ESCOXVP6.mjs";e();import{createServer as n,mergeConfig as a}from"vite";async function c(o,t={},i={}){return process.env.EDITOR=process.env.EDITOR||"code",await n(a(t,r(o,i)))}export{c as a};