-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(addon-components): add ValaxyThemesResolver (#448)
- Loading branch information
Showing
5 changed files
with
176 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# valaxy-addon-components | ||
|
||
**valaxy-addon-components** 是一个为 Valaxy 提供通用 Vue 组件的插件 | ||
|
||
[](https://www.npmjs.com/package/valaxy-addon-waline) | ||
|
||
- [English](./README.md) | **简体中文** | ||
|
||
## 安装 | ||
|
||
```bash | ||
pnpm add valaxy-addon-components | ||
``` | ||
|
||
<details> | ||
<summary>通用组件</summary><br> | ||
|
||
可以通过以下方式启用插件的通用组件,关于通用组件的完整列表,请参见 [通用组件](#通用组件) | ||
|
||
```ts | ||
import { defineValaxyConfig } from 'valaxy' | ||
import { addonComponents } from 'valaxy-addon-components' | ||
|
||
export default defineValaxyConfig({ | ||
addons: [ | ||
addonComponents(), | ||
], | ||
}) | ||
``` | ||
|
||
<br></details> | ||
|
||
<details> | ||
<summary>主题组件</summary><br> | ||
|
||
还可以通过插件 `ValaxyThemesResolver` 功能扩展 `unplugin-vue-components`,实现引入第三方主题。以下以 [Yun](https://github.com/YunYouJun/valaxy/tree/main/packages/valaxy-theme-yun) 主题为例: | ||
|
||
```ts | ||
import { defineValaxyConfig } from 'valaxy' | ||
import { ValaxyThemesResolver } from 'valaxy-addon-components' | ||
|
||
export default defineValaxyConfig({ | ||
components: { | ||
resolvers: [ValaxyThemesResolver({ themes: ['yun'] })], | ||
}, | ||
}) | ||
``` | ||
|
||
| 属性名 | 类型 | 默认值 | 说明 | | ||
| ---- | ---- | ---- | ---- | | ||
| themes | `string[]` | --- | 需要导入 components 的第三方主题 | | ||
|
||
<br></details> | ||
|
||
## 使用 | ||
|
||
大多数用户可能希望将组件挂载到主题的页脚。你可以在 `components` 文件夹下新建一个文件,例如 `MyFooter.vue`,并按如下方式使用: | ||
|
||
```vue | ||
<template> | ||
<YunFooter> | ||
<VCLiveTime start-time="2022-01-01"> | ||
<template #live-time-before> | ||
<span>本站已运行</span> | ||
</template> | ||
<template #live-time-after> | ||
<span>后缀</span> | ||
</template> | ||
</VCLiveTime> | ||
</YunFooter> | ||
</template> | ||
``` | ||
|
||
## 通用组件 | ||
|
||
### 命名空间以 VC 开头 | ||
|
||
#### VCLiveTime | ||
|
||
用于显示站点的生存时间 | ||
|
||
| 属性名 | 类型 | 默认值 | 说明 | | ||
| ---- | ---- | ---- | ---- | | ||
| startTime | `string` | --- | 设置站点开始计时的时间 | | ||
|
||
### 第三方组件 | ||
|
||
对第三方服务进行封装,优先使用通用命名规则。 | ||
|
||
#### Codepen | ||
|
||
- `CodePen`: [Codepen](https://codepen.io/) | ||
- Example: <https://yun.valaxy.site/examples/addons/components> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { ComponentResolver } from 'unplugin-vue-components' | ||
|
||
export interface ValaxyThemesResolverOptions { | ||
themes: string[] | ||
} | ||
|
||
export function ValaxyThemesResolver(options: ValaxyThemesResolverOptions): ComponentResolver { | ||
const { themes } = options | ||
return { | ||
type: 'component', | ||
resolve: (name: string) => { | ||
for (const theme of themes) { | ||
if (name.toLowerCase().startsWith(theme.toLowerCase())) { | ||
const formattedName = name.charAt(0).toUpperCase() + name.slice(1) | ||
return { | ||
name: formattedName, | ||
path: `valaxy-theme-${theme}/components/${name.toLowerCase()}`, | ||
from: `valaxy-theme-${theme}`, | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './node' | ||
export * from './core/resolvers' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97d0814
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://yun.valaxy.site as production
🚀 Deployed on https://66e2af0cb595372e3a725bfa--valaxy.netlify.app