当前位置:网站首页>Ten minutes to teach you how to use VitePress to build and deploy a personal blog site
Ten minutes to teach you how to use VitePress to build and deploy a personal blog site
2022-08-09 13:15:00 【51CTO】
使用VitePressIt allows us to quickly build a static blog site,This article will lead you to build a foundationVitePressstatic blog site and deploy to GitHub Pages(githubServing static web pages)
快速上手
- 新建目录并初始化(My directory is named kittydocs)
这里我们使用pnpm式,当然yarn,npm都是可以的,如果你没有安装pnpm可以全局安装
然后初始化
- 安装vitepress
- package.json添加script
These three scripts respectively represent starting the local document service,打包文档,After starting the package(dist)服务
- 创建文档 文档放在docs目录下,新建docs/index.md
At this point our file structure is
- Start the local service documentation site
One will be activated at this pointhttp://localhost:3000/ 的服务,默认加载docs/index.md
A simple site here is done,当然这肯定是不够的,接下来我们看vitepress的配置
配置文件
在docs目录下创建一个 .vuepress
目录,如下结构
config.js导出一个js对象
At this point we restart the service to see it
导航栏
- title和logo
首先看一下title和logo的配置
其中logo的地址对应的是public下的图片,目录结构如下所示
这里logo我是用了vue的图标,此时页面效果为
- 右侧导航
我们可以在themeConfig.navConfigure the right navigation,And click to jump to our designated page.
同时我们在docs下新建guide/index.md和test.md
At this point, our page can show us playingnvaAnd supports jump localmarkdowndocuments and external links
We can also nest configurations like this,Makes a drop-down option appear in the navigation bar
If we want to have dropdown options grouped,That is, there is a dividing line in the middle,我们的nav可以这样写
此时效果为
Configure social linkssocialLinks
使用themeConfig.socialLinksOur social links can be configured,目前支持的有
,配置如下
侧边栏Sidebar
The sidebar can be found in themeConfig.Sidebar中配置,其实和nav配置差不多
Here I have carried some articles from my Nuggets and put them in,目录结构如下图
页面展示效果如下
However, we generally do not configure sidebars in this way,Because then every page will have a sidebar.We need to make the sidebar appear only for certain pages.所以我们可以这样配置
sideBarvalue to an object,对象的key是一个路径,The sidebar will only appear if this path is included.所以我们将nav的配置中的guildchange to blog,At the same time the path points to oursarticles下的markdown文件
At this point you will find that entering the home page does not appearsideBar,The sidebar will only appear if you click on the blog
Configure a collapsible sidebar
To configure a collapsible sidebar simply add collapsible
设置为true
即可,The default initial page is the Expand All page,If you need to close the state just put itcollapsed
设置为true
首页布局
The home page is to enter our blog and it will loaddocs/index.md,So we need to beautify it,我们VitePressThe default theme provides a home page layout
部署到GitHub Pages
既然要部署到GitHub Pages,你得先在github新建一个仓库,because he will be usedGitHub Pages,So the repository is named username.github.io的形式,username是你github的用户名.然后点击设置
选择pages
Set the root directory here/(root),Of course, other directories can also be selected,点击保存,If you choose another directory egdocs,config.js就需要配置一个base
Finally choose a topic(Do not select here I found that the site does not work,The packaged code can be pushed up later,会默认加载index.html)
然后将打包后的distPush the files below to your remote repository.vitepressThe official website provides us with a script filedeploy.sh
,We just need to change the remote repository
Execute this script file directly,Our packaged files will be pushed to our repository.Then we can directly access our static blog site,Like this example blog of mine 东方小月.If you want to customize other domain names,You can create an organization and then create a new repository named under the organizationorganization.github.io的形式(organizationis your organization name)Then do the same thing.Details can be clicked here 创建 GitHub Pages 站点
The final code has been pushed to kittypage,需要的可以自行获取
创作不易,你的点赞就是我的动力!如果感觉这篇文章对你有帮助的话就请点个赞吧,谢谢谢!!orz
边栏推荐
- API调用,API传参,面向对接开发,你真的会写接口文档吗?
- 听声辨物,这是AI视觉该干的???|ECCV 2022
- 自定义VIEW实现应用内消息提醒上下轮播
- 基于CAP组件实现补偿事务与幂等性保障
- AI basketball referee, walking is special, ask harden care don't care
- Batch大小不一定是2的n次幂!ML资深学者最新结论
- 内网穿透工具ngrok使用教程
- Shell之常用小工具(sort、uniq、tr、cut)
- JD.com architects tidy up: what are the core technical knowledge points of jvm and performance tuning
- Flutter入门进阶之旅(二)Hello Flutter
猜你喜欢
基于CAP组件实现补偿事务与幂等性保障
Flutter入门进阶之旅(七)GestureDetector
900页数学论文证明旋转的黑洞不会爆炸,丘成桐:30多年来广义相对论首次重大突破...
两个链表相加
1-hour live broadcast recruitment order: industry big names share dry goods, and enterprise registration opens丨qubit·viewpoint
系统提供的堆 VS 手动改写堆
Manchester city launch emotional intelligence scarf can be detected, give the fans
shell脚本------函数的格式,传参,变量,递归,数组
【Untitled】
8、IDEA提交代码出现: Fetch failed fatal: Could not read from remote repository
随机推荐
AQS同步组件-FutureTask解析和用例
我们真的需要DApp吗?App真的不能满足我们的幻想吗?
Shell之常用小工具(sort、uniq、tr、cut)
你没见过的《老友记》镜头,AI给补出来了|ECCV 2022
Flutter入门进阶之旅(八)Button Widget
Go-based web access parameters
[Interview high-frequency questions] Linked list high-frequency questions that can be gradually optimized
听声辨物,这是AI视觉该干的???|ECCV 2022
Scala Advanced (7): Collection Content Summary (Part 1)
The latest interview summary in 20022 brought by Ali senior engineer is too fragrant
Flutter入门进阶之旅(一)-初识Flutter
WeChat Mini Program Payment and Refund Overall Process
脱光衣服待着就能减肥,当真有这好事?
Flutter入门进阶之旅(二)Hello Flutter
Win10 compiles the x264 library (there are also generated lib files)
用 API Factory 产品生成 API 文档
Report: The number of students who want to learn AI has increased by 200%, and there are not enough teachers
基于CAP组件实现补偿事务与幂等性保障
How to upload local file trial version in binary mode in ABAP report
1-hour live broadcast recruitment order: industry big names share dry goods, and enterprise registration opens丨qubit·viewpoint