初始化Hexo

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# 回退时可以跳过初始化部分,从主题部分开始重置
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. 整个回退过程结束。

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