安装
安装插件 hexo-deployer-git
npm install hexo-deployer-git --save |
配置
修改站点配置文件_config.yml
# You can use this: |
-
branch:将静态站点部署到的 Git 分支
- 在 GitHub 上默认
gh-pages
- 在 Coding.net 上默认
coding-pages
- 否则默认为
master
- 在 GitHub 上默认
-
token :令牌值,用于对 repo 进行身份验证。
$
前缀,可从Hexo环境变量中读取令牌(推荐)。 -
repo_name:部署到多个存储库时的唯一名称。例如
deploy:
repo:
# 两种语法都支持
github: https://github.com/user/project.git,branch
gitee:
url: https://gitee.com/user/project.git
branch : branch_name -
message:提交消息。默认为
Site updated: {{ now('YYYY-MM-DD HH:mm:ss') }}
. -
name 和 email:用于提交更改的用户信息,覆盖全局配置。此信息与 git login 无关
-
extend_dirs:要发布的其他目录。例如
demo
,examples
-
ignore_hidden:(Boolean|Object)是否忽略要发布的隐藏文件
-
ignore_pattern:(Object|RegExp)部署时选择忽略模式
# _config.yaml
deploy:
- type: git
repo: git@github.com:<username>/<username>.github.io.git
branch: master
- type: git
repo: git@gitee.com:<username>/<username>.git
branch: src
extend_dirs: /
ignore_hidden: false
ignore_pattern:
public: .deploy:
type: git
repo:
github: git@github.com:<username>/<username>.github.io.git
coding: git@git.coding.net:<username>/<username>.coding.me.git
gitee: git@gitee.com:<username>/<username>.git
branch: master
使用令牌部署
虽然此插件可以从配置中解析身份验证令牌,但仅当您确定不会提交配置时才使用此方法,包括提交到私有存储库。更安全的方法是将它作为环境变量添加到 CI 中,然后简单地将环境变量的名称添加到此插件的配置中(例如$GITHUB_TOKEN
)。
附加指南:
- 创建 GitHub 个人访问令牌
- 将身份验证令牌添加到 Travis CI。[链接]
工作方式
hexo-deployer-git
通过在 config 中生成站点.deploy_git
并强制推送到 repo(es) 来工作。如果.deploy_git
不存在,将初始化一个 repo ( git init
)。否则将使用当前的 repo(及其提交历史)。
用户可以将部署的 repo 克隆到.deploy_git
以保留提交历史记录。
git clone <gh-pages repo> .deploy_git |
重启
删除.deploy_git
文件夹。
rm -rf .deploy_git |
大小写敏感
git 对大小写不敏感,因此仅修改文件名大小写在 Hexo 中并不会被重新部署,但是网页路径却对大小写敏感,这样常常会引起 404,对此只需删除.deploy_git
下对应的文件夹即可。