Redian新闻
>
一款程序员专属的静态站点,赞!

一款程序员专属的静态站点,赞!

公众号新闻

来源:blog.csdn.net/qq_36362721/article/details/127827721

Vitepress 是一款基于Vite 的静态站点生成工具。开发的初衷就是为了建设 Vue 的文档。Vitepress 的方便之处在于,可以使用流行的 Markdown 语法进行编写,也可以直接运行 Vue 的代码。也就是说,它能很方便地完成展示组件 Demo 的任务。
使用 Vitepress 作为文档建设工具还有另外一个好处。由于 Vitepress 是基于 Vite 的,所以它也很好的继承了 Bundless 特性,开发的代码能以“秒级”速度在文档中看到运行效果,完全可以充当调试工具来使用。所以通常情况下我开发组件时,就会直接选择在 Vitepress 上进行调试。这个开发方式大家也可以尝试一下。
效果展示:https://www.yhjava.com

知识点

  • 利用 Vitepress 搭建生成文档网站
  • 引用组件并展示到 Demo
  • 引入代码示例提高阅读体验

【task1】搭建Vitepress生成文档网站

安装开发依赖
pnpm i vitepress -D
配置vitepress的vite配置
默认 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
  }
});
创建文档首页
文件名:docs/index.md
## 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?
这里重启一下项目。至此vitePress测试成功。

【task2】引用组件并展示到 Demo

构建docs目录
docs
 |--- .vitepress
 |  |--- theme
 |  |     |--- index.ts
 |  |--- config.ts
 |--- components
 |      |--- button
 |      |      |--- index.md
 |      |--- index.md
 |      | ...
 |--- index.md
 |--- vite.config.ts
子菜单所对应的 markdwon 文件路径(默认页面 index.md)
配置菜单项
文件名: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】引入组件代码提高阅读

修改sidebar
文件名: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>
使用sizecolorpainround属性来定义 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就该这么学》,同时也非常适合专业的运维人员阅读,成为辅助您工作的高价值工具书!


微信扫码关注该文公众号作者

戳这里提交新闻线索和高质量文章给我们。
相关阅读
5097 血壮山河之武汉会战 浴血田家镇 5中国程序员拒写赌博程序被拔14颗牙,全身损伤达88%Costco卖金条上架就售空!网友分享薅羊毛技巧,赞叹太划算微信将推出“公务员专供版”?腾讯回应中国46岁程序员拒写赌博程序遭拔14颗牙;小红书被疑“偷”原画师作品喂自家大模型;全面停止服务,俄遇“微软危机”|Q资讯中国 程序员 赴越南,拒写 赌博程序 遭到数月虐待,被拔 14 颗牙,全身损伤达 88%效果太惊艳~孩子专属的防晒保湿2合1面霜、小绿泥洗发水来了!网传高盛中国办公室所有人被带走,北京、上海办事处最新回应;中国程序员拒写赌博程序被拔14颗牙;北京严禁使用AI生成处方丨雷峰早报腾讯否认微信将推公务员专供版;特斯拉回应上海工厂加薪;周杰伦演唱会2张连座票炒到15万;上海要求手机点餐餐厅配纸质菜单...程序员未写出赌博程序被拔掉 14 颗牙最彪悍校规:诺贝尔奖获得者,才能拥有一个专属停车位!更彪悍:已有110个专属停车位名额被发放!程序员「求生宝典」!AI大发展下的程序员求生指南,干货满满推荐几款程序员必备的画图工具,被惊艳到了![干货] “书山有路勤为径、学海无涯苦作舟”这样翻译,赞!第三章 旧文明的社会组织 (1)孩子也能挣$1000!全墨600个站点,空瓶换钱开始,有这些华人区!半山听雨夏日专属的「便携榨汁杯」来啦!上班、游玩、健身,鲜榨鲜喝,还不到百元!六善全球首个疗愈居所,古老的静修之旅在野猪笼落下那一刻想到的薅羊毛!亚马逊 First Reads 自选两本新书电子版免费送,会员专享!程序员未写出赌博程序被拔掉14颗牙;前华为“天才少年”稚晖君公布首款人形机器人;马斯克称X平台将移除拉黑功能 | AI一周资讯微信将推“公务员专供版”,消息发出2小时内可撤回?腾讯回应Gap / BR / Old Navy 50加元礼品卡7.9折!会员专享!全国 程序员 薪酬大曝光!狠狠酸住了,33% 程序员月薪达到...腾讯张军否认微信将推出“公务员专供版”:这玩笑开大了晚上23点,又一程序员被120抬上担架好声音拒不认错,赞助商被坑惨了可怕!真实版中国程序员因在东南亚拒写赌博程序,被囚禁、虐待拔14颗牙,身体损伤达88%小白入门的第一台咖啡机,在家就能享受专属的咖啡时光薅羊毛!购Amazon电子礼品卡,免费送5元抵用券!会员专享!【九零后老妈随笔】7/1/2023 清晨独享的静谧时光美到50岁完全不是问题!富婆专属的快乐!我要你也拥有!英诺达发布DFT静态验证工具,提高IC设计质量及可靠性2023地中海邮轮行 (二)威尼斯
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。