前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Hexo的安装及重置恢复

Hexo的安装及重置恢复

作者头像
ZONGLYN
发布2019-08-08 11:52:27
2.4K0
发布2019-08-08 11:52:27
举报
文章被收录于专栏:程序萌部落程序萌部落

写在前面

Hexo博客已经使用挺长时间了,其出色的静态网页渲染能力深得我的喜欢,然鹅也是因为 Hexo 基本完全依赖渲染模板的原因,如果在整博客的过程中引入了错误的代码段或者和已有代码发生了冲突,会直接影响博客的正常渲染,对于Hexo来说,不能渲染就等于完全废了;针对出现的错误,有时候我们还不一定能找得出来。经常是改一处错两处,那么到了迫不得已的时候,就有必要对博客进行重置了。

关于 Hexo 博客的重置,一般只需重置主题即可,因为 99% 的错误都是在主题文件中的,Hexo主框架自安装完就不会有什么改动。下面,就从重置主题开始,简单记录下我重置过程的代码。

初始化Hexo

代码语言:javascript
复制
# 回退时可以跳过初始化部分,从主题部分开始重置
**H:\hexo>hexo init myblog**
INFO  Cloning hexo-starter to H:\hexo\myblog
Cloning into 'H:\hexo\myblog'...
remote: Counting objects: 59, done.
remote: Total 59 (delta 0), reused 0 (delta 0), pack-reused 59
Unpacking objects: 100% (59/59), done.
Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
Cloning into 'H:/hexo/myblog/themes/landscape'...
remote: Counting objects: 785, done.
remote: Total 785 (delta 0), reused 0 (delta 0), pack-reused 784
Receiving objects: 100% (785/785), 2.54 MiB | 476.00 KiB/s, done.
Resolving deltas: 100% (403/403), done.
Submodule path 'themes/landscape': checked out 'decdc2d9956776cbe95420ae94bac87e22468d38'
INFO  Install dependencies
错误: 找不到或无法加载主类 install
INFO  Start blogging with Hexo!
**H:\hexo>cd hexo**
**H:\hexo\hexo>hexo g**
INFO  Start processing
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Template render error: (unknown path) [Line 8, Column 23]
  Error: Unable to call `the return value of (posts["first"])["updated"]["toISOString"]`, which is undefined or falsey
    at Object.exports.prettifyError (H:\hexo\hexo\node_modules\_nunjucks@3.0.1@nunjucks\src\lib.js:34:15)
    at H:\hexo\hexo\node_modules\_nunjucks@3.0.1@nunjucks\src\environment.js:489:31
    at new_cls.root [as rootRenderFunc] (eval at _compile (H:\hexo\hexo\node_modules\_nunjucks@3.0.1@nunjucks\src\environment.js:568:24), <anonymous>
210:3)
    at new_cls.render (H:\hexo\hexo\node_modules\_nunjucks@3.0.1@nunjucks\src\environment.js:482:15)
    at Hexo.module.exports (H:\hexo\hexo\node_modules\_hexo-generator-feed@1.2.2@hexo-generator-feed\lib\generator.js:40:22)
    at Hexo.tryCatcher (H:\hexo\hexo\node_modules\_bluebird@3.5.1@bluebird\js\release\util.js:16:23)
    at Hexo.<anonymous> (H:\hexo\hexo\node_modules\_bluebird@3.5.1@bluebird\js\release\method.js:15:34)
    at H:\hexo\hexo\node_modules\_hexo@3.4.0@hexo\lib\hexo\index.js:340:24
    at tryCatcher (H:\hexo\hexo\node_modules\_bluebird@3.5.1@bluebird\js\release\util.js:16:23)
    at MappingPromiseArray._promiseFulfilled (H:\hexo\hexo\node_modules\_bluebird@3.5.1@bluebird\js\release\map.js:61:38)
    at MappingPromiseArray.PromiseArray._iterate (H:\hexo\hexo\node_modules\_bluebird@3.5.1@bluebird\js\release\promise_array.js:114:31)
    at MappingPromiseArray.init (H:\hexo\hexo\node_modules\_bluebird@3.5.1@bluebird\js\release\promise_array.js:78:10)
    at MappingPromiseArray._asyncInit (H:\hexo\hexo\node_modules\_bluebird@3.5.1@bluebird\js\release\map.js:30:10)
    at Async._drainQueue (H:\hexo\hexo\node_modules\_bluebird@3.5.1@bluebird\js\release\async.js:138:12)
    at Async._drainQueues (H:\hexo\hexo\node_modules\_bluebird@3.5.1@bluebird\js\release\async.js:143:10)
    at Immediate.Async.drainQueues (H:\hexo\hexo\node_modules\_bluebird@3.5.1@bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)
**H:\hexo\hexo>cd ..**
**H:\hexo>cd myblog**
**H:\hexo\myblog>hexo g**
ERROR Local hexo not found in H:\hexo\myblog
ERROR Try running: 'npm install hexo --save'
**H:\hexo\myblog>cnpm install**
| [8/9] Installing cssom@0.3.xplatform unsupported hexo@3.4.0 › hexo-fs@0.2.2 › chokidar@1.7.0 › fsevents@^1.0.0 Package require os(darwin) not compa
ible with your platform(win32)
[fsevents@^1.0.0] optional install error: Package require os(darwin) not compatible with your platform(win32)
√ Installed 9 packages
√ Linked 274 latest versions
> hexo-util@0.6.1 build:highlight H:\hexo\myblog\node_modules\_hexo-util@0.6.1@hexo-util
> node scripts/build_highlight_alias.js > highlight_alias.json
√ Run 1 scripts
deprecate hexo@3.4.0 › swig@1.4.2 This package is no longer maintained
Recently updated (since 2017-10-29): 1 packages (detail see file H:\hexo\myblog\node_modules\.recently_updates.txt)
√ All packages installed (310 packages installed from npm registry, used 29s, speed 39.09kB/s, json 283(524.52kB), tarball 608.11kB)
**H:\hexo\myblog>hexo g**
INFO  Start processing
INFO  Files loaded in 207 ms
INFO  Generated: index.html
INFO  Generated: archives/index.html
INFO  Generated: fancybox/blank.gif
INFO  Generated: archives/2017/11/index.html
INFO  Generated: fancybox/fancybox_sprite.png
INFO  Generated: fancybox/jquery.fancybox.css
INFO  Generated: fancybox/fancybox_sprite@2x.png
INFO  Generated: fancybox/fancybox_loading.gif
INFO  Generated: fancybox/fancybox_loading@2x.gif
INFO  Generated: fancybox/jquery.fancybox.pack.js
INFO  Generated: fancybox/jquery.fancybox.js
INFO  Generated: archives/2017/index.html
INFO  Generated: fancybox/fancybox_overlay.png
INFO  Generated: css/fonts/FontAwesome.otf
INFO  Generated: fancybox/helpers/jquery.fancybox-buttons.css
INFO  Generated: fancybox/helpers/jquery.fancybox-thumbs.css
INFO  Generated: js/script.js
INFO  Generated: css/fonts/fontawesome-webfont.eot
INFO  Generated: css/fonts/fontawesome-webfont.woff
INFO  Generated: css/style.css
INFO  Generated: fancybox/helpers/fancybox_buttons.png
INFO  Generated: fancybox/helpers/jquery.fancybox-thumbs.js
INFO  Generated: fancybox/helpers/jquery.fancybox-buttons.js
INFO  Generated: fancybox/helpers/jquery.fancybox-media.js
INFO  Generated: 2017/11/05/hello-world/index.html
INFO  Generated: css/fonts/fontawesome-webfont.svg
INFO  Generated: css/fonts/fontawesome-webfont.ttf
INFO  Generated: css/images/banner.jpg
INFO  28 files generated in 546 ms
**H:\hexo\myblog>hexo s**
INFO  Start processing
INFO  Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.

主题部分(初始化/重置)

Hexo模块化的结构和生成流程决定了Hexo本身和主题theme是分离的,或者说耦合性不大,如果博客的主题在先使用过程中出现了一些无法修改的问题,那么就需要重置一下主题,比如我是用的indigo主题。 再次提醒,大部分错误都是theme中的错误导致的,在替换时只需要修改blog目录中的theme文件夹,替换其中的主题即可,blog根目录的东西一般不会出毛病(一般自定义时都是修改主题内的文件)。 注:为什么不用版本控制,因为本身对主题修改的地方不多,且直接重新克隆可以保持主题的最新状态。

重置步骤
  1. blog\theme\indigo 将这个文件夹重命名(不要删,还有用)
  2. blog\theme 此目录下重新克隆 git clone https://github.com/yscoder/hexo-theme-indigo.git indogo
  3. 从原indigo中将一些基本文件替换到新的indigo中
    • indigo\ _config.yaml (注意是indigo目录下的配置文件)
    • indigo\source (全部内容,除了js和css,这两部分可能包含先前的错误)
    • 基本的替换完成后即可运行了(当然现在的版本少了很多自定义内容)
  4. 开始恢复自定义代码,这部分每还原一步都要运行一下(本地部署运行)看是否(编译)正常
  5. 自定义代码集中在 indigo\layout
    • indigo\layout\ _partial\menu.ejs
    • indigo\layout\ _partial\footer.ejs
    • indigo\layout\ _partial\plugins\site-visit
    • indigo\layout\ _partial\plugins\page-visit
    • indigo\layout\ _partial\plugins\google-analytics.ejs
    • indigo\layout\ _partial\plugins\baidu.ejs
    • indigo\layout\tag.ejs
    • indigo\source\css\style.css
  6. 执行deploy提交git,与git源不冲突,可以正常提交,因为对git来说上述操作都是不可见的。
  7. 整个回退过程结束。

正常来说,上述操作可以发现到底是在修改那个文件时出现错误,如果是一些不知道怎么引起的疑难杂症,通过这样的替换工作也可以将版本回退到正常的版本。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-12-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 写在前面
  • 初始化Hexo
  • 主题部分(初始化/重置)
    • 重置步骤
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档