一款程序员专属的静态站点,赞!
来源:blog.csdn.net/qq_36362721/article/details/127827721
知识点
利用 Vitepress 搭建生成文档网站 引用组件并展示到 Demo 引入代码示例提高阅读体验
【task1】搭建Vitepress生成文档网站
pnpm i vitepress -D
默认 Vitepress 是无需配置 vitepress.config.ts
的,但是组件库中需要支持 JSX 语法与 UnoCSS,所以就需要添加配置文件。
docs/vite.config.ts
import { defineConfig } from "vite";
import vueJsx from "@vitejs/plugin-vue-jsx";
import Unocss from "../config/unocss";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
// 添加JSX插件
vueJsx(),
Unocss(),
],
// 这里变更一下端口
server: {
port: 3000
}
});
## hello Vitepress
const str:string = "hello vitepress"
{
"scripts": {
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:serve": "vitepress serve docs"
}
}
pnpm docs:dev
vitepress v1.0.0-alpha.28
➜ Local: http://localhost:3000/
➜ Network: use --host to expose
[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?
【task2】引用组件并展示到 Demo
docs
|--- .vitepress
| |--- theme
| | |--- index.ts
| |--- config.ts
|--- components
| |--- button
| | |--- index.md
| |--- index.md
| | ...
|--- index.md
|--- vite.config.ts
docs/.vitepress/config.ts
const sidebar = {
'/': [
{
text: 'Guide',
items: [
{ text: '快速开始', link: '/' },
{ text: '通用', link: '/components/button/' },
]
}
]
}
const config = {
themeConfig: {
sidebar,
}
}
export default config
docs/.vitepress/theme/index.ts
import Theme from 'vitepress/dist/client/theme-default/index.js'
import SmartyUI from '../../../src/entry'
export default {
...Theme, // 默认主题
enhanceApp({ app }) {
app.use(SmartyUI)
},
}
docs/components/button/index.md
# Button 按钮
<div style="margin-bottom:20px;">
<SButton color="blue">主要按钮</SButton>
<SButton color="green">绿色按钮</SButton>
<SButton color="gray">灰色按钮</SButton>
<SButton color="yellow">黄色按钮</SButton>
<SButton color="red">红色按钮</SButton>
</div>
pnpm docs:dev
vitepress v1.0.0-alpha.28
➜ Local: http://localhost:3000/
➜ Network: use --host to expose
【task3】引入组件代码提高阅读
docs/.vitepress/config.ts
const sidebar = {
'/': [
{
text: 'Guide',
items: [
{ text: '快速开始', link: '/' },
{ text: '通用', link: '/components/button/' },
]
},
{
text: 'Components',
items: [
{ text: '组件', link: '/components/' },
{ text: '按钮', link: '/components/button/' },
]
}
]
}
<div style="margin-bottom:20px;">
<SButton color="blue">主要按钮</SButton>
<SButton color="green">绿色按钮</SButton>
<SButton color="gray">灰色按钮</SButton>
<SButton color="yellow">黄色按钮</SButton>
<SButton color="red">红色按钮</SButton>
</div>
<div style="margin-bottom:20px;">
<SButton color="blue" icon="search">搜索按钮</SButton>
<SButton color="green" icon="edit">编辑按钮</SButton>
<SButton color="gray" icon="check">成功按钮</SButton>
<SButton color="yellow" icon="message">提示按钮</SButton>
<SButton color="red" icon="delete">删除按钮</SButton>
</div>
<div style="margin-bottom:20px;">
<SButton color="blue" icon="search"></SButton>
<SButton color="green" icon="edit"></SButton>
<SButton color="gray" icon="check"></SButton>
<SButton color="yellow" icon="message"></SButton>
<SButton color="red" icon="delete"></SButton>
</div>
size
、color
、pain
、round
属性来定义 Button 的样式。<template>
<div style="margin-bottom:20px;">
<SButton color="blue">主要按钮</SButton>
<SButton color="green">绿色按钮</SButton>
<SButton color="gray">灰色按钮</SButton>
<SButton color="yellow">黄色按钮</SButton>
<SButton color="red">红色按钮</SButton>
</div>
<div style="margin-bottom:20px;">
<SButton color="blue" icon="search">搜索按钮</SButton>
<SButton color="green" icon="edit">编辑按钮</SButton>
<SButton color="gray" icon="check">成功按钮</SButton>
<SButton color="yellow" icon="message">提示按钮</SButton>
<SButton color="red" icon="delete">删除按钮</SButton>
</div>
<div style="margin-bottom:20px;">
<SButton color="blue" icon="search"></SButton>
<SButton color="green" icon="edit"></SButton>
<SButton color="gray" icon="check"></SButton>
<SButton color="yellow" icon="message"></SButton>
<SButton color="red" icon="delete"></SButton>
</div>
</template>
<div class="flex flex-row">
<SButton icon="edit" plain></SButton>
<SButton icon="delete" plain></SButton>
<SButton icon="share" plain></SButton>
<SButton round plain icon="search">搜索</SButton>
</div>
icon
属性即可,icon
的列表可以参考 Element
的 icon
组件,也可以设置在文字右边的 icon
,只要使用 i
标签即可,可以使用自定义图标。<template>
<div class="flex flex-row">
<SButton icon="edit" ></SButton>
<SButton icon="delete" ></SButton>
<SButton icon="share" ></SButton>
<SButton icon="search">搜索</SButton>
</div>
</template>
pnpm docs:dev
开源地址
https://github.com/vuejs/vitepress
END
官方站点:www.linuxprobe.com
Linux命令大全:www.linuxcool.com
刘遄老师QQ:5604215
Linux技术交流群:2636170
(新群,火热加群中……)
想要学习Linux系统的读者可以点击"阅读原文"按钮来了解书籍《Linux就该这么学》,同时也非常适合专业的运维人员阅读,成为辅助您工作的高价值工具书!
微信扫码关注该文公众号作者
戳这里提交新闻线索和高质量文章给我们。
来源: qq
点击查看作者最近其他文章