当前位置:网站首页>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
边栏推荐
- FFmpeg compiles and installs on win10 (configure libx264)
- Information system project managers must memorize the core test sites (63) The main process of project portfolio management & DIPP analysis
- 国产抗新冠口服药每瓶不超300元/ 我国IPv6网络全面建成/ 谷歌入局折叠屏手机...今日更多新鲜事在此...
- AI basketball referee, walking is special, ask harden care don't care
- h264 protocol
- win10编译x264库(也有生成好的lib文件)
- 字符串转换整数 (atoi)
- 【微服务~远程调用】整合RestTemplate、WebClient、Feign
- Rust从入门到精通04-数据类型
- 发明时代,「幂集创新」事关你我
猜你喜欢
Flutter入门进阶之旅(八)Button Widget
Blocking, non-blocking, multiplexing, synchronous, asynchronous, BIO, NIO, AIO all in one pot
数字化转型之支撑保障单元
ThreadLocal的简单理解
MySQL principle and optimization of Group By optimization techniques
智驾科技完成C1轮融资,此前2轮已融4.5亿元
Scala Advanced (7): Collection Content Summary (Part 1)
Scala 高阶(七):集合内容汇总(上篇)
How should the acceptance criteria for R&D requirements be written?| Agile Practices
合并两个有序列表
随机推荐
How to upload local file trial version in binary mode in ABAP report
WPF implements a MessageBox message prompt box with a mask
Golang学习之路(五):Golang的函数
goalng-sync/atomic原子操作
HAproxy:负载均衡
Common gadgets of Shell (sort, uniq, tr, cut)
[Interview high-frequency questions] Linked list high-frequency questions that can be gradually optimized
Rust从入门到精通04-数据类型
虚拟机安装出现的问题汇总
Flutter入门进阶之旅(六)Layout Widget
【HCIP持续更新】IS-IS协议原理与配置
AI basketball referee, walking is special, ask harden care don't care
位图与位运算
Apexsqlrecover无法连接数据库
GRPC整体学习
系统提供的堆 VS 手动改写堆
Glory to the Blue Yonder, speeds up the strategic growth
读写分离后,性能居然提升100%了呀
Scala Advanced (7): Collection Content Summary (Part 1)
荣耀携手Blue Yonder,加快企业战略增长