记录一次博客被玩坏的经历!同时也学到了:
 
事情是这样的:操作部分从这里开始看 
本来博客已经搭建完毕了,零零碎碎的基本功能也已经基本实现,但是在尝试使用PWA功能的时候,整个博客崩溃了,网上的帖子也看了几十上百篇,但仍然挽救不了,于是打算重装。
鉴于本地文件已经被玩坏了,各种报错,遂将 GitHub 上的内容给拷贝下来,才发现事情没有那么简单,配置文件那些全部都没有!!!才明白这个博客框架只是将一部分生成页面的文件发布到了 GitHub,于是从废纸篓取出刚刚删除的配置文件。
操作部分: 
重装不是完完全全地重装,后续是找回垃圾篓里的配置文件操作的。
可能每个人写笔记的方式不一样,为了方便易懂:
注释即为操作的步骤,文档类型即为操作的位置或者修改文件的位置,例bash类型即为在命令行里的操作,markdown类型即为在某个文件里修改内容或其他操作。
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 hexo init blog hexo -v cd  blognpm install hexo n '第一篇hexo文章'  hexo g hexo s npm install hexo-server --save hexo clean npm install --save hexo-deployer-git 
 
1 2 3 4 # 修改配置文件_config.yml  type: git repo: git@github.com:xgyxss/xgyxss.github.io.git branch: main 
 
1 2 hexo d --message 'Blog Optimization'  
 
1 2 # 在hexo目录下,新建一个CNAME文件,该文件没有后缀名,内容即为GitHub Pages中的Custom domain,即为:yexingshusheng.com yexingshusheng.com 
 
1 2 # 修改 _config.yml 文件  url: https://yexingshusheng.com 
 
1 # 在仓库xxx.github.io -> Settings -> Pages中将Custom domain改为:yexingshusheng.com,待其check完毕后,即可在网址中直接通过自定义域名yexingshusheng.com访问。 
 
1 2 3 4 npm install hexo-theme-melody vim _config.yml 
 
 
1 2 3 4 5 6 7 8 9 10 11 npm install hexo-renderer-pug hexo-renderer-stylus --save touch  _config.melody.ymlcp  ./node_modules/hexo-theme-melody/_config.yml _config.melody.ymlnpm update hexo-theme-melody hexo new page tags 
 
1 2 3 4 5 --- title: 标签 date: 2021-12-15 05:20:00 type: "tags" --- 
 
1 2 hexo clean;hexo g;hexo s; 
 
1 2 hexo new page categories 
 
1 2 3 4 5 --- title: 分类 date: 2021-12-15 05:20:00 type: "categories" --- 
 
 
1 2 3 4 5 --- title: Slides date: 2021-12-15 05:20:00 type: "slides" --- 
 
 
1 2 3 4 5 --- title: Gallery date: 2021-12-15 05:20:00 type: "gallery" --- 
 
 
1 2 3 4 5 6 --- title: 404 date: 2021-12-15 05:20:00 layout: 404 permalink: /404 --- 
 
 
1 2 3 4 5 --- title: 运营历史 date: 2021-12-15 05:20:00 type: "history" --- 
 
 
1 2 3 4 5 --- title: 关于作者 date: 2021-12-15 05:20:00 type: "about" --- 
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 # 修改_config.melody.yml文件  theme_ color:  enable: true   main: "#49B1F5"   paginator: "#00C4B6"   button_hover: "#FF7242"    text_ selection: "#00C4B6"  link_color: "#858585"    hr_ color: "#A4D8FA"  tag_start_ color: "#A4D8FA"   tag_end_ color: "#1B9EF3"   header_text_ color: "#EEEEEE"   footer_text_ color: "#EEEEEE" menu:   Home: /   Archives: /archives   Tags: /tags   Categories: /categories   History: /history   About: /about 
 
至此,只需要根据官网完善后续步骤即可。
毕竟不是第一次安装了,后续就直接将垃圾篓里的文件 package.json、_config.yml、_config.melody.yml、source 目录找回,安装package.json里对应的插件,然后将 _config.yml、_config.melody.yml 这两个配置文件里的部分内容更改即可。
配置完之后本应该没问题了,又另外出了一点 bug。
报错大致如下: 
1 2 3 4 5 6 7 8 WARN No layout 404.html WARN No layout categories/index.html WARN No layout tags/index.html WARN No layout comments/index.html WARN No layout about/index.html WARN No layout history /index.html WARN No layout index.html ... 
 
排查:
插件
 
主题
检查配置文件是否更改成当前安装的主题。
 
markdown 文件
 
 
网上的资料千篇一律的是插件的丢失,本博客最终查出是对应的 markdown 文件的空格问题 。
拿 404.md 文件为例:
1 2 3 4 5 title: 404 date: 2021-12-15 16:08:14 layout: 404 permalink: /404 comments: false 
 
当时写的是:
1 2 3 4 5 title:404 date:2021-12-15 16:08:14 layout:404 permalink:/404 comments:false 
 
对比可以看出,该问题是由于缺少空格 ,导致文件渲染出了问题,进而导致整个博客页面渲染空白。
解决:依次将报错的文件的对应位置添加空格,即可成功渲染。