盒子
盒子
文章目录
  1. 目的
  2. GitHub 操作
    1. 新建 Pages 仓库
    2. 获取 tokens
  3. GitLab 操作
    1. 新建自己的 hexo 仓库
    2. clone一份官方 hexo 仓库到本地
  4. 文件配置
  5. GitHub域名
  6. 总览

hexo 通过 gitlab-ci 部署到 github

目的

Markdown 文件提交到 GitLab ,通过 GitLabci 工具,自动采用 hexo 将其渲染为 html 文件并部署到 GitHub 。可以真正做到

只维护 Markdown 的博客源文件即可

提交 Markdown 就能看博客

源文件、配置文件长久备份

跨平台、跨终端

GitHub 操作

新建 Pages 仓库

假如你的 GitHub 用户名为 xxx ,新建 共有仓库 xxx.github.io

获取 tokens

GitHub 上获取一个 只用于 操作 repoPersonal access tokens

具体路径为

SettingsDeveloper settingsPersonal access tokensGenerate new token

注意权限勾选 repo 即可

GitLab 操作

新建自己的 hexo 仓库

gitlab 新建一个自己的 私有仓库 。在这里我们假设命名为 blog

clone一份官方 hexo 仓库到本地

地址:https://gitlab.com/pages/hexo

将其 clone 到本地,删除 .git 文件夹,并将该文件夹初始化为自己在 gitlab新建的仓库blog

文件配置

  • 修改 hexoconfig.yml 文件

    url: your-blog-url
    root: /

    deploy:
    type: git
    repository:
    github: https://personal-access-token:x-oauth-basic@github.com/xxx/xxx.github.io.git
    branch: master

    your-blog-url 替换为自己的博客地址

    把上面从 GitHub 获取的 personal-access-token 放到这里来

    xxx 替换为自己的用户名

  • 修改 .gitlab-ci.yml 文件

    image: node:10.15.3

    cache:
    paths:
    - node_modules/

    before_script:
    - git config --global user.name "github user name"
    - git config --global user.email "gitub email"
    - npm install -g hexo
    - npm install -g hexo-cli
    - npm install
    - npm install hexo-deployer-git --save

    pages:
    stage: deploy
    script:
    - hexo clean
    - hexo generate
    - hexo deploy
    artifacts:
    paths:
    - public
    only:
    - master

GitHub域名

source 文件夹新建文件 CNAME 并写入你的域名,例如

www.holmeyoung.com

总览

$ tree -L 2       
.
├── _config.yml
├── package.json
├── scaffolds
│   ├── draft.md
│   ├── page.md
│   └── post.md
├── source
│   ├── about
│   ├── categories
│   ├── CNAME
│   ├── _posts
│   └── tags
└── themes
└── next

现在只需要写好 markdown 文件,放到 _posts 文件夹,提交到 GitLab ,稍等编译结束,访问你的博客域名就能看见啦

支持一下
万一真的就有人扫了呢
  • 微信扫一扫
  • 支付宝扫一扫