我的第一篇博客

一直以来就很想写博客,作为一名码农,也曾经想自己搭建一个,但是苦于技术实在太渣,人又懒(没救了),造不了车轮,也没能力造。于是兜兜转转,浪费了好长时间,终于下定决心用hexo。
原因很简单,一来逼格很高,二来开拓眼界,再来hexo写博客也很方便(虽然说我从来没有用过其它的博客)。
下面就讲一下我刚接触hexo走过的弯路。

按照官网的做法

1
2
3
$ hexo init <folder>
$ cd <folder>
$ npm install

npm install死活无法安装,报错“xcode-select: error: tool ‘xcodebuild’ requires Xcode, but active developer directory ‘/Library/Developer/CommandLineTools’ is a command line tools instance”

官网推荐的做法是安装xcode,并在xcode中安装命令行工具。

For Mac users
You may encounter some problems when compiling. Please install Xcode from App Store first. After Xcode is installed, open Xcode and go to Preferences -> Download -> Command Line Tools -> Install to install command line tools.

大概原因是因为在执行npm install的时候,会去执行node-gyp.py文件,而这个文件的执行依赖xcode。
详细可见:Problems on Mavericks with only Command Line Tools installed

这个做法我显然是不能接受的。第一,我压根不需要xcode。第二,我的磁盘容量有限,要省着点花。我根本没有必要为了解决这个错误,特意去安装一个好几个G的IDE。
寻寻觅觅,终于在网上找到了一个方法,将npm install改为

1
$ npm install --no-optional

终于绕过了xcode的安装。

事情到了这里还没有结束

当一切都安装完毕之后,我看了一下项目的结构是这样的

1
2
3
4
5
6
7
8
9
.
├── _config.yml
├── package.json
├── scaffolds
├── scripts
├── source
| ├── _drafts
| └── _posts
└── themes

可是我的结构里怎么都没有_drafts文件夹,当我去执行hexo publish命令时会报错,因为publish命令是将_draft文件夹内的文件放到_post文件夹下。几经周折才发现,_draft文件夹的创建是要用命令

1
$ hexo new draft <title>

当执行以上命令时,项目就会自动生成_draft文件夹,并在该文件夹下生成你指定title的.md文件。

仅以此作为第一次用hexo搭建博客时遇到的坎儿。留表纪念!

avatar

chilihotpot

You Are The JavaScript In My HTML