博客搬家笔记

windows迁移至mac,遇到了无数bug,简单记录一下。

迁移环境:

  • windows10 -> macOS Big Sur
  • hexo v3.9.0 -> v6.0.0
  • NexT.Pisces v7.3.0 -> v5.1.4

一、mac搭建本地环境

本部分参考博客:https://www.jianshu.com/p/c3b6e7f84321

1. 环境安装

git和node.js

1
2
brew install git
brew install node

hexo

1
2
3
4
5
6
7
8
9
10
# 安装hexo
npm install hexo-cli -g

# 初始化hexo目录
mkdir blog
cd blog

# 新建hexo服务
hexo init
hexo s

打开 localhost:4000查看是否成功

2. ssh密钥设置

1
2
3
4
5
# 查看本地密钥
cd ~/.ssh

# 如果没有就生成
ssh-keygen -t rsa -C "example@example.com"

之后复制 ~/.ssh/id_rsa.pub里面的内容到GitHub个人主页的Settings -> SSH and GPG keys→New SSH key,并点击确认邮件

1
2
3
4
5
6
7
8
9
10
11
12
# 测试连接
ssh git@github.com

#这里要等很长时间并且选yes,被坑了很久……
tina@TinadeMBP .ssh % ssh git@github.com
The authenticity of host 'github.com (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ECDSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi maomaoyu804! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

3. 设置个人信息

1
2
git config --global user.name "yourname”
git config --global user.email youremail@example.com

二、搬一下之前的文件

站点根目录需要替换的内容:
_config.yml、scaffolds、source、themes、public
坑1:我的hexo+next版本太久了,导致搬过来后部分内容显示有问题,所以直接使用旧版本的config可能有一些锅,建议重新配一下config,orz……具体的一堆坑下文会提到。
不过不是很确定是不是必须更新,毕竟有亿点点麻烦……

三、启动

1. 尝试启动

此时用的还是旧版本hexo

1
hexo s

坑2:启动不起来

1
err: Error: Cannot find module xxx

解决办法:缺什么装什么

1
npm install cheerio --save

参考博客:https://www.jianshu.com/p/c3b6e7f84321

坑3:启动成功后,并没有显示网站,而是如下内容:

1
{% extends ‘_layout.swig‘ %} {% import ‘_macro/post.swigas post_template %}

解决办法:hexo在5.0后把swig删除,需要自己安装

1
npm i hexo-renderer-swig

参考博客:https://blog.csdn.net/qq_39898645/article/details/109181736

2. 启动后

启动成功后,归档等标签图标无法正常解析,查博客说是版本太久了无法正常解析……
于是我走上了更新NexT的不归路……
参考博客:https://www.jianshu.com/p/02a8be67b391

四、重新配置config

NexT官网:http://theme-next.iissnan.com/getting-started.html
大体上照着原来的博客配就可以。
坑4:在点击首页或者归档等位置时出现

1
Cannot GET /tags/%20/

找到主题配置文件的menu位置,把||前面的空格删掉:

1
2
3
4
5
6
7
8
9
menu:
home: /||home
#about: /about/||user
#tags: /tags/ || tags
#categories: /categories/ || th
archives: /archives/||archive
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat

这个坑解决了orz
坑5:点击头像下面的日志会出现跟刚刚很像的问题

1
cannot get archives%7C%7C%20archive

于是尝试把刚刚位置的||及后面都删掉,发现字前面的图标没了……
解决方法:在themes/next/layout/_macro/sidebar.swig中:

1
2
3
4
5
# 找到
<a href="{{ url_for(theme.menu.archives).split('||')[0] | trim }}">

# 修改为
<a href="{{ url_for(theme.menu.archives[0].path) }}">

参考博客:https://blog.csdn.net/qq_44852901/article/details/122817214(好厉害啊orz……

自闭了,吃饭。