VuePress建立的博客部署到GitHub或Gitee上

在上一篇中,我们详细介绍了如何利用VuePress搭建起个人博客系统,但这只是在本地debug启动的,接下来,我们把它部署到Github网站。

  • config.js中配置base

      base: '/v-blog/',

    v-blog是我Github上的仓库名

  • 编写自动化脚本

    在根目录/v-blog/下我们需要编写两个脚本

    因为写在一个脚本里话编译完会直接退出,

    所以把编译的命令单独放在另外一个脚本文件里调就可以了

    • build.bat

      @echo off
      vuepress build docs
    • deploy.bat

      @echo off
      
      echo building...
      call build.bat
      echo building-complete. cd docs/.vuepress/dist
      git init
      git add -A
      git commit -m 'auto-deploy'
      git remote add origin https://github.com/CoderMonkie/v-blog.git
      git pull
      git push --force origin HEAD:gh-pages REM To delete the dist folder
      cd ..
      echo delete-directory: "%cd%/dist"
      rmdir /s /q "%cd%/dist"
      cd..
      cd..
      echo Auto-Deploy-Complete!
      pause

    然后,只要双击执行depploy.bat就可以。

    或者配置到package.jsonscripts中。

    "scripts": {
    "deploy": "deploy.bat"
    }
    npm run deploy

    编译完成提及到远程的时候,会提示输入用户名密码。

    (或者保存登录权限信息使其静默推送)

  • GitHub中本项目的setting下确认

    我们在push时设为推送到gh-pages分支,

    此时,v-blog -- setting下的GitHub Pages设置,

    应该为gh-pages选中状态,不是的话改为gh-pages

    这样就完成了。如果GitHub Pages设置页显示:

    Your site is published at https://codermonkie.github.io/v-blog/

    那么说明网站发布了,可以查看。

    Your site is ready to be published at https://codermonkie.github.io/v-blog/.

    那么说明GitHub还没有完成给你发布,访问的话会是404,等待吧。


(深夜)更新:已经好了v-blog

GitHub Pages/source的下拉框里切换了几次,不经意间发现已经发布了。


补充:

补两张图,看起来能更简明,直截了当。

  • GitHub

    在【Setting -- GitHub Pages】的Source的下拉框中选择要使用的分支

    (也可以branch/docs文件夹,不过我们VuePress生成的博客嘛直接用分支了)

  • Gitee

    在【服务 -- Gitee Pages】点【启动】

    更新网站的话静态文件推送后要点【更新】


如果是要将博客部署到Gitee:

除了我们可以同时提交到两个远程(GitHub和Gitee仓库),

关联多个远程仓库,实现一次push多站提交

也可以在同一个工程文件里实现两个远程仓库的部署。

将上面给出的脚本deploy.bat,另存一份deploy-gitee.bat,

修改一下,主要有两处:

  • 远程地址(github -> gitee 的地址)
  • 提交到的远程分支名(gh-pages -> v-blog-pages)
@echo off

echo building...
call build.bat
echo building-complete. cd docs/.vuepress/dist
git init
git remote add origin https://gitee.com/coder-monkey/v-blog.git
git add -A
git commit -m 'auto-deploy'
git pull
git push --force origin HEAD:v-blog-pages REM To delete the dist folder
cd ..
echo delete-directory: "%cd%/dist"
rmdir /s /q "%cd%/dist"
cd..
cd..
echo Auto-Deploy-Complete!
pause

package.json里加scripts一个命令

"scripts": {
"deploy-gitee": "deploy-gitee.bat"
}

双击执行deploy-gitee.bat或以下:

npm run deploy-gitee

再稍微动动手脚本稍作修改就可以实现一次命令多个远程部署了~


auto-deploy.bat最终版:

@echo off

echo building...
call build.bat
echo building-complete. cd docs/.vuepress/dist git init
git config user.name maonianyou
git config user.email maonianyou@foxmail.com
git add -A
git commit -m "%date% %time% auto-deploy"
REM 静默推送的话可在地址里填入username和password,如
REM git remote add origin https://username:password@gitee.com/username/repo.git
git remote add origin https://gitee.com/coder-monkey/v-blog.git
git pull
git push --force origin HEAD:v-blog-pages
echo "Gitee Pages Deploy Complete!" REM 部署完上面的 Gitee Pages
REM 需要删除 .git 文件夹
REM 以备部署 GitHub Pages 再次初始化时用
rmdir /s /q "%cd%/.git" git init
git config user.name maonianyou
git config user.email maonianyou@gmail.com
git add -A
git commit -m "%date% %time% auto-deploy"
REM 静默推送的话可在地址里填入username和password,如
REM git remote add origin https://username:password@github.com/username/repo.git
git remote add origin https://github.com/CoderMonkie/v-blog.git
git pull
git push --force origin HEAD:gh-pages
echo "GitHub Pages Deploy Complete!" REM To delete the dist folder
cd ..
echo delete-directory: "%cd%/dist"
rmdir /s /q "%cd%/dist"
cd..
cd..
echo Auto-Deploy-Complete!
pause
  "scripts: {
"deploy": "auto-deploy.bat"
}
npm run deploy

