docs: add useValaxyConfig useSiteConfig useThemeConfig

This commit is contained in:
YunYouJun 2024-02-17 22:18:27 +08:00
parent fe94ed5449
commit eb4df405f6
9 changed files with 296 additions and 256 deletions

View File

@ -13,7 +13,7 @@
},
"dependencies": {
"valaxy": "workspace:*",
"valaxy-theme-custom": "./valaxy-theme-custom"
"valaxy-theme-custom": "file:./valaxy-theme-custom"
},
"devDependencies": {
"typescript": "^5.3.3"

View File

@ -1,7 +1,7 @@
{
"name": "valaxy-theme-custom",
"version": "0.0.0",
"packageManager": "pnpm@8.15.2",
"packageManager": "pnpm@8.15.3",
"author": {
"email": "me@yunyoujun.cn",
"name": "YunYouJun",

View File

@ -22,7 +22,7 @@
"devDependencies": {
"@iconify-json/simple-icons": "^1.1.91",
"nodemon": "^3.0.3",
"vite": "^5.1.2",
"vite": "^5.1.3",
"vitepress": "1.0.0-rc.42"
}
}

View File

@ -4,3 +4,5 @@ categories:
- API
end: false
---
More info see [API | Write Theme](/themes/write#api).

View File

@ -264,6 +264,52 @@ Markdown 样式是主题呈现文章样式的部分,需要由主题自定义
> 你还可以使用 Valaxy 内置的 API 以快速实现相关功能。
#### 获取用户的 Valaxy Config
你可以通过内置的 `useValaxyConfig` 获取用户的 Valaxy 配置。
::: tip
这部分配置与用户的 `valaxy.config.ts` 中的配置相对应,但它仅在客户端使用,因此并不包含 Node 端相关配置(如 `vite` 等)。
:::
```ts
import { useSiteConfig, useValaxyConfig } from 'valaxy'
import { useThemeConfig } from 'valaxy-theme-custom'
const config = useValaxyConfig()
// site.config.ts or config.value.siteConfig
const siteConfig = useSiteConfig()
// theme.config.ts or config.value.themeConfig
const themeConfig = useThemeConfig()
```
#### 提供 Typed useThemeConfig
你可以提供一个主题的 `useThemeConfig` 函数,以便自己/用户获得带有类型约束的配置。
```ts
// composables/config.ts
import { useValaxyConfig } from 'valaxy'
// custom your theme type
import type { YunTheme } from '../types'
/**
* getThemeConfig
*/
export function useThemeConfig<ThemeConfig = YunTheme.Config>() {
const config = useValaxyConfig<ThemeConfig>()
return computed(() => config!.value.themeConfig)
}
```
```ts
// use
import { useThemeConfig } from 'valaxy-theme-custom'
const themeConfig = useThemeConfig()
```
#### 获取文章列表
获取文章列表有两种方式。
@ -336,6 +382,7 @@ const fm = useFrontmatter()
// stores/app.ts
import { acceptHMRUpdate, defineStore } from 'pinia'
// custom your theme name
export const useYunAppStore = defineStore('yun-app', () => {
// global cache for yun

View File

@ -3,7 +3,7 @@
"type": "module",
"version": "0.18.1",
"private": true,
"packageManager": "pnpm@8.15.2",
"packageManager": "pnpm@8.15.3",
"description": "📄 Vite & Vue powered static blog generator.",
"author": {
"email": "me@yunyoujun.cn",
@ -61,12 +61,12 @@
"@antfu/eslint-config": "2.6.4",
"@iconify-json/logos": "^1.1.42",
"@iconify-json/vscode-icons": "^1.1.33",
"@microsoft/api-extractor": "^7.40.1",
"@microsoft/api-extractor": "^7.40.2",
"@types/debug": "^4.1.12",
"@types/markdown-it-attrs": "^4.1.3",
"@types/markdown-it-container": "^2.0.9",
"@types/markdown-it-emoji": "^2.0.4",
"@types/node": "^20.11.17",
"@types/node": "^20.11.19",
"@types/prompts": "^2.4.9",
"@types/resolve": "^1.20.6",
"@valaxyjs/devtools": "workspace:*",
@ -97,7 +97,7 @@
"valaxy-addon-waline": "workspace:*",
"valaxy-theme-press": "workspace:*",
"valaxy-theme-yun": "workspace:*",
"vitest": "^1.2.2",
"vitest": "^1.3.0",
"vue-tsc": "1.8.27",
"zx": "^7.2.3"
},

View File

@ -45,6 +45,6 @@
"typescript": "^5.3.3",
"unbuild": "^2.0.0",
"unplugin-vue-router": "^0.7.0",
"vite": "^5.1.2"
"vite": "^5.1.3"
}
}

View File

@ -75,7 +75,7 @@
"@unhead/vue": "^1.8.10",
"@valaxyjs/devtools": "workspace:*",
"@vitejs/plugin-vue": "^5.0.4",
"@vue/devtools-api": "^7.0.14",
"@vue/devtools-api": "^7.0.15",
"@vueuse/core": "^10.7.2",
"@vueuse/integrations": "^10.7.2",
"body-scroll-lock": "4.0.0-beta.0",
@ -114,8 +114,8 @@
"pathe": "^1.1.2",
"pinia": "^2.1.7",
"qrcode": "^1.5.3",
"sass": "^1.70.0",
"shiki": "^1.1.2",
"sass": "^1.71.0",
"shiki": "^1.1.3",
"star-markdown-css": "^0.4.2",
"unconfig": "^0.3.11",
"unocss": "^0.58.5",
@ -123,8 +123,8 @@
"unplugin-vue-markdown": "^0.26.0",
"unplugin-vue-router": "^0.7.0",
"vanilla-lazyload": "^17.8.8",
"vite": "^5.1.2",
"vite-plugin-vue-devtools": "^7.0.14",
"vite": "^5.1.3",
"vite-plugin-vue-devtools": "^7.0.15",
"vite-plugin-vue-layouts": "0.11.0",
"vite-ssg": "0.23.6",
"vite-ssg-sitemap": "0.6.1",

File diff suppressed because it is too large Load Diff