安装前提
安装 Hexo 相当简单。然而在安装前,您必须检查系统中中是否已安装下列应用程序:
安装 Git
shell>um install git-core
安装 Node.js
shell>wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
安装完成后,重启终端并执行下列命令即可安装 Node.js。
shell>nvm install stable
安装 Hexo
shell>npm install -g hexo-cli
安装 Hexo 完成后,请执行下列命令,Hexo 将会在指定文件夹中新建所需要的文件。
shell>cd /usr/local
shell>mkdir Hexofolder
shell>cd Hexofolder
shell>hexo init /usr/local/Hexofolder
shell>npm install
新建完成后,指定文件夹的目录如下:
. ├── _config.yml ├── package.json ├── scaffolds ├── source | ├── _drafts | └── _posts └── themes |
_config.yml
网站的 配置 信息,您可以在此配置大部分的参数。
package.json
应用程序的信息。EJS, Stylus 和 Markdown renderer 已默认安装,您可以自由移除。
scaffolds
模版 文件夹。当您新建文章时,Hexo 会根据 scaffold 来建立文件。
Hexo的模板是指在新建的markdown文件中默认填充的内容。例如,如果您修改scaffold/post.md中的Front-matter内容,那么每次新建一篇文章时都会包含这个修改。
source
资源文件夹是存放用户资源的地方。除 _posts 文件夹之外,开头命名为 _ (下划线)的文件 / 文件夹和隐藏的文件将会被忽略。Markdown 和 HTML 文件会被解析并放到 public 文件夹,而其他文件会被拷贝过去。
themes
主题 文件夹。Hexo 会根据主题来生成静态页面。
安装hexo
hexo 3.0把服务器独立成个别模块,需要单独安装:
shell>hexo-server
搭桥到github
没账号的创建账号,有账号的看下面。
创建一个repo,名称为yourname.github.io, 其中yourname是你的github名称,按照这个规则创建才有用哦,如下:
登录阿里云,配置github账户信息(YourName和YourEail都替换成你自己的):
shell>git config --global user.name "xxxx"
shell>git config --global user.email "xxxxxx@outlook.com"
创建SSH
生成秘钥
//换成你自己的邮箱
shell>ssh-keygen -t rsa -C "xxxxx@outlook.com"
//一直next并记住生成的地址
Your public key has been saved in /root/.ssh/id_rsa.pub.
进入.ssh 目录提出key
shell>cat id_rsa.pub
//把显示的内容复制到GitHub的SSHkey配置即可
shell>cat id_rsa.pub
添加一个 New SSH key ,title随便取,key就填刚刚那一段。
验证是否添加成功
在终端输入
shell>ssh -T git@github.com
[The authenticity of host 'github.com (192.xxx.xxx.xxx' can't be established.
RSA key fingerprint is 16:27:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,192.xxx.xxx.xxx' (RSA) to the list of known hosts.
Hi megoc! You've successfully authenticated, but GitHub does not provide shell access.
修改_config.yml文件的一些配置(冒号之后都是有一个半角空格的):
deploy:
type: git
repo: https://github.com/YourgithubName/YourgithubName.github.io.git
branch: master
进入 Hexofolder目录,分别执行以下命令:
shell>hexo clean
shell>hexo generate
shell>hexo server
打开浏览器输入:http://localhost:4000 你就可以访问了,但是这必须是在本地配置本地访问,所以这个我们并无法预览,ctrl+c干掉它,我们继续
上传到github
先安装一波:npm install hexo-deployer-git --save(这样才能将你写好的文章部署到github服务器上并让别人浏览到)
执行命令(建议每次都按照如下步骤部署,一定要在 /usr/local/Hexofolder/目录下):
shell>hexo clean
shell>hexo generate
shell>hexo deploy
注意deploy的过程中要输入你的username及passward。如下:
在浏览器中输入http://yourgithubname.github.io就可以看到你的个人博客了。
感觉gitbash中东西太多的时候输入clear命令清空。
如果404找不到资源,等会重新执行上述命令再访问。