还能继续改进?

  • package.json/scripts

    加一条,执行git pushauto-deploy.bat

    这样推送加部署就一口气完成啦

  • 使用netlify或者travis-ci这样的工具

    GitHubWebHook也要了解一下

更多好玩的,赶快来探索吧~

将`VuePress`建立的博客部署到GitHub或Gitee上的更多相关文章

  1. 怎么把使用vuepress搭建的博客部署到Github Pages

    推荐在这里阅读效果更佳 背景 网上搜了很多教程,包括官网的教程,但是还是费了一番功夫, 如果你使用自动化部署脚本部署不成功的话,可以参考我的这个笨方法 这是部署后的效果 前提 我假设你本地运行OK, ...

  2. 搭建自己的技术博客系列(二)把 Hexo 博客部署到 GitHub 上

    1.在GitHub上建一个新仓库

  3. hexo博客部署到github无法上传的问题

    博客生成之后,按照网上别人的教程,讲项目部署到github上,修改_config.yaml中的deploy部分如下所示: deploy: type: git repository: https://g ...

  4. Hexo博客部署-使用github作为保存中转仓库

    本篇是在VPS上搭建Hexo静态博客的第一篇博文,写本篇的目的一是纪念一下,二是作为一个部署文档保留. 博客地址 相关描述 VPS环境是在搬瓦工上安装的centos6(x86),1核,512MB,10 ...

  5. Hexo 博客部署到 GitHub

    本文简单记录了一下把 Hexo 部署到 GitHub 上的过程,也是搭建静态博客最常用的一种方式. 前面写了关于如何把 Hexo 安装在树莓派上的教程,但树莓派毕竟是连着自己的家的路由器,万一哪天网断 ...

  6. 上一周,小白的我试着搭建了两个个人博客:在github和openshift上

    上一周,突发奇想,想搭建个自己的博客. 由于是突发奇想,自然想先找免费的试试手.仔细搜索下,选定了目标Openshift和Github. Openshift 安装WordPress OpenShift ...

  7. Hexo博客部署到远程仓库(Conding、Gitee、Github)

    一.本地环境搭建 1.安装Git Git可以有效.高速的处理各种项目版本管理.也就是用来管理你的hexo博客文章,上传到GitHub的工具. Git下载地址 安装好了之后使用git -version查 ...

  8. 手把手教你使用 VuePress 搭建个人博客

    手把手教你使用 VuePress 搭建个人博客 有阅读障碍的同学,可以跳过第一至四节,下载我写好的工具包: git clone https://github.com/zhangyunchencc/vu ...

  9. 使用VuePress搭建个人博客

    使用VuePress搭建个人博客 VuePress 是一个基于 Vue 的静态网站生成器.其中主要用到:Vue,VueRouter,Webpack. 类似的工具:hexo 基于 Markdown 语法 ...

随机推荐

  1. Codeforces Round #509 (Div. 2) A. Heist 贪心

    There was an electronic store heist last night. All keyboards which were in the store yesterday were ...

  2. ubuntu16.04安装FastDFS-5.08

    fastdfs github地址: https://github.com/happyfish100/ 1.FastDFS上传原理 - storage定时向tracker上传状态信息 - client上 ...

  3. System.Linq.Dynamic字符串转委托

    以前一直想着有没有一个方法能够把字符串直接转化成函数的,刚好有需求就找了下,还真有. 微软地址:https://docs.microsoft.com/en-us/previous-versions/b ...

  4. Java集合面试题汇总篇

    文章收录在 GitHub JavaKeeper ,N线互联网开发必备技能兵器谱 作为一位小菜 "一面面试官",面试过程中,我肯定会问 Java 集合的内容,同时作为求职者,也肯定会 ...

  5. MySQL存储过程举例

    涉及循环.动态sql等主要的MySQL存储过程知识. 需求: 遍历所有[test_ondev_[0-9]]开头的表,将其中的所有数据按表中的col字段存储到[test_ondev_history_ + ...

  6. P2320鬼谷子的钱袋(分治)

    ------------恢复内容开始------------ 描述:https://www.luogu.com.cn/problem/P2320 m个金币,装进一些钱袋.钱袋中大于1的钱互不相同. 问 ...

  7. Elasticsearch系列---Term Vector工具探查数据

    概要 本篇主要介绍一个Term Vector的概念和基本使用方法. term vector是什么? 每次有document数据插入时,elasticsearch除了对document进行正排.倒排索引 ...

  8. java读源码 之 list源码分析(ArrayList)---JDK1.8

    java基础 之 list源码分析(ArrayList) ArrayList: 继承关系分析: public class ArrayList<E> extends AbstractList ...

  9. 微信小程序-swiper(轮播图)抖动问题

    ps:问题 组件swiper(轮播图)真机上不自动滚动 一直卡在那里抖动 以前遇到这个问题,官方一直没有正面回复.就搁置了,不过有大半年没写小程序了也没去关注,今天就去看了下官方文档,发觉更新了点好东 ...

  10. SQL语言概况(4.1)

    SQL语言概况(4.1) 目录 SQL语言概况(4.1) 4.1 SQL语言概况 4.1.1 历史及标准简介 4.1.2 SQL语言定义及特点 4.1.3 使用说明 参考资料: 数据库原理及设计(第3 ...