vitepress的使用

创建项目并启动项目

// 1.创建项目,直接在空项目下安装vitepress(npm/yarn等都可以,这个可以看官网,官网给了好几种安装方式)
yarn add -D vitepress
// 2.初始化配置项目(npm/官网也给了多种包管理工具的安装方式)
npx vitepress init
// 初始化命令执行完会遇到以下几个问题
┌  Welcome to VitePress!
│
◇  Where should VitePress initialize the config?  // 将哪个目录作为根目录(默认./)./docs
│
◇  Site title: // 设置标题(有默认的,可以直接回车,后期可以改)
│  My Awesome Project
│
◇  Site description: // 设置网站描述(也是可以默认的,后期可以改)A VitePress Site
│
◆  Theme: //选择使用的主题模版
│  ● Default Theme (Out of the box, good-looking docs)  //默认的主题模版
│  ○ Default Theme + Customization //使用默认+自定义的,我选的这个
│  ○ Custom Theme //使用自定义主题
◇  Use TypeScript for config and theme files? //是否使用ts作为模版(我选的是no)
│  ● Yes / ○ No
◆  Add VitePress npm scripts to package.json? //是否将package.json作为配置文件(这里选择yes)
│  ● Yes / ○ No
└
// 整体为:./docs 回车 回车 第二个 no yes

这样就创建完毕了,目前项目的结构应该是如下所示:

├─ docs
│  ├─ .vitepress //当前目录所在的位置就是文档的根目录
│  │  └─ config.js //项目的配置文件,最重要
│  ├─ api-examples.md
│  ├─ markdown-examples.md
│  └─ index.md
└─ package.json

项目启动

yarn docs:dev

得到如下页面(这样项目就搭建完成了)
在这里插入图片描述

运行原理:项目启动后会允许根目录下的index.md,在项目里面所有的md文档均会被编译为html,这里项目的根目录被设置为了./docs,因此会先运行/docs/index.md以下所有介绍的根目录均代表./docs目录下

配置介绍

首页

---
# https://vitepress.dev/reference/default-theme-home-page
layout: home  //指定以home格式呈现(一共有三种模式呈现doc,page,home,默认以doc格式呈现)

//下面的这些都是页面的显示各位可以去参考页面
hero:
  name: "My Awesome Project"
  text: "A VitePress Site"
  tagline: My great project tagline
  image:
  	scr:/logo.svg  //默认找根目录下的public文件夹内的图片
  	alt:VitePress
  actions:
    - theme: brand
      text: Markdown Examples
      link: /markdown-examples
    - theme: alt
      text: API Examples
      link: /api-examples

features:
  - title: Feature A
    details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
  - title: Feature B
    details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
  - title: Feature C
    details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
---

文件路由

根目录下的config.mjs里面

import { defineConfig } from 'vitepress'

// https://vitepress.dev/reference/site-config
export default defineConfig({
  title: "萧寂博客园",
  description: "A VitePress Site",
  themeConfig: {
    // https://vitepress.dev/reference/default-theme-config
    nav: [  //右上角导航栏
      {
        text: '前端', items: [
          { text: '前端子页面', link: '/web/index' },
          {
            text: '',  //这个写东西了就代表有标题了
            items: [
              { text: '前端子页面', link: '/web/进阶基础' },
            ]
          }
        ]
      },
      { text: '标签页', link: '/markdown-examples' }
    ],

    sidebar: {
      // 下面这个当匹配到对应的路由时会动态加载侧边栏,例如下面我这个就是匹配到/web/index这个时才展示侧边栏
      // 下面这种方法可以保证页面切换左边侧边栏不会消失
      '/web/index': {
        title: 'web前端',
        items: [
          { text: '前端首页', link: '/web/index' },
          { text: '前端侧边栏', link: '/web/进阶基础' }
        ]
      },
      '/web/进阶基础': {
        title: '进阶基础',
        items: [
          { text: '前端首页', link: '/web/index' },
          { text: '前端侧边栏', link: '/web/进阶基础' },
        ]
      }
    },

    socialLinks: [  // 右上角的图标(如github这种)
      { icon: 'github', link: 'https://github.com/vuejs/vitepress' }
    ]
  }
})

文档模式

一共有三种模式呈现doc,page,home,默认以doc格式呈现
更改文档模式如下(在当前指定的md文件最上面填写如下代码)

---
layout:home
---

图片资源

图片资源放在根目录下的public文件夹内,可以直接写名字,默认这个名字的资源是去找public文件夹第一层去找同名文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萧寂173

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值