valaxy 0.27.0 → 0.28.0-beta.1
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.
- package/client/components/AppLink.vue +4 -0
- package/client/components/ClientOnly.ts +12 -0
- package/client/components/ValaxyDynamicComponent.vue +22 -14
- package/client/composables/common.ts +6 -5
- package/client/composables/features/copy-markdown.ts +85 -0
- package/client/composables/features/index.ts +1 -0
- package/client/config.ts +4 -2
- package/client/entry-ssr.ts +25 -0
- package/client/locales/en.yml +8 -0
- package/client/locales/zh-CN.yml +8 -0
- package/client/main.ts +81 -22
- package/client/modules/components.ts +2 -2
- package/client/modules/floating-vue.ts +2 -3
- package/client/modules/valaxy.ts +2 -3
- package/client/setup/main.ts +2 -3
- package/client/setups.ts +24 -3
- package/client/styles/css-vars.scss +7 -6
- package/client/types/index.ts +2 -2
- package/dist/node/cli/index.mjs +14 -9
- package/dist/node/index.d.mts +152 -8
- package/dist/node/index.mjs +14 -9
- package/dist/shared/{valaxy.DpV6HHc6.mjs → valaxy.CKsfoRMA.mjs} +3250 -1892
- package/dist/shared/{valaxy._i636HSR.d.mts → valaxy.Dgja0_Y0.d.mts} +77 -1
- package/dist/types/index.d.mts +2 -2
- package/package.json +24 -24
- package/shared/node/i18n.ts +15 -1
- package/types/config.ts +74 -0
- package/types/frontmatter/page.ts +6 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineComponent, onMounted, ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
export default defineComponent({
|
|
4
|
+
name: 'ClientOnly',
|
|
5
|
+
setup(_, { slots }) {
|
|
6
|
+
const show = ref(false)
|
|
7
|
+
onMounted(() => {
|
|
8
|
+
show.value = true
|
|
9
|
+
})
|
|
10
|
+
return () => show.value ? slots.default?.() : null
|
|
11
|
+
},
|
|
12
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { Component } from 'vue'
|
|
3
|
-
import { compile,
|
|
3
|
+
import { compile, computed, defineComponent } from 'vue'
|
|
4
4
|
|
|
5
5
|
const props = withDefaults(
|
|
6
6
|
defineProps<{
|
|
@@ -12,22 +12,30 @@ const props = withDefaults(
|
|
|
12
12
|
},
|
|
13
13
|
)
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
// Separate compile from component creation — compile() is expensive and
|
|
16
|
+
// should only re-run when the template string itself changes.
|
|
17
|
+
const compiledRender = computed(() => {
|
|
18
|
+
if (!props.templateStr)
|
|
19
|
+
return null
|
|
20
|
+
return compile(props.templateStr)
|
|
21
|
+
})
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
// defineComponent creates a proper component instance so that compile()'s
|
|
24
|
+
// render function can access data properties through the instance context.
|
|
25
|
+
// Avoids defineAsyncComponent which causes "missing template" warnings in SSG.
|
|
26
|
+
const dynamicComponent = computed<Component | null>(() => {
|
|
27
|
+
const render = compiledRender.value
|
|
28
|
+
if (!render)
|
|
29
|
+
return null
|
|
30
|
+
return defineComponent({
|
|
31
|
+
data: () => ({ ...props.data }),
|
|
20
32
|
render,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
dynamicComponent.value = defineAsyncComponent(() => Promise.resolve(componentDefinition))
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
watch(() => [props.templateStr, props.data], () => {
|
|
27
|
-
createComponent()
|
|
28
|
-
}, { immediate: true })
|
|
33
|
+
})
|
|
34
|
+
})
|
|
29
35
|
</script>
|
|
30
36
|
|
|
31
37
|
<template>
|
|
32
|
-
<
|
|
38
|
+
<div v-if="dynamicComponent">
|
|
39
|
+
<component :is="dynamicComponent" />
|
|
40
|
+
</div>
|
|
33
41
|
</template>
|
|
@@ -2,7 +2,7 @@ import type { PostFrontMatter } from '../../types'
|
|
|
2
2
|
import type { ValaxyData } from '../app/data'
|
|
3
3
|
|
|
4
4
|
import { isClient } from '@vueuse/core'
|
|
5
|
-
import { computed, inject } from 'vue'
|
|
5
|
+
import { computed, hasInjectionContext, inject } from 'vue'
|
|
6
6
|
import { useRoute } from 'vue-router'
|
|
7
7
|
import { dataSymbol, useSiteConfig } from '../config'
|
|
8
8
|
|
|
@@ -73,10 +73,11 @@ export function useEncryptedPhotos() {
|
|
|
73
73
|
* inject pageData
|
|
74
74
|
*/
|
|
75
75
|
export function useData<FM = Record<string, any>>(): ValaxyData<FM> {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
if (!hasInjectionContext())
|
|
77
|
+
throw new Error('[Valaxy] useData() must be called inside setup() or a component lifecycle')
|
|
78
|
+
const data = inject<ValaxyData<FM>>(dataSymbol)
|
|
79
|
+
if (!data)
|
|
80
|
+
throw new Error('[Valaxy] data not properly injected in app')
|
|
80
81
|
return data
|
|
81
82
|
}
|
|
82
83
|
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { isClient, useClipboard } from '@vueuse/core'
|
|
2
|
+
import { computed, ref, watchEffect } from 'vue'
|
|
3
|
+
import { useRoute } from 'vue-router'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Composable for copying raw Markdown content of the current post.
|
|
7
|
+
* Requires `siteConfig.llms.files: true` to have .md files available at build output.
|
|
8
|
+
*
|
|
9
|
+
* The `available` ref is initially `false` and becomes `true` after a HEAD request
|
|
10
|
+
* confirms the `.md` file exists. This allows themes to conditionally render
|
|
11
|
+
* the copy button only when the llms feature is enabled.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```vue
|
|
15
|
+
* <script setup>
|
|
16
|
+
* import { useCopyMarkdown } from 'valaxy'
|
|
17
|
+
* const { copy, copied, loading, available, error } = useCopyMarkdown()
|
|
18
|
+
* </script>
|
|
19
|
+
* <template>
|
|
20
|
+
* <button v-if="available" @click="copy" :disabled="loading">
|
|
21
|
+
* {{ copied ? 'Copied!' : 'Copy Markdown' }}
|
|
22
|
+
* </button>
|
|
23
|
+
* <span v-if="error" class="text-red">{{ error }}</span>
|
|
24
|
+
* </template>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function useCopyMarkdown() {
|
|
28
|
+
const route = useRoute()
|
|
29
|
+
const copied = ref(false)
|
|
30
|
+
const loading = ref(false)
|
|
31
|
+
const available = ref(false)
|
|
32
|
+
const error = ref<string | null>(null)
|
|
33
|
+
const { copy: copyToClipboard } = useClipboard({ legacy: true })
|
|
34
|
+
|
|
35
|
+
const mdUrl = computed(() => {
|
|
36
|
+
const p = route.path !== '/' && route.path.endsWith('/')
|
|
37
|
+
? route.path.slice(0, -1)
|
|
38
|
+
: route.path
|
|
39
|
+
return `${p}.md`
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// Probe the .md file to detect availability (siteConfig.llms.files enabled at build time)
|
|
43
|
+
if (isClient) {
|
|
44
|
+
watchEffect(() => {
|
|
45
|
+
available.value = false
|
|
46
|
+
error.value = null
|
|
47
|
+
fetch(mdUrl.value, { method: 'HEAD' })
|
|
48
|
+
.then((res) => { available.value = res.ok })
|
|
49
|
+
.catch(() => { available.value = false })
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function copy() {
|
|
54
|
+
if (loading.value)
|
|
55
|
+
return
|
|
56
|
+
|
|
57
|
+
error.value = null
|
|
58
|
+
loading.value = true
|
|
59
|
+
try {
|
|
60
|
+
const res = await fetch(mdUrl.value)
|
|
61
|
+
if (!res.ok)
|
|
62
|
+
throw new Error(`Failed to fetch ${mdUrl.value}: ${res.status}`)
|
|
63
|
+
|
|
64
|
+
const text = await res.text()
|
|
65
|
+
await copyToClipboard(text)
|
|
66
|
+
copied.value = true
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
copied.value = false
|
|
69
|
+
}, 2000)
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
const msg = err instanceof Error ? err.message : 'Unknown error'
|
|
73
|
+
error.value = msg
|
|
74
|
+
console.error('[valaxy] Failed to copy markdown:', err)
|
|
75
|
+
setTimeout(() => {
|
|
76
|
+
error.value = null
|
|
77
|
+
}, 3000)
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
loading.value = false
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return { copy, copied, loading, mdUrl, available, error }
|
|
85
|
+
}
|
package/client/config.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { ComputedRef, InjectionKey } from 'vue'
|
|
|
6
6
|
// https://github.com/microsoft/TypeScript/issues/42873
|
|
7
7
|
import type { DefaultTheme, ValaxyConfig } from '../types'
|
|
8
8
|
import type { ValaxyData } from './app/data'
|
|
9
|
-
import { computed, inject, readonly, shallowRef } from 'vue'
|
|
9
|
+
import { computed, hasInjectionContext, inject, readonly, shallowRef } from 'vue'
|
|
10
10
|
|
|
11
11
|
// @ts-expect-error virtual module @valaxyjs/config
|
|
12
12
|
import valaxyConfig from '/@valaxyjs/config'
|
|
@@ -62,10 +62,12 @@ export function initContext() {
|
|
|
62
62
|
* @public
|
|
63
63
|
*/
|
|
64
64
|
export function useValaxyConfig<ThemeConfig = DefaultTheme.Config>() {
|
|
65
|
+
if (!hasInjectionContext())
|
|
66
|
+
throw new Error('[Valaxy] useValaxyConfig() must be called inside setup() or a component lifecycle')
|
|
65
67
|
const config = inject<ComputedRef<ValaxyConfig<ThemeConfig>>>(valaxyConfigSymbol)
|
|
66
68
|
if (!config)
|
|
67
69
|
throw new Error('[Valaxy] site config not properly injected in app')
|
|
68
|
-
return config
|
|
70
|
+
return config
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
/**
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createHead } from '@unhead/vue/server'
|
|
2
|
+
import { renderToString } from 'vue/server-renderer'
|
|
3
|
+
import { createValaxyApp, routesWithLayout } from './main'
|
|
4
|
+
|
|
5
|
+
export async function render(routePath: string) {
|
|
6
|
+
const ctx = createValaxyApp({ routePath, createHead })
|
|
7
|
+
const { app, router, head } = ctx
|
|
8
|
+
|
|
9
|
+
await router.push(routePath)
|
|
10
|
+
await router.isReady()
|
|
11
|
+
|
|
12
|
+
const ssrCtx: Record<string, any> = {}
|
|
13
|
+
const html = await renderToString(app, ssrCtx)
|
|
14
|
+
await ctx.triggerOnSSRAppRendered()
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
html,
|
|
18
|
+
head,
|
|
19
|
+
modules: ssrCtx.modules as Set<string> | undefined,
|
|
20
|
+
teleports: ssrCtx.teleports as Record<string, string> | undefined,
|
|
21
|
+
initialState: ctx.initialState,
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { routesWithLayout as routes }
|
package/client/locales/en.yml
CHANGED
|
@@ -50,6 +50,14 @@ post:
|
|
|
50
50
|
related_posts: Related posts
|
|
51
51
|
view_link: View link
|
|
52
52
|
read_more: READ MORE
|
|
53
|
+
copy_markdown: Copy Markdown
|
|
54
|
+
copy_markdown_link: Copy Markdown Link
|
|
55
|
+
copy_page: Copy page
|
|
56
|
+
copied_markdown: Copied!
|
|
57
|
+
view_as_markdown: View as Markdown
|
|
58
|
+
open_in_github: Open in GitHub
|
|
59
|
+
open_in_chatgpt: Open in ChatGPT
|
|
60
|
+
open_in_claude: Open in Claude
|
|
53
61
|
cover: Cover
|
|
54
62
|
time_warning: This article was last updated {ago}. The information described in this article may have changed.
|
|
55
63
|
copyright:
|
package/client/locales/zh-CN.yml
CHANGED
|
@@ -50,6 +50,14 @@ post:
|
|
|
50
50
|
related_posts: 相关文章
|
|
51
51
|
view_link: 查看链接
|
|
52
52
|
read_more: 阅读更多
|
|
53
|
+
copy_markdown: 复制 Markdown
|
|
54
|
+
copy_markdown_link: 复制 Markdown 链接
|
|
55
|
+
copy_page: 复制页面
|
|
56
|
+
copied_markdown: 已复制!
|
|
57
|
+
view_as_markdown: 查看 Markdown
|
|
58
|
+
open_in_github: 在 GitHub 中打开
|
|
59
|
+
open_in_chatgpt: 在 ChatGPT 中打开
|
|
60
|
+
open_in_claude: 在 Claude 中打开
|
|
53
61
|
cover: 封面
|
|
54
62
|
time_warning: '本文最后更新于 {ago},文中所描述的信息可能已发生改变。'
|
|
55
63
|
copyright:
|
package/client/main.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import type { ValaxySSGContext } from './setups'
|
|
2
|
+
|
|
1
3
|
import { dataSymbol, initValaxyConfig, valaxyConfigSymbol } from 'valaxy'
|
|
2
4
|
import { setupLayouts } from 'virtual:generated-layouts'
|
|
3
|
-
import {
|
|
5
|
+
import { createSSRApp, createApp as vueCreateApp } from 'vue'
|
|
6
|
+
import { createMemoryHistory, createRouter, createWebHistory } from 'vue-router'
|
|
4
7
|
import { routes as autoRoutes } from 'vue-router/auto-routes'
|
|
5
8
|
|
|
6
9
|
// import App from '/@valaxyjs/App.vue'
|
|
7
10
|
import App from './App.vue'
|
|
8
|
-
|
|
9
11
|
import { initData } from './app/data'
|
|
12
|
+
import ClientOnly from './components/ClientOnly'
|
|
10
13
|
|
|
11
14
|
import setupMain from './setup/main'
|
|
12
15
|
import { setupValaxyDevTools } from './utils/dev'
|
|
@@ -43,7 +46,7 @@ function filterDraft(routes: any[]) {
|
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
// not filter hide for ssg
|
|
46
|
-
const routesWithLayout = setupLayouts(import.meta.env.DEV
|
|
49
|
+
export const routesWithLayout = setupLayouts(import.meta.env.DEV
|
|
47
50
|
? routes
|
|
48
51
|
: filterDraft(routes),
|
|
49
52
|
)
|
|
@@ -51,31 +54,87 @@ const routesWithLayout = setupLayouts(import.meta.env.DEV
|
|
|
51
54
|
if (import.meta.env.DEV)
|
|
52
55
|
setupValaxyDevTools()
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
interface CreateValaxyAppOptions {
|
|
58
|
+
routePath?: string
|
|
59
|
+
createHead?: () => any
|
|
60
|
+
hydrate?: boolean
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function createValaxyApp(options: CreateValaxyAppOptions = {}): ValaxySSGContext {
|
|
64
|
+
const { routePath, createHead, hydrate } = options
|
|
65
|
+
const isSSR = import.meta.env.SSR
|
|
66
|
+
|
|
67
|
+
// Use createSSRApp for server-side rendering and for client-side hydration
|
|
68
|
+
// of SSG pre-rendered pages. vueCreateApp is only for pure SPA mode.
|
|
69
|
+
const app = (isSSR || hydrate) ? createSSRApp(App) : vueCreateApp(App)
|
|
70
|
+
|
|
71
|
+
const history = isSSR
|
|
72
|
+
? createMemoryHistory(import.meta.env.BASE_URL)
|
|
73
|
+
: createWebHistory(import.meta.env.BASE_URL)
|
|
74
|
+
|
|
75
|
+
const router = createRouter({
|
|
76
|
+
history,
|
|
58
77
|
routes: routesWithLayout,
|
|
59
|
-
base: import.meta.env.BASE_URL,
|
|
60
78
|
scrollBehavior(to, from) {
|
|
61
79
|
if (to.path !== from.path)
|
|
62
80
|
return { top: 0 }
|
|
63
81
|
},
|
|
64
|
-
}
|
|
65
|
-
(ctx) => {
|
|
66
|
-
// app-level provide
|
|
67
|
-
const { app, router } = ctx
|
|
82
|
+
})
|
|
68
83
|
|
|
69
|
-
|
|
70
|
-
app.provide(dataSymbol, data)
|
|
84
|
+
const head = createHead ? createHead() : undefined
|
|
71
85
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
86
|
+
app.use(router)
|
|
87
|
+
if (head)
|
|
88
|
+
app.use(head)
|
|
89
|
+
app.component('ClientOnly', ClientOnly)
|
|
76
90
|
|
|
77
|
-
|
|
91
|
+
// SSR render callback management
|
|
92
|
+
const appRenderCallbacks: (() => void)[] = []
|
|
78
93
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
94
|
+
const ctx: ValaxySSGContext = {
|
|
95
|
+
app,
|
|
96
|
+
router,
|
|
97
|
+
head,
|
|
98
|
+
routes: routesWithLayout,
|
|
99
|
+
isClient: !isSSR,
|
|
100
|
+
initialState: {},
|
|
101
|
+
onSSRAppRendered: isSSR ? (cb: () => void) => appRenderCallbacks.push(cb) : () => {},
|
|
102
|
+
triggerOnSSRAppRendered: () => Promise.all(appRenderCallbacks.map(cb => cb())),
|
|
103
|
+
routePath,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Restore serialised state on client
|
|
107
|
+
if (!isSSR && typeof window !== 'undefined' && (window as any).__INITIAL_STATE__) {
|
|
108
|
+
ctx.initialState = JSON.parse((window as any).__INITIAL_STATE__)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// app-level provide
|
|
112
|
+
const data = initData(router)
|
|
113
|
+
app.provide(dataSymbol, data)
|
|
114
|
+
app.provide(valaxyConfigSymbol, valaxyConfig)
|
|
115
|
+
|
|
116
|
+
setupMain(ctx, valaxyConfig)
|
|
117
|
+
|
|
118
|
+
return ctx
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Client-side auto-mount
|
|
122
|
+
if (!import.meta.env.SSR) {
|
|
123
|
+
;(async () => {
|
|
124
|
+
const { createHead } = await import('@unhead/vue/client')
|
|
125
|
+
// Detect SSG pre-rendered content for proper hydration
|
|
126
|
+
const appEl = document.getElementById('app')
|
|
127
|
+
const hydrate = !!(appEl && appEl.innerHTML.trim())
|
|
128
|
+
const { app, router } = createValaxyApp({ createHead, hydrate })
|
|
129
|
+
await router.isReady()
|
|
130
|
+
app.mount('#app', hydrate)
|
|
131
|
+
})()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Legacy compatibility export for vite-ssg.
|
|
136
|
+
* vite-ssg expects `createApp(routePath)` returning `{ app, router, ... }`.
|
|
137
|
+
* This wraps `createValaxyApp` to match that signature so
|
|
138
|
+
* `--ssg-engine vite-ssg` continues to work.
|
|
139
|
+
*/
|
|
140
|
+
export const createApp = (routePath?: string) => createValaxyApp({ routePath })
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ValaxySSGContext } from '../setups'
|
|
2
2
|
|
|
3
3
|
import AppLink from '../components/AppLink.vue'
|
|
4
4
|
import ValaxyTranslate from '../components/builtin/ValaxyTranslate.vue'
|
|
@@ -7,7 +7,7 @@ import ValaxyTranslate from '../components/builtin/ValaxyTranslate.vue'
|
|
|
7
7
|
* register global components
|
|
8
8
|
* @param ctx
|
|
9
9
|
*/
|
|
10
|
-
export function registerGlobalComponents(ctx:
|
|
10
|
+
export function registerGlobalComponents(ctx: ValaxySSGContext) {
|
|
11
11
|
ctx.app.component('AppLink', AppLink)
|
|
12
12
|
ctx.app.component('VT', ValaxyTranslate)
|
|
13
13
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { DefaultTheme, ValaxyConfig } from 'valaxy/types'
|
|
2
|
-
import type { ViteSSGContext } from 'vite-ssg'
|
|
3
|
-
|
|
4
2
|
import type { ComputedRef } from 'vue'
|
|
3
|
+
import type { ValaxySSGContext } from '../setups'
|
|
5
4
|
import FloatingVue from 'floating-vue'
|
|
6
5
|
import 'floating-vue/dist/style.css'
|
|
7
6
|
|
|
8
|
-
export async function install({ app }:
|
|
7
|
+
export async function install({ app }: ValaxySSGContext, config: ComputedRef<ValaxyConfig<DefaultTheme.Config>>) {
|
|
9
8
|
// @see https://floating-vue.starpad.dev/guide/config#default-values
|
|
10
9
|
const defaultFloatingVueConfig = {}
|
|
11
10
|
app.use(FloatingVue, Object.assign(defaultFloatingVueConfig, config.value.siteConfig.floatingVue || {}))
|
package/client/modules/valaxy.ts
CHANGED
|
@@ -8,11 +8,10 @@ import type { DefaultTheme, ValaxyConfig } from 'valaxy/types'
|
|
|
8
8
|
*/
|
|
9
9
|
// import messages from '@intlify/unplugin-vue-i18n/messages'
|
|
10
10
|
|
|
11
|
-
import type { ViteSSGContext } from 'vite-ssg'
|
|
12
|
-
|
|
13
11
|
import type { ComputedRef } from 'vue'
|
|
14
12
|
import type { Router } from 'vue-router'
|
|
15
13
|
import type { PageDataPayload } from '../../types'
|
|
14
|
+
import type { ValaxySSGContext } from '../setups'
|
|
16
15
|
import { ensureSuffix } from '@antfu/utils'
|
|
17
16
|
import { useStorage } from '@vueuse/core'
|
|
18
17
|
import { createI18n } from 'vue-i18n'
|
|
@@ -52,7 +51,7 @@ export const i18n = createI18n({
|
|
|
52
51
|
missingWarn: false,
|
|
53
52
|
})
|
|
54
53
|
|
|
55
|
-
export async function install({ app, router }:
|
|
54
|
+
export async function install({ app, router }: ValaxySSGContext, config: ComputedRef<ValaxyConfig<DefaultTheme.Config>>) {
|
|
56
55
|
const locale = useStorage('valaxy-locale', config?.value.siteConfig.lang || 'en')
|
|
57
56
|
i18n.global.locale.value = locale.value
|
|
58
57
|
|
package/client/setup/main.ts
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
// https://github.com/microsoft/TypeScript/issues/42873
|
|
5
5
|
import type { DefaultTheme, ValaxyConfig } from 'valaxy/types'
|
|
6
6
|
/* __imports__ */
|
|
7
|
-
import type { ViteSSGContext } from 'vite-ssg'
|
|
8
|
-
|
|
9
7
|
import type { ComputedRef } from 'vue'
|
|
8
|
+
import type { ValaxySSGContext } from '../setups'
|
|
10
9
|
|
|
11
10
|
import { consola } from 'consola'
|
|
12
11
|
import { registerGlobalComponents } from '../modules/components'
|
|
@@ -16,7 +15,7 @@ import { install as installPinia } from '../modules/pinia'
|
|
|
16
15
|
import { install as installUnhead } from '../modules/unhead'
|
|
17
16
|
import { install as installValaxy } from '../modules/valaxy'
|
|
18
17
|
|
|
19
|
-
export default function setupMain(ctx:
|
|
18
|
+
export default function setupMain(ctx: ValaxySSGContext, config: ComputedRef<ValaxyConfig<DefaultTheme.Config>>) {
|
|
20
19
|
// @ts-expect-error inject in runtime
|
|
21
20
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
22
21
|
const injection_arg = ctx
|
package/client/setups.ts
CHANGED
|
@@ -1,16 +1,37 @@
|
|
|
1
1
|
import type { Awaitable } from '@antfu/utils'
|
|
2
|
-
import type {
|
|
2
|
+
import type { App } from 'vue'
|
|
3
|
+
import type { Router, RouteRecordRaw } from 'vue-router'
|
|
3
4
|
import type { MermaidOptions } from './types'
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @en
|
|
8
|
+
* SSG context interface — property-compatible with ViteSSGContext so that
|
|
9
|
+
* downstream themes / addons only need to change their import path.
|
|
10
|
+
*
|
|
11
|
+
* @zh
|
|
12
|
+
* SSG 上下文接口 — 属性签名与 ViteSSGContext 完全兼容,下游主题/插件只需更改 import 路径。
|
|
13
|
+
*/
|
|
14
|
+
export interface ValaxySSGContext {
|
|
15
|
+
app: App
|
|
16
|
+
router: Router
|
|
17
|
+
routes: RouteRecordRaw[]
|
|
18
|
+
head: any
|
|
19
|
+
isClient: boolean
|
|
20
|
+
initialState: Record<string, any>
|
|
21
|
+
onSSRAppRendered: (cb: () => void) => void
|
|
22
|
+
triggerOnSSRAppRendered: () => Promise<unknown[]>
|
|
23
|
+
routePath?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
5
26
|
/**
|
|
6
27
|
* @see https://github.com/antfu-collective/vite-ssg
|
|
7
28
|
* @en
|
|
8
29
|
* The context object for the application setup function.
|
|
9
30
|
*
|
|
10
31
|
* @zh
|
|
11
|
-
* 应用 setup
|
|
32
|
+
* 应用 setup 函数的上下文对象。
|
|
12
33
|
*/
|
|
13
|
-
export type AppContext =
|
|
34
|
+
export type AppContext = ValaxySSGContext
|
|
14
35
|
|
|
15
36
|
export type AppSetup = (ctx: AppContext) => Awaitable<void>
|
|
16
37
|
|
|
@@ -5,11 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
$c-primary: #0078e7 !default;
|
|
7
7
|
|
|
8
|
-
@use "./palette" with (
|
|
9
|
-
|
|
10
|
-
"primary": $c-primary,
|
|
11
|
-
)
|
|
12
|
-
);
|
|
8
|
+
@use "./palette" with ($colors: ("primary": $c-primary,
|
|
9
|
+
));
|
|
13
10
|
@use './css-vars/borders.css' as *;
|
|
14
11
|
@use './css-vars/palette.css' as *;
|
|
15
12
|
@use './css-vars/function.css' as *;
|
|
@@ -75,6 +72,8 @@ html.dark {
|
|
|
75
72
|
--va-c-bg-soft: #f9f9f9;
|
|
76
73
|
--va-c-bg-alt: #f9f9f9;
|
|
77
74
|
--va-c-bg-mute: #f1f1f1;
|
|
75
|
+
|
|
76
|
+
--va-c-bg-elevated: #f9f9f9;
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
html.dark {
|
|
@@ -85,6 +84,8 @@ html.dark {
|
|
|
85
84
|
--va-c-bg-alt: #161618;
|
|
86
85
|
--va-c-bg-soft: #202127;
|
|
87
86
|
--va-c-bg-mute: #2f2f2f;
|
|
87
|
+
|
|
88
|
+
--va-c-bg-elevated: #202127;
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/* code */
|
|
@@ -144,4 +145,4 @@ html.dark {
|
|
|
144
145
|
|
|
145
146
|
:root {
|
|
146
147
|
--va-header-anchor-symbol: '#';
|
|
147
|
-
}
|
|
148
|
+
}
|
package/client/types/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type mermaid from 'mermaid'
|
|
2
|
-
import type {
|
|
2
|
+
import type { ValaxySSGContext } from '../setups'
|
|
3
3
|
|
|
4
|
-
export type UserModule = (ctx:
|
|
4
|
+
export type UserModule = (ctx: ValaxySSGContext) => void
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @see https://mermaid.js.org/config/schema-docs/config.html#mermaid-config-schema
|
package/dist/node/cli/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'node:process';
|
|
2
2
|
import 'yargs';
|
|
3
3
|
import 'yargs/helpers';
|
|
4
|
-
export { c as cli,
|
|
4
|
+
export { c as cli, I as registerDevCommand, W as run, Z as startValaxyDev } from '../../shared/valaxy.CKsfoRMA.mjs';
|
|
5
5
|
import 'node:os';
|
|
6
6
|
import 'node:path';
|
|
7
7
|
import 'consola';
|
|
@@ -29,13 +29,9 @@ import 'feed';
|
|
|
29
29
|
import 'markdown-it';
|
|
30
30
|
import 'table';
|
|
31
31
|
import 'hookable';
|
|
32
|
+
import 'node:child_process';
|
|
33
|
+
import 'node:v8';
|
|
32
34
|
import 'vite-ssg-sitemap';
|
|
33
|
-
import 'vite-ssg/node';
|
|
34
|
-
import '@intlify/unplugin-vue-i18n/vite';
|
|
35
|
-
import '@unhead/addons/vite';
|
|
36
|
-
import 'unplugin-vue-components/vite';
|
|
37
|
-
import 'vite-plugin-vue-layouts';
|
|
38
|
-
import 'vitepress-plugin-group-icons';
|
|
39
35
|
import 'markdown-it-async';
|
|
40
36
|
import '@shikijs/transformers';
|
|
41
37
|
import 'shiki';
|
|
@@ -46,21 +42,30 @@ import 'markdown-it-emoji';
|
|
|
46
42
|
import 'markdown-it-footnote';
|
|
47
43
|
import 'markdown-it-image-figures';
|
|
48
44
|
import 'markdown-it-task-lists';
|
|
45
|
+
import 'vitepress-plugin-group-icons';
|
|
49
46
|
import 'node:url';
|
|
50
47
|
import 'markdown-it-container';
|
|
51
48
|
import 'katex';
|
|
49
|
+
import 'katex/contrib/mhchem';
|
|
52
50
|
import 'unplugin-vue-markdown/vite';
|
|
53
51
|
import 'js-base64';
|
|
52
|
+
import '@intlify/unplugin-vue-i18n/vite';
|
|
53
|
+
import '@unhead/addons/vite';
|
|
54
|
+
import 'unplugin-vue-components/vite';
|
|
55
|
+
import 'vite-plugin-vue-layouts';
|
|
56
|
+
import 'p-map';
|
|
57
|
+
import 'node:buffer';
|
|
58
|
+
import 'minisearch';
|
|
59
|
+
import 'lru-cache';
|
|
54
60
|
import 'node:fs';
|
|
55
61
|
import 'jiti';
|
|
56
62
|
import 'unocss';
|
|
57
63
|
import 'pascalcase';
|
|
58
|
-
import 'lru-cache';
|
|
59
64
|
import 'html-to-text';
|
|
60
65
|
import 'vue-router/vite';
|
|
66
|
+
import '@unhead/vue/server';
|
|
61
67
|
import '@clack/prompts';
|
|
62
68
|
import 'node:net';
|
|
63
|
-
import 'node:child_process';
|
|
64
69
|
import 'node:readline';
|
|
65
70
|
import 'qrcode';
|
|
66
71
|
import 'ejs';
|