0%

2024年Hexo博客迁移到另一台电脑

简洁版,快速的完成迁移

首要注意

本篇适用于之前已经搭建过,需要迁移操作。

其中的执行命令你都可以在这篇文章找到相应的解释。

基本情况

Win11系统

所有命令均在PS进行

准备

安装Node.js

安装过程我只更改了路径,其他保持默认,一步步点击Next

安装git

配置npm代理

设置npm代理

1
2
npm config set proxy http://XXX:XXX
npm config set https-proxy http://XXX:XXX

如果要取消代理,则

1
2
npm config delete proxy
npm config delete https-proxy

参考:

https://blog.zuiyu1818.cn/posts/node_package

配置git代理

1.全局代理

1
2
git config --global http.proxy http://XXX:XXX
git config --global https.proxy https://XXX:XXX

2.只对github代理

1
2
git config --global http.https://github.com.proxy https://XXX:XXX
git config --global https.https://github.com.proxy https://XXX:XXX

参考:

https://www.cnblogs.com/China-Dream/p/16476775.html

备份文件夹文件

需要备份的文件夹文件如下:

  1. 博客配置文件./_config.yml
  2. 主题文件夹./theme/
  3. 文章及相关内容的文件夹./source/
  4. 模板文件夹./scaffolds/
  5. 依赖包的名字及版本号./package.json

Hexo本地搭建

安装Hexo

创建文件夹blog(即你的博客文件夹)

在该文件夹下,执行下面命令:

1
npm install -g hexo-cli

输出结果:

1
2
3
4
added 53 packages in 12s

14 packages are looking for funding
run `npm fund` for details

复制备份文件夹文件

复制备份文件夹文件到blog

在新电脑中重新部署

blog文件夹中执行

1
npm install

输出结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
npm warn deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm warn deprecated cuid@2.1.8: Cuid and other k-sortable and non-cryptographic ids (Ulid, ObjectId, KSUID, all UUIDs) are all insecure. Use @paralleldrive/cuid2 instead.
npm warn deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm warn deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm warn deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated glob@6.0.4: Glob versions prior to v9 are no longer supported
npm warn deprecated rimraf@2.4.5: Rimraf versions prior to v4 are no longer supported
npm warn deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgrade to @latest
npm warn deprecated hexo-bunyan@2.0.0: Please see https://github.com/hexojs/hexo-bunyan/issues/17
npm warn deprecated swig-templates@2.0.3: unmaintained
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported

added 246 packages, and audited 247 packages in 26s

17 packages are looking for funding
run `npm fund` for details

15 vulnerabilities (2 low, 7 moderate, 3 high, 3 critical)

To address issues that do not require attention, run:
npm audit fix

To address all issues (including breaking changes), run:
npm audit fix --force

Run `npm audit` for details.

本地测试

1
2
hexo g   #生成静态文件
hexo s #启动服务预览

看命令行输出,你可以访问http://localhost:4000/来预览你的博客了。

注:

如果服务启动成功,但是使用Chrome打开网址显示此网站无法提供安全连接ERR_SSL_PROTOCOL_ERROR,是因为Chrome自动把http转为https。你可以尝试更换浏览器或者尝试搜索解决Chrome自动http转为https的问题。(并不是端口号等的问题)。

部署至github

安装hexo-deployer-git

blog文件夹中执行如下命令:

1
npm install hexo-deployer-git --save

输出结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
up to date, audited 247 packages in 12s

17 packages are looking for funding
run `npm fund` for details

15 vulnerabilities (2 low, 7 moderate, 3 high, 3 critical)

To address issues that do not require attention, run:
npm audit fix

To address all issues (including breaking changes), run:
npm audit fix --force

Run `npm audit` for details.

设置你的账户默认身份

执行下面命令,我填写的是我的github邮箱和我的github名字:

1
2
git config --global user.email "you@example.com"
git config --global user.name "Your Name"

两个命令都没有任何输出结果

链接远程仓库

生成新的SSH钥匙:

1
ssh-keygen -t rsa -C "your_email@example.com"

your_email@example.com我填的是github的邮箱,过程期间按回车,完成后,找到并打开生成的id_rsa.pub文件(C:\Users\XXX\.ssh\id_rsa.pub),复制所有的内容。

打开你的github主页,依次点击右上角你的头像->Settings,在该页面的左侧找到SSH and GPG keys,在SSH keys一栏中点击New SSH key,你可以在Title随便起个名字,并把复制的id_rsa.pub文件内容粘贴到Key中。

注:

部署至github这个标题下,起初我没有进行链接远程仓库这个操作,其他依次进行,虽然git了过去,但github pages部署失败。

部署

执行下面命令部署至github:

1
hexo d

到这里你就可以在你的github pages查看你的网站啦。

后记

整个过程还是比较简单的。

有些地方应该增加些解释,对于git、hexo等很多的知识我还没有学习。

如果你发现文章中的任何的错误,欢迎告诉我,也欢迎技术等任何讨论。

谢谢你的来访,下篇文章见: )

本文参考:

https://swayye.xyz/2020/01/10/hexo博客迁移/ (主要)

https://swayye.xyz/2018/12/28/建站历程:安装及部署篇/ (主要)

欢迎打赏