本文已发布于个人博客 Ne0Ng's Blog
Travis CI 加 Hexo 实现自动构建部署 Github Pages 博客 | Ne0Ng's Blog
几天前从新安装 fedora 31, 因而趁着过年在家从新搭建了这个博客,顺便折腾了 Travis CI 来自动构建部署个人博客,而后把个人 Hexo 博客文件放到了 Github 上,终于不用怕我从新安装系统时忘记备份个人博客了。同时也不须要在本地配置系统了。<!-- more -->html
npm install -g hexo-cli
hexo init username.github.io
username
是你的 Github 用户名,固然也能够把 username.github.io
替换成你想要的任何名字node
_config.yml
项目 | 解释 | 怎么改 |
---|---|---|
title |
网站的标题 | 啥都行,例如个人站点标题叫 Ne0Ng's Blog |
author |
你的名字 | 这个填上你的名字 |
language |
网站的语言 | 都能看个人博客了,那就改为 zh-CN |
timezone |
网站的时区 | 国内的地区都填上 Asia/Shanghai |
url |
网站的连接 | 若是你没有域名的话,就填 username.github.io |
其余的修改能够参考 Hexo 的文档
在本文里面,以Suka
主题为例子更多自定义参考 Suka Docgit
cd themes git clone https://github.com/SukkaW/hexo-theme-suka.git suka cd suka npm install --production cp -i _config.example.yml _config.yml
# 回到站点的根目录 cat themes/suka/site_config.yml >> _config.yml
编辑站点的 _config.yml
,将 theme: landscape
改成 theme: suka
github
改好以后,你站点的 _config.yml
大概是这样npm
# Extensions ## Plugins: https://hexo.io/plugins/ ## Themes: https://hexo.io/themes/ theme: suka # Deployment ## Docs: https://hexo.io/docs/deployment.html deploy: type: '' # Suka-theme suka_theme: search: enable: true path: search.json field: post # Page | Post | All. Default post prism: enable: false line_number: true theme: default
hexo s --debug # 确认站点功能正常
因为我是在 CI 阶段从网络直接 clone 整个主题,因此我就将 themes/
加入了 .gitignore
,因此这里你还要将主题的配置文件复制到站点根目录内,以后 CI 阶段再将其放回原位置。(若是你用的主题有其余的配置文件时应该一并复制到站点根目录)json
复制一份主题的配置文件缓存
cp themes/suka/_config.yml _config.theme.yml
初始化 gitbash
git init
确保 .gitignore
内有下面的内容 (若是没有这个文件的话能够本身建立)网络
.DS_Store Thumbs.db db.json *.log node_modules/ public/ .deploy*/ themes/
新建一个 repo 命名为 username.github.io (username
是你的 Github 帐户名称)
# 添加 Github 仓库到本地 git remote add origin https://github.com/username/username.github.io.git # 新建一个名为 source 的分支 git checkout -b source # 将全部文件添加到 git git add . # 添加 commit git commit -m "initial" # 将本地的文件推送到 Github 上的 source 分支 git push -u origin source
若是操做上没有问题你上传以后 repo 里面的文件应该差很少是这样的
. ├── _config.theme.yml ├── _config.yml ├── .gitignore ├── package.json ├── package-lock.json ├── scaffolds └── source
repo
这个 scopes ),而后把 token 的值记录下来 GH_TOKEN
, 值( VALUE )为你上一步记录的 token,最后保存.travis.yml
的文件,参考如下内容进行填入,(我都有注释,不要照抄)os: linux language: node_js node_js: - 10 # 使用 nodejs LTS v10 branches: only: - source # 只监控 source 的 branch cache: directories: - node_modules # 缓存 node_modules 加快构建速度 before_script: ## 根据你所用的主题和自定义的不一样,这里会有所不一样 - npm install -g hexo-cli # 在 CI 环境内安装 Hexo - mkdir themes # 因为咱们没有将 themes/ 上传,因此咱们须要新建一个 - cd themes - git clone https://github.com/SukkaW/hexo-theme-suka.git suka #从 Github 上拉取 Suka 主题 - cd suka - npm install --production # 安装 Suka 主题的依赖 - cd ../.. # 返回站点根目录 - cp _config.theme.yml themes/suka/_config.yml # 将主题的配置文件放回原处 - npm install # 在根目录安装站点须要的依赖 script: - hexo generate # generate static files deploy: # 根据我的状况,这里会有所不一样 provider: pages skip_cleanup: true # 构建完成后不清除 token: $GH_TOKEN # 你刚刚设置的 token keep_history: true # 保存历史 fqdn: blog.ne0ng.page # 自定义域名,使用 username.github.io 可删除 on: branch: source # hexo 站点源文件所在的 branch local_dir: public target_branch: master # 存放生成站点文件的 branch,使用 username.github.io 必须是 master
master
分支查看到生成的站点文件写完以后一直再修改,最近修改将一些步骤写清楚了(为一些内容加了注释),如今我认为应该很清楚了,若是你有看到的话欢迎给我留言(有发现什么错误或我写的不够清楚的话更要给我留言😂。
本文做者 : Ne0Ng
本文采用CC BY-NC-SA 4.0许可协议.
本文连接 : https://blog.ne0ng.page/archives/proxy-for-dnf/