docs: add more config desc & remove transition to looks faster

This commit is contained in:
YunYouJun 2024-12-14 22:07:08 +08:00
parent b06b3006e5
commit 9e476f491d
9 changed files with 152 additions and 20 deletions

View File

@ -2,6 +2,7 @@ gallery:
tip: search tip: search
nav: nav:
config: Config
guide: Guide guide: Guide
theme: Themes theme: Themes
addon: Addons addon: Addons

View File

@ -2,6 +2,7 @@ gallery:
tip: 搜索 tip: 搜索
nav: nav:
config: 配置
guide: 指南 guide: 指南
theme: 主题 theme: 主题
addon: 插件 addon: 插件

View File

@ -5,6 +5,12 @@ categories:
- config - config
--- ---
::: tip
扩展配置是 Valaxy 提供的高阶配置,允许你自定义更多与底层/构建相关的配置。
:::
以下是所有的扩展配置项与相关类型。 以下是所有的扩展配置项与相关类型。
> [packages/valaxy/node/type.ts](https://github.com/YunYouJun/valaxy/blob/main/packages/valaxy/node/types.ts) > [packages/valaxy/node/type.ts](https://github.com/YunYouJun/valaxy/blob/main/packages/valaxy/node/types.ts)
@ -79,3 +85,92 @@ export default defineValaxyConfig({
} }
}) })
``` ```
### Vite
你可以参见 [Vite 文档](https://vite.dev/config/shared-options.html) 自定义 Vite 相关配置。
```ts [valaxy.config.ts]
import { defineValaxyConfig } from 'valaxy'
export default defineValaxyConfig({
vite: {
plugins: []
}
})
```
### Markdown
可自定义 Markdown 相关配置,如代码主题、区块内容、添加 `markdown-it` 插件、transformer 等。
效果参见: [Markdown](/guide/markdown)。
::: details valaxy/node/plugins/markdown/types.ts
<<< @/../packages/valaxy/node/plugins/markdown/types.ts
:::
```ts [valaxy.config.ts]
import { defineValaxyConfig } from 'valaxy'
export default defineValaxyConfig({
markdown: {
// default material-theme-palenight
// theme: 'material-theme-palenight',
theme: {
// light: 'material-theme-lighter',
light: 'github-light',
// dark: 'material-theme-darker',
dark: 'github-dark',
},
blocks: {
tip: {
icon: 'i-carbon-thumbs-up',
text: 'ヒント',
langs: {
'zh-CN': '提示',
},
},
warning: {
icon: 'i-carbon-warning-alt',
text: '注意',
},
danger: {
icon: 'i-carbon-warning',
text: '警告',
},
info: {
text: 'información',
},
},
codeTransformers: [
// We use `[!!code` in demo to prevent transformation, here we revert it back.
{
postprocess(code) {
return code.replace(/\[!!code/g, '[!code')
},
},
],
config(md) {
// md.use(xxx)
}
},
})
```
### DevTools
设置 `devtools: false` 以关闭 DevTools。
### 插件 addons
参见 [使用插件](/addons/use)。
### UnoCSS
参见 [UnoCSS](/guide/config/unocss-options)。

View File

@ -192,6 +192,23 @@ export default defineSiteConfig({
::: :::
### 作者信息
更多字段可参考上文类型或直接在编辑器提示中查看。
```ts [site.config.ts]
import { defineSiteConfig } from 'valaxy'
export default defineSiteConfig({
author: {
name: '你的名字',
// 你的头像
avatar: 'https://xxx',
intro: '个人简介'
}
})
```
### Default Frontmatter ### Default Frontmatter
::: zh-CN ::: zh-CN
@ -760,6 +777,16 @@ export default defineSiteConfig({
}) })
``` ```
### 更多配置
> 更多详细配置可参见 [types/config.ts](https://github.com/YunYouJun/valaxy/blob/main/packages/valaxy/types/config.ts)。
::: details packages/valaxy/types/config.ts SiteConfig
<<< @/../packages/valaxy/types/config.ts#snippet{ts:line-numbers}
:::
## 主题配置 {lang="zh-CN"} ## 主题配置 {lang="zh-CN"}
## Theme Config {lang="en"} ## Theme Config {lang="en"}
@ -771,3 +798,7 @@ export default defineSiteConfig({
::: en ::: en
Please refer to [Using Themes](/themes/use) and the theme you are using to configure it. Please refer to [Using Themes](/themes/use) and the theme you are using to configure it.
::: :::
## 扩展配置
更多高阶配置请参见 [扩展配置](/guide/config/extend)。

View File

@ -95,6 +95,10 @@ export default defineValaxyConfig<PressTheme.Config>({
}, },
], ],
}, },
{
text: 'nav.config',
link: '/guide/config/',
},
{ {
text: 'API', text: 'API',
link: 'https://api.valaxy.site/', link: 'https://api.valaxy.site/',

View File

@ -61,16 +61,14 @@ onContentUpdated(() => {
<slot name="main-header-after" /> <slot name="main-header-after" />
<slot name="main-content"> <slot name="main-content">
<Transition appear> <ValaxyMd class="mx-auto w-full max-w-4xl" :frontmatter="frontmatter">
<ValaxyMd class="mx-auto w-full max-w-4xl" :frontmatter="frontmatter"> <h1 v-if="hasSidebar && !isHome && frontmatter.title" :id="frontmatter.title" tabindex="-1">
<h1 v-if="hasSidebar && !isHome && frontmatter.title" :id="frontmatter.title" tabindex="-1"> {{ localeTitle }}
{{ localeTitle }} <a class="header-anchor" :href="`#${frontmatter.title}`" aria-hidden="true" />
<a class="header-anchor" :href="`#${frontmatter.title}`" aria-hidden="true" /> </h1>
</h1> <slot name="main-content-md" />
<slot name="main-content-md" /> <slot />
<slot /> </ValaxyMd>
</ValaxyMd>
</Transition>
<PressDocFooter v-if="!isHome" class="pb-8 max-w-4xl" w="full" m="auto" /> <PressDocFooter v-if="!isHome" class="pb-8 max-w-4xl" w="full" m="auto" />

View File

@ -38,7 +38,6 @@ export async function startValaxyDev({
const resolvedOptions = await resolveOptions({ userRoot: root }) const resolvedOptions = await resolveOptions({ userRoot: root })
const valaxyApp = createValaxyNode(resolvedOptions) const valaxyApp = createValaxyNode(resolvedOptions)
const viteConfig: InlineConfig = mergeConfig({ const viteConfig: InlineConfig = mergeConfig({
// initial vite config // initial vite config
...defaultViteConfig, ...defaultViteConfig,
@ -65,8 +64,9 @@ export async function startValaxyDev({
{ {
name: 'r', name: 'r',
fullName: 'restart', fullName: 'restart',
action() { async action() {
initServer(valaxyApp, viteConfig) await initServer(valaxyApp, viteConfig)
printInfo(resolvedOptions, port, remote)
}, },
}, },
{ {

View File

@ -67,7 +67,7 @@ export async function initServer(valaxyApp: ValaxyNode, viteConfig: InlineConfig
) )
try { try {
GLOBAL_STATE.server = await createServer(valaxyApp, viteConfigs, { const server = await createServer(valaxyApp, viteConfigs, {
async onConfigReload(newConfig, config, force = false) { async onConfigReload(newConfig, config, force = false) {
if (force) { if (force) {
vLogger.info(`${yellow('force')} reload the server`) vLogger.info(`${yellow('force')} reload the server`)
@ -93,8 +93,10 @@ export async function initServer(valaxyApp: ValaxyNode, viteConfig: InlineConfig
initServer(valaxyApp, viteConfig) initServer(valaxyApp, viteConfig)
}, },
}) })
await GLOBAL_STATE.server.listen() await server.listen()
serverSpinner.succeed(`${valaxyPrefix} ${colors.green('server ready.')}`) serverSpinner.succeed(`${valaxyPrefix} ${colors.green('server ready.')}`)
GLOBAL_STATE.server = server
return server
} }
catch (e) { catch (e) {
consola.error('failed to start server. error:\n') consola.error('failed to start server. error:\n')

View File

@ -5,14 +5,14 @@ import type { ValaxyNode } from './types'
import process from 'node:process' import process from 'node:process'
import { colors } from 'consola/utils' import { colors } from 'consola/utils'
import { createServer as createViteServer, mergeConfig as mergeViteConfig } from 'vite' import { createServer as createViteServer, mergeConfig as mergeViteConfig } from 'vite'
import { serverSpinner } from './cli/utils/cli' // import { serverSpinner } from './cli/utils/cli'
import { valaxyPrefix } from './logger' import { valaxyPrefix } from './logger'
import { ViteValaxyPlugins } from './plugins/preset' import { ViteValaxyPlugins } from './plugins/preset'
/** /**
* with valaxyPrefix * with valaxyPrefix
*/ */
function getServerInfoText(msg: string) { export function getServerInfoText(msg: string) {
return `${valaxyPrefix} ${colors.gray(msg)}` return `${valaxyPrefix} ${colors.gray(msg)}`
} }
@ -26,7 +26,7 @@ export async function createServer(
const { options } = valaxyApp const { options } = valaxyApp
serverSpinner.text = getServerInfoText('init vite plugins ..') // serverSpinner.text = getServerInfoText('init vite plugins ..')
const plugins = await ViteValaxyPlugins(valaxyApp, serverOptions) const plugins = await ViteValaxyPlugins(valaxyApp, serverOptions)
// dynamic import to avoid bundle it in build // dynamic import to avoid bundle it in build
@ -42,14 +42,14 @@ export async function createServer(
) )
} }
serverSpinner.text = getServerInfoText('merge vite config ...') // serverSpinner.text = getServerInfoText('merge vite config ...')
const mergedViteConfig = mergeViteConfig( const mergedViteConfig = mergeViteConfig(
viteConfig, viteConfig,
{ {
plugins: vitePlugins, plugins: vitePlugins,
}, },
) )
serverSpinner.text = getServerInfoText('create vite server ...') // serverSpinner.text = getServerInfoText('create vite server ...')
const server = await createViteServer(mergedViteConfig) const server = await createViteServer(mergedViteConfig)
return server return server
} }