在新机器上部署hexo
环境
C:\Users\黄壮壮>node -v
v10.14.2
C:\Users\黄壮壮>npm -v
6.4.1
$ git --version
git version 2.20.1.windows.1
- hexo
npm install hexo -g,开始安装Hexo
建立hexo项目
在制定文件夹下初始化hexo项目
hexo init
初始化信息
D:\blog_hexo>hexo init
INFO Cloning hexo-starter to D:\blog_hexo
Cloning into 'D:\blog_hexo'...
remote: Enumerating objects: 68, done.
remote: Total 68 (delta 0), reused 0 (delta 0), pack-reused 68
Unpacking objects: 100% (68/68), done.
Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
Cloning into 'D:/blog_hexo/themes/landscape'...
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 867 (delta 8), reused 5 (delta 1), pack-reused 846
Receiving objects: 100% (867/867), 2.55 MiB | 155.00 KiB/s, done.
Resolving deltas: 100% (457/457), done.
Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'
�[32mINFO �[39m Install dependencies
npm WARN deprecated titlecase@1.1.2: no longer maintained
npm WARN deprecated postinstall-build@5.0.3: postinstall-build's behavior is now built into npm! You should migrate off of postinstall-build and use the new `prepare` lifecycle script with npm 5.0.0 or greater.
> nunjucks@3.1.6 postinstall D:\blog_hexo\node_modules\nunjucks
> node postinstall-build.js src
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
added 422 packages from 501 contributors and audited 4700 packages in 19.884s
found 0 vulnerabilities
INFO Start blogging with Hexo!
hexo与gitee page建立连接
- 设置Git的username与email
D:\blog_hexo>git config --global user.name "Q10Viking"
D:\blog_hexo>git config --global user.email "1193094618@qq.com"
- 生成密钥
会创建.ssh文件夹,制定我们要生成的文件名
Enter file in which to save the key (/c/Users/黄壮壮/.ssh/id_rsa): /c/Users/黄壮壮/.ssh/gitee_id_rsa
$ ssh-keygen -t rsa -C "1193094618@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/黄壮壮/.ssh/id_rsa): /c/Users/黄壮壮/.ssh/gitee_id_rsa
Created directory '/c/Users/黄壮壮/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/黄壮壮/.ssh/gitee_id_rsa.
Your public key has been saved in /c/Users/黄壮壮/.ssh/gitee_id_rsa.pub.
The key fingerprint is:
SHA256:6iYxI/Zn6R2/ErZtJAaTqJ6auwKpLOHX6wkmvfL4A+g 1193094618@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| |
| |
| . . |
| . + |
|.. . oS |
|=.= + .= . |
|*=.B.+.+.* |
|+E*o=o*.ooo |
|B==+oX+ .oo. |
+----[SHA256]-----+
在gitee中的Q10Viking项目中添加公钥
问题解决
问题: git@gitee.com: Permission denied (publickey)
添加密钥到ssh-agent
eval "$(ssh-agent -s)"
添加生成的SSH key到ssh-agent
ssh-add ~/.ssh/gitee_id_rsa
过程
黄壮壮@LAPTOP-4K4RIFUD MINGW64 ~/.ssh
$ ssh -T git@gitee.com
git@gitee.com: Permission denied (publickey).
黄壮壮@LAPTOP-4K4RIFUD MINGW64 ~/.ssh
$ eval "$(ssh-agent -s)"
Agent pid 8060
黄壮壮@LAPTOP-4K4RIFUD MINGW64 ~/.ssh
$ ssh-add ~/.ssh/gitee_id_rsa
Identity added: /c/Users/黄壮壮/.ssh/gitee_id_rsa (1193094618@qq.com)
黄壮壮@LAPTOP-4K4RIFUD MINGW64 ~/.ssh
$ ssh -T git@gitee.com
Hi Q10Viking! You've successfully authenticated, but GITEE.COM does not provide shell access.
- deploy
D:\blog_hexo>hexo d -g
... ...
git@gitee.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: git@gitee.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
at ChildProcess.<anonymous> (D:\blog_hexo\node_modules\hexo-util\lib\spawn.js:37:17)
at ChildProcess.emit (events.js:182:13)
at ChildProcess.cp.emit (D:\blog_hexo\node_modules\cross-spawn\lib\enoent.js:40:29)
at maybeClose (internal/child_process.js:962:16)
at Socket.stream.socket.on (internal/child_process.js:381:11)
at Socket.emit (events.js:182:13)
at Pipe._handle.close (net.js:610:12)
$ ssh -T git@gitee.com
Hi Anonymous! You've successfully authenticated, but GITEE.COM does not provide shell access.
Note: Perhaps the current use is DeployKey.
Note: DeployKey only supports pull/fetch operations
- 解决
在博客blog_hexo文件下将密钥添加到ssh-agent中
黄壮壮@LAPTOP-4K4RIFUD MINGW64 /d/blog_hexo
$ ssh -T git@gitee.com
git@gitee.com: Permission denied (publickey).
黄壮壮@LAPTOP-4K4RIFUD MINGW64 /d/blog_hexo
$ eval "$(ssh-agent -s)"
Agent pid 15248
黄壮壮@LAPTOP-4K4RIFUD MINGW64 /d/blog_hexo
$ ssh-add ~/.ssh/gitee_id_rsa
Identity added: /c/Users/黄壮壮/.ssh/gitee_id_rsa (1193094618@qq.com)
黄壮壮@LAPTOP-4K4RIFUD MINGW64 /d/blog_hexo
$ ssh -T git@gitee.com
Hi Q10Viking! You've successfully authenticated, but GITEE.COM does not provide shell access.
在git bash中运行,不要再cmd中
黄壮壮@LAPTOP-4K4RIFUD MINGW64 /d/blog_hexo
$ hexo d -g
INFO Start processing
INFO Files loaded in 83 ms
... ...
On branch master
nothing to commit, working tree clean
remote: Powered By Gitee.com
Branch 'master' set up to track remote branch 'master' from 'git@gitee.com:q10viking/Q10Viking.git'.
To gitee.com:q10viking/Q10Viking.git
+ a714c32...8f1302b HEAD -> master (forced update)
INFO Deploy done: git
hexo项目于git关联后
为github迁移到gitee做准备
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
添加了git信息
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[branch "master"]
remote = git@gitee.com:q10viking/Q10Viking.git
merge = refs/heads/master
deploy:
type: git
repository: git@gitee.com:q10viking/Q10Viking.git
branch: master
Next主题
下载主题
下载到hexo项目下的 themes/next 中
黄壮壮@LAPTOP-4K4RIFUD MINGW64 /d/blog_hexo
$ git clone https://github.com/theme-next/hexo-theme-next themes/next
Cloning into 'themes/next'...
remote: Enumerating objects: 31, done.
remote: Counting objects: 100% (31/31), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 4785 (delta 12), reused 22 (delta 11), pack-reused 4754
Receiving objects: 100% (4785/4785), 4.91 MiB | 87.00 KiB/s, done.
Resolving deltas: 100% (2891/2891), done.
使用主题
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
## theme: landscape
theme: next
迁移
- 从github迁移到gitee
- 从旧电脑迁移到新电脑
- github->gitee迁移在新电脑上按上面配置好环境,新建一个hexo项目,此时使用的git的仓库使用gitee的,这样这个项目就会提交到我们建立在gitee的仓库中。主要涉及两个文件关于git
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repository: git@gitee.com:q10viking/Q10Viking.git
branch: master
[branch "master"]
remote = git@gitee.com:q10viking/Q10Viking.git
merge = refs/heads/master
- 旧电脑-->新电脑迁移在将旧电脑的next主题的所有文件拷贝过来,放在themes目录下(任然使用Next主题),将sources目录下的文件(我们写的文章)复制到新电脑对应的目录
图床
在hexo项目下的source目录下新建一个imgs文件用来存储图片
使用Typora编辑器,用相对路径加载图片