【Hexo】更换设备后部署博客

👋 本人自己换电脑时进行的操作。

🦋 适合本人自己,大家仅供参考!

1 工具准备

1.1 安装 Git

直接去官网下载Git并安装,如果国内网速太慢可以“科学上网”或者从其他平台下载。安装时一路next到底就行了,也可以在网上找教程。

可参考安装教程
Git 详细安装教程(详解 Git 安装过程的每一个步骤)

1.2 安装 VS Code(可选)

在安装Git之前,我建议先安装 VS Code。因为安装 Git Bash 时,可以设置 VS Code 作为默认编辑器。Visual Studio Code,简称 VS Code。目前最为强大易用的编辑器,轻量且快速。

可下载 .ZIP 压缩包便携版。

链接直达

1.3 安装 Node.js(可选)

建议下载长期支持版,而非当前发布版,因为如果是最新版,容易出现一些奇妙的 bug。

可参考安装教程
Node.js安装与配置(详细步骤)
node.js安装及环境配置超详细教程【Windows系统安装包方式】

国内使用 npm 可能很慢,你可以“科学上网”,或者考虑切换为 taobao 镜像源,即手动输入以下内容后按回车(也可以Ctrl+CCtrl+V复制以下代码按回车):

1
npm config set registry https://registry.npm.taobao.org

2 生成SSH密钥

Windows 用户建议使用 Windows PowerShell 或者 Git Bash,最好是 Git Bash ,在 命令提示符(cmd) 下无 catls 命令。

2.1 生成 SSH Key

1
ssh-keygen -t ed25519 -C "3332664073@qq.com"
  • -t key 类型
  • -C 注释

输出,如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/git/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/git/.ssh/id_ed25519
Your public key has been saved in /home/git/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:ohDd0OK5WG2dx4gST/j35HjvlJlGHvihyY+Msl6IC8I 3332664073@qq.com
The key's randomart image is:
+--[ED25519 256]--+
| .o |
| .+oo |
| ...O.o + |
| .= * = +. |
| .o +..S*. + |
|. ...o o..+* * |
|.E. o . ..+.O |
| . . ... o =. |
| ..oo. o.o |
+----[SHA256]-----+
  • 中间通过三次回车键确定

2.2 查看SSH key

1
ls ~/.ssh/

输出:

1
id_ed25519  id_ed25519.pub
  • 私钥文件 id_ed25519
  • 公钥文件 id_ed25519.pub

2.3 读取公钥文件

1
cat ~/.ssh/id_ed25519.pub

输出,如:

1
ssh-ed25519 AAAA***5B 3332664073@qq.com

2.4 复制 SSH 公钥

如果您的 SSH 公钥文件与示例代码不同,请修改文件名以匹配您当前的设置。 在复制密钥时,请勿添加任何新行或空格。

1
clip < ~/.ssh/id_ed25519.pub

3 覆盖SSH文件

3.1 下载备份文件

阿里云盘backup -> .ssh文件夹下载下来,或 百度网盘我的资源 -> backup -> .ssh文件夹下载下来

3.2 覆盖

将下载下来的 .ssh 文件夹里面的密钥覆盖到电脑 C:\Users\用户名\.ssh 路径下

4 写作

4.1 克隆源码

git clone我的GitHub账号下的hexo的源码

1
git clone git@github.com:aizhiqian/hexo.git

如果出错,这是上一步SSH覆盖后的权限错误,自行上网查找

4.2 新建文件

在没安装 Node.js ,也就没安装 hexo-cli 的情况下,可以仿照以前的 post 文章源码头部新建 .md 文件,然后将其放在 source\_posts 目录下。

1
2
3
4
5
6
7
8
9
10
11
12
---
title:
date:
tags:
-
-
categories:
keywords:
description:
top_img:
cover:
---

4.3 推送

1
2
3
git add .
git commit -m "自定义信息"
git push origin main

!!注:push之后,这时的源码文章文件不会自动添加 abbrlink ,但是真实文章链接却是含有 abbrlink 的链接,此时只需要 git pull origin main 源码到本地,并在本地运行 hexo clean && hexo g 命令,再次 push 即可。


5 最好使用以下步骤:

  • 安装 Node.js、VSCode、Git、hexo-cli
  • git clone git@github.com:aizhiqian/hexo.git
  • npm install
  • hexo n "文章标题"
  • hexo clean && hexo g
  • 最后 push