1. 配置账号-认证账号
1. 配置user.name和user.email
git config --global user.name niewj
git config --global user.email yourname@mail.com
#验证:
git config --global user.name
git config --global user.email
1.2 配置 ssh登录秘钥
ssh-keygen -t rsa -C "yourname@mail.com"
# 回车完事
#Your identification has been saved in /c/Users/weiju/.ssh/id_rsa.
#Your public key has been saved in /c/Users/weiju/.ssh/id_rsa.pub.
- 打开 c:/User/weiju/.ssh/id_rsa.pub 拷贝其中文本;
- 打开github网站: https://github.com/settings/keys -> "New SSH key":
Title: 取个名字, 如"blog";
key: 粘贴刚才赋值的 id_rsa.pub的文本
过程见下面: 认证成功!
niewj@LAPTOP-7EINAF4M MINGW64 /d/data/hexo $ ssh git@github.com The authenticity of host 'github.com (52.74.223.119)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts. PTY allocation request failed on channel 0 Hi niewj! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed. niewj@LAPTOP-7EINAF4M MINGW64 /d/data/hexo $ ssh git@github.com PTY allocation request failed on channel 0 Hi niewj! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed. niewj@LAPTOP-7EINAF4M MINGW64 /d/data/hexo $ ssh -T git@github.com Hi niewj! You've successfully authenticated, but GitHub does not provide shell access. niewj@LAPTOP-7EINAF4M MINGW64 /d/data/hexo
2. 安装博客框架 hexo
2.1 安装hexo和hexo-deployer-git插件
查看 npm有否, 有, 直接 npm install -g hexo 安装:
2.1.1 hexo安装
$ npm -v
6.4.1
niewj@LAPTOP-7EINAF4M MINGW64 /d/data/hexo
$ npm install -g hexo
C:\Users\weiju\AppData\Roaming\npm\hexo -> C:\Users\weiju\AppData\Roaming\npm\node_modules\hexo\bin\hexo
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules\hexo\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ hexo@5.1.1
added 88 packages from 348 contributors in 27.48s
我在安装过程中出现异常 TypeError: Console expects a writable stream instance
检查发现是nodejs版本问题, 我的是8.x的版本, 重新装了个v12.18.3, 然后重新来过:
$ node -v
v12.18.3
niewj@LAPTOP-7EINAF4M MINGW64 /d/data/hexo
$ npm -v
6.14.6
npm install -g hexo
安装完之后, 在本地创建一个目录, 比如我的; d:/data/hexo
打开cmd窗口, 用管理员身份运行
进入到此目录下:
D:\data\hexo>hexo init
INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
Cloning into 'D:/data/hexo/themes/landscape'...
remote: Enumerating objects: 733, done.
remote: Counting objects: 100% (733/733), done.
remote: Compressing objects: 100% (288/288), done.
Receiving objects: 100% (663/663), 684.30 KiB | 26.00 KiB/s, done.
emote: Total 663 (delta 415), reused 607 (delta 360), pack-reused 0
Resolving deltas: 100% (415/415), completed with 49 local objects.
From https://github.com/hexojs/hexo-theme-landscape
* branch 73a23c51f8487cfcd7c6deec96ccc7543960d350 -> FETCH_HEAD
Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'
[32mINFO [39m Install dependencies
added 183 packages from 420 contributors and audited 189 packages in 18.358s
8 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
INFO Start blogging with Hexo!
landscape 美 /ˈlændskeɪp/ n. 风景;风景画;景色;山水画;乡村风景画;地形
2.1.2 安装hexo-deployer-git插件
npm install
D:\data\hexo>npm install hexo-deployer-git --save
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ hexo-deployer-git@2.1.0
added 29 packages from 336 contributors and audited 218 packages in 126.928s
8 packages are looking for funding
run `npm fund` for details
found 1 low severity vulnerability
run `npm audit fix` to fix them, or `npm audit` for details
Git deployer plugin for Hexo
方便我们用hexo deploy
部署;
2.2 预览
# hexo server
D:\data\hexo>hexo server
INFO Validating config
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop
访问: http://localhost:4000/
看到页面, 是默认的主题;可以改变;
3. 部署到github的设置
涉及两个地方:
- hexo下的_config.yml配置文件
- github上的git地址: 选ssh的(之前都配置了访问认证的~)
拷贝 niewj.github.io 的ssh地址, 粘贴到 _config.yml
: (大概在最底下)
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repository: git@github.com:niewj/niewj.github.io.git
branch: master
4. 生成静态文件然后重启动
#hexo generate
# 也可以用 hexo g 简写
D:\data\hexo>hexo generate
INFO Validating config
INFO Start processing
INFO Files loaded in 87 ms
INFO Generated: archives/index.html
INFO Generated: archives/2020/index.html
INFO Generated: archives/2020/08/index.html
INFO Generated: index.html
INFO Generated: fancybox/fancybox_loading.gif
INFO Generated: fancybox/helpers/fancybox_buttons.png
INFO Generated: fancybox/fancybox_overlay.png
INFO Generated: fancybox/fancybox_loading@2x.gif
INFO Generated: fancybox/fancybox_sprite.png
INFO Generated: fancybox/fancybox_sprite@2x.png
INFO Generated: fancybox/blank.gif
INFO Generated: js/script.js
INFO Generated: fancybox/jquery.fancybox.css
INFO Generated: fancybox/helpers/jquery.fancybox-buttons.css
INFO Generated: fancybox/helpers/jquery.fancybox-buttons.js
INFO Generated: fancybox/helpers/jquery.fancybox-media.js
INFO Generated: fancybox/helpers/jquery.fancybox-thumbs.css
INFO Generated: css/style.css
INFO Generated: 2020/08/31/hello-world/index.html
INFO Generated: css/fonts/fontawesome-webfont.ttf
INFO Generated: fancybox/helpers/jquery.fancybox-thumbs.js
INFO Generated: css/fonts/fontawesome-webfont.eot
INFO Generated: fancybox/jquery.fancybox.pack.js
INFO Generated: css/fonts/fontawesome-webfont.woff
INFO Generated: css/fonts/FontAwesome.otf
INFO Generated: fancybox/jquery.fancybox.js
INFO Generated: css/fonts/fontawesome-webfont.svg
INFO Generated: css/images/banner.jpg
INFO 28 files generated in 532 ms
然后冲新启动看看:
#hexo server
# 或者简写 hexo s
D:\data\hexo>hexo s
INFO Validating config
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
5. 主题选择更改
官网主题链接: themes
5.1 选择主题:比如我选择了主题:3-hexo
点击 3-hexo
会跳转到GitHub开源的主题地址, 可以在hexo目录下 git clone
他的地址;
也可以直接下载zip包, 解压;
- 目录名改剪短: 直接改为:
3-hexo
; - 拷贝这个目录到
themes
目录下; - 修改
_config.yml
中的 theme:theme: 3-hexo
;
5.2 重新生成(管理员权限在cmd窗口)
d:\data\hexo>hexo generate
INFO Validating config
INFO Start processing
INFO Files loaded in 122 ms
INFO Deleted: favicon.png
INFO Deleted: styles.css
INFO Generated: img/school-book.png
INFO Generated: img/gov.png
INFO Generated: css/fonts/icomoon.eot
INFO Generated: css/fonts/icomoon.woff
INFO Generated: css/fonts/icomoon.svg
INFO Generated: css/fonts/iconfont.woff
INFO Generated: css/fonts/icomoon.ttf
INFO Generated: css/fonts/iconfont.eot
INFO Generated: 2020/08/31/hello-world/index.html
INFO Generated: archives/2020/08/index.html
INFO Generated: archives/index.html
INFO Generated: archives/2020/index.html
INFO Generated: index.html
INFO Generated: img/brown-papersq.png
INFO Generated: img/avatar.jpg
INFO Generated: css/fonts/iconfont.woff2
INFO Generated: css/fonts/iconfont.ttf
INFO Generated: css/fonts/iconfont.svg
INFO Generated: css/hl_theme/atom-dark.css
INFO Generated: img/article-list-background.jpeg
INFO Generated: css/mobile.css
INFO Generated: css/hl_theme/atom-light.css
INFO Generated: js/titleTip.js
INFO Generated: js/search.js
INFO Generated: css/hl_theme/brown-paper.css
INFO Generated: css/hl_theme/darcula.css
INFO Generated: css/hl_theme/github-gist.css
INFO Generated: css/hl_theme/github.css
INFO Generated: css/hl_theme/gruvbox-dark.css
INFO Generated: css/hl_theme/kimbie-light.css
INFO Generated: css/hl_theme/kimbie-dark.css
INFO Generated: css/hl_theme/rainbow.css
INFO Generated: css/hl_theme/gruvbox-light.css
INFO Generated: css/hl_theme/railscasts.css
INFO Generated: css/hl_theme/sublime.css
INFO Generated: css/hl_theme/school-book.css
INFO Generated: css/hl_theme/zenbum.css
INFO Generated: css/hl_theme/sunburst.css
INFO Generated: img/alipay.jpg
INFO Generated: js/jquery.pjax.js
INFO Generated: css/gitalk.css
INFO Generated: css/style.css
INFO Generated: css/fonts/selection.json
INFO Generated: js/script.js
INFO Generated: js/iconfont.js
INFO Generated: img/weixin.jpg
INFO Generated: js/gitment.js
INFO Generated: js/gitalk.js
INFO 48 files generated in 613 ms
重新启动server看看:
d:\data\hexo>hexo s
INFO Validating config
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
启动可以了~
6. 发布到github
d:\data\hexo>hexo clean
INFO Validating config
INFO Deleted database.
INFO Deleted public folder.
d:\data\hexo>hexo deploy
INFO Validating config
INFO Start processing
INFO Files loaded in 132 ms
INFO Generated: archives/index.html
INFO Generated: archives/2020/index.html
INFO Generated: archives/2020/08/index.html
INFO Generated: index.html
INFO Generated: img/gov.png
INFO Generated: img/school-book.png
INFO Generated: img/brown-papersq.png
INFO Generated: img/avatar.jpg
INFO Generated: js/search.js
INFO Generated: css/fonts/icomoon.eot
INFO Generated: css/hl_theme/brown-paper.css
......
.......
Counting objects: 62, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (55/55), done.
Writing objects: 100% (62/62), 514.83 KiB | 0 bytes/s, done.
Total 62 (delta 10), reused 0 (delta 0)
remote: Resolving deltas: 100% (10/10), done.
To git@github.com:niewj/niewj.github.io.git
* [new branch] HEAD -> master
Branch master set up to track remote branch master from git@github.com:niewj/niewj.github.io.git.
[32mINFO [39m Deploy done: [35mgit[39m
d:\data\hexo>
over!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。