Hexo的安装及重置恢复

2019-08-08 11:52:27 浏览数 (1)

写在前面

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

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

初始化Hexo

代码语言:javascript复制
# 回退时可以跳过初始化部分,从主题部分开始重置
**H:hexo>hexo init myblog**
INFO  Cloning hexo-starter to H:hexomyblog
Cloning into 'H:hexomyblog'...
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:hexohexo>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:hexohexonode_modules_nunjucks@3.0.1@nunjuckssrclib.js:34:15)
    at H:hexohexonode_modules_nunjucks@3.0.1@nunjuckssrcenvironment.js:489:31
    at new_cls.root [as rootRenderFunc] (eval at _compile (H:hexohexonode_modules_nunjucks@3.0.1@nunjuckssrcenvironment.js:568:24), <anonymous>
210:3)
    at new_cls.render (H:hexohexonode_modules_nunjucks@3.0.1@nunjuckssrcenvironment.js:482:15)
    at Hexo.module.exports (H:hexohexonode_modules_hexo-generator-feed@1.2.2@hexo-generator-feedlibgenerator.js:40:22)
    at Hexo.tryCatcher (H:hexohexonode_modules_bluebird@3.5.1@bluebirdjsreleaseutil.js:16:23)
    at Hexo.<anonymous> (H:hexohexonode_modules_bluebird@3.5.1@bluebirdjsreleasemethod.js:15:34)
    at H:hexohexonode_modules_hexo@3.4.0@hexolibhexoindex.js:340:24
    at tryCatcher (H:hexohexonode_modules_bluebird@3.5.1@bluebirdjsreleaseutil.js:16:23)
    at MappingPromiseArray._promiseFulfilled (H:hexohexonode_modules_bluebird@3.5.1@bluebirdjsreleasemap.js:61:38)
    at MappingPromiseArray.PromiseArray._iterate (H:hexohexonode_modules_bluebird@3.5.1@bluebirdjsreleasepromise_array.js:114:31)
    at MappingPromiseArray.init (H:hexohexonode_modules_bluebird@3.5.1@bluebirdjsreleasepromise_array.js:78:10)
    at MappingPromiseArray._asyncInit (H:hexohexonode_modules_bluebird@3.5.1@bluebirdjsreleasemap.js:30:10)
    at Async._drainQueue (H:hexohexonode_modules_bluebird@3.5.1@bluebirdjsreleaseasync.js:138:12)
    at Async._drainQueues (H:hexohexonode_modules_bluebird@3.5.1@bluebirdjsreleaseasync.js:143:10)
    at Immediate.Async.drainQueues (H:hexohexonode_modules_bluebird@3.5.1@bluebirdjsreleaseasync.js:17:14)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)
**H:hexohexo>cd ..**
**H:hexo>cd myblog**
**H:hexomyblog>hexo g**
ERROR Local hexo not found in H:hexomyblog
ERROR Try running: 'npm install hexo --save'
**H:hexomyblog>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:hexomyblognode_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:hexomyblognode_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:hexomyblog>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:hexomyblog>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. blogthemeindigo 将这个文件夹重命名(不要删,还有用)
  2. blogtheme 此目录下重新克隆 git clone https://github.com/yscoder/hexo-theme-indigo.git indogo
  3. 从原indigo中将一些基本文件替换到新的indigo中
    • indigo _config.yaml (注意是indigo目录下的配置文件)
    • indigosource (全部内容,除了js和css,这两部分可能包含先前的错误)
    • 基本的替换完成后即可运行了(当然现在的版本少了很多自定义内容)
  4. 开始恢复自定义代码,这部分每还原一步都要运行一下(本地部署运行)看是否(编译)正常
  5. 自定义代码集中在 indigolayout
    • indigolayout _partialmenu.ejs
    • indigolayout _partialfooter.ejs
    • indigolayout _partialpluginssite-visit
    • indigolayout _partialpluginspage-visit
    • indigolayout _partialpluginsgoogle-analytics.ejs
    • indigolayout _partialpluginsbaidu.ejs
    • indigolayouttag.ejs
    • indigosourcecssstyle.css
  6. 执行deploy提交git,与git源不冲突,可以正常提交,因为对git来说上述操作都是不可见的。
  7. 整个回退过程结束。

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

0 人点赞