Test

记录hexo搭建博客过程

Go Go Go

1.安装hexo

Installing Hexo is quite easy and only requires the following beforehand:

  1. Node.js (Should be at least Node.js 10.13, recommends 12.0 or higher)
  2. Git
    If your computer already has these, congratulations! You can skip to the following command.
1
npm install -g hexo-cli

npm全称Node Package Manager,它是Nodejs的包管理器。

Once Hexo is installed, run the following commands to initialize Hexo in the target <folder>.

1
2
3
hexo init <folder>
cd <folder>
npm install

Once initialized, here’s what your project folder will look like:

1
2
3
4
5
6
7
8
.
├── _config.yml
├── package.json
├── scaffolds
├── source
| ├── _drafts
| └── _posts
└── themes

2.打开本地端口,预览页面

1
hexo server

3.新建一篇博客,默认为post类型

1
2
hexo new "my blog name"
hexo new draft "my blog name"#新建draft类型博客,暂不发布

默认为post类型,可在_config.yml内调整#writing标签下调整default_layout更改。

进行主要内容的创作 ···

4.部署到远程站点

1
hexo deploy

首次部署前需要
1.创建名称为kyrie2to11.github.io的github仓库,注意仓库名只能为个人github账户名.github.io
2.在本地任意文件夹内利用git bash产生 ssh key

1
ssh-keygen -t rsa -C "agentoftheshield123@gmail.com"

3.将产生的rsa公钥(文件名为id_rsa.pub)添加到对应仓库的deploy key内
4.安装hexo-deployer-git插件

1
npm install hexo-deployer-git --save

5.编辑_config.yml配置2处
url模块更改url

1
url: https://kyrie2to11.github.io/

deployment模块更改

1
2
3
4
deploy:
type: git
repo: https://github.com/kyrie2to11/kyrie2to11.github.io.git
branch: master #gh-pages

6.更改#Site设置

1
2
3
4
5
6
7
8
# Site
title: Jarvis's Blog
subtitle: '记录生活,沉淀自己'
description: '记录学习和生活,留下时光的痕迹'
keywords:
author: jarvis
language: zh-Hans
timezone: Asia/Shanghai

5.hexo命令

以上命令需要cd到文件夹/jarvis才有效

1
2
3
4
5
hexo n "postName"   # 新建文章
hexo clean # 清除缓存
hexo g # 生成静态网页
hexo s # 本地预览
hexo d # 部署到Github

6.博客备份

新建一个blog_backup仓库(private),创建完成后,在VScode终端中执行以下命令

1
2
3
4
5
6
git init       # 初始化仓库
git add . # 添加文件到暂存区
git commit -m "first commit" # 将暂存区内容添加到仓库
git branch -M main # 重命名分支为main
git remote add origin https://github.com/kyrie2to11/Blog_backup.git # 添加到远程版本库
git push -u origin main # 提交到Github

7.文件目录

关于博客文件目录,我们目前只需要知道以下几个重要的文件目录即可:

public目录下存放的是我们生成的「静态页面」;

source/_posts目录下存放的是我们写的「文章」;

themes目录下存放的是「博客」的主题;

_config.yml是「博客全局配置」文件;

_config.landscape.yml是「博客主题配置」文件。

8.SSH连接命令

1
ssh -T git@github.com

在powershell输入后出现以下结果:

1
Hi kyrie2to11! You've successfully authenticated, but GitHub does not provide shell access.

9.远程部署后只显示内容,未加载主题

问题描述:
本地部署正常加载主题和内容,部署到github后打开网页只加载内容不加载主题

问题解决:
_config.yml文件#URL设置错误,误将#URL模块内的url:设置为与#Deployment模块内的repo:相同。
参考知乎问题下Erain的回答。链接:https://www.zhihu.com/question/319817323
具体改正如下:

1
2
3
url: https://github.com/kyrie2to11/kyrie2to11.github.io.git #此url设置错误,改为下一行

url: https://kyrie2to11.github.io/

更改设置并部署后,强制刷新浏览器(shift+F5)即可。


问题描述:
Hexo d部署报错之spawn failed

问题解决:
修改配置文件中的repo
具体改正如下:

1
repo: git@github.com:kyrie2to11/kyrie2to11.github.io.git

更改设置并部署后,强制刷新浏览器(shift+F5)即可。

10.hexo卸载

1
npm uninstall -g hexo-cli