hexo 安装&配置

MAC升级系统之后很多东西都没有了,hexo也出现了各种奇奇怪怪的问题,索性全部重新安装过了一遍,简单记录下安装搭建hexo的过程。

安装nodejs

brew install node

安装hexo

npm install -g hexo
##创建blog文件夹 创建一个blog文件夹,并在这个文件夹新建所有blog所需要的文件
mkdir blog
hexo init

安装依赖包

npm install

本地查看

hexo g
hexo s

部署到github

在github创建一个和你github用户名一样的项目

检查添加ssh key

检查SSH keys的设置

cd ~/.ssh 检查本机的ssh密钥
如果提示:'No such file or directory' 说明你是第一次使用git,那就生成新的ssh key ###生成ssh key
$ ssh-keygen -t rsa -C "邮件地址@youremail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):<回车就好>

添加SSH Key到GitHub

登陆github,Account Settings—->SSH Public keys —-> add another public keys

cat /Users/Edward_L/.ssh/id_rsa.pub
把这个密钥添加进去就好了 ###测试
$ ssh -T git@github.com
看到'Hi cnfeat! You've successfully authenticated, but GitHub does not provide shell access.'这个就好了~ ### 设置用户信息
$ git config --global user.name "cnfeat"//用户名
$ git config --global user.email  "cnfeat@gmail.com"//填写自己的邮箱

将独立域名与GitHub Pages的空间绑定

在source中新建一个名为CNAME的文本文件,里面写入你要绑定的域名,例如

EdwardL.xyz
www.EdwardL.xyz

高级进阶-关于_config.yml的设置

下面是我的blog配置

# Hexo Configuration
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: Edward_L's Blog
subtitle: 活着就是为了折腾
description:
author: Edward_L
email: linzhexi777@gmail.com
language:

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://edward-l.github.io/
root: /
permalink: :year/:month/:day/:title/
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
permalink_defaults:

# Directory
source_dir: source
public_dir: public

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
highlight:
  enable: true
  line_number: true
  tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Archives
## 2: Enable pagination
## 1: Disable pagination
## 0: Fully Disable
archive: 1
category: 2
tag: 2

# Server
## Hexo uses Connect as a server
## You can customize the logger format as defined in
## http://www.senchalabs.org/connect/logger.html
port: 4000
server_ip: localhost
logger: false
logger_format: dev

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: MMM D YYYY
time_format: H:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 0
pagination_dir: page

# Disqus
disqus_shortname: 

# Extensions
## Plugins: https://github.com/hexojs/hexo/wiki/Plugins
## Themes: https://github.com/hexojs/hexo/wiki/Themes
theme: landscape-plus
exclude_generator:

# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
  type: git
  repository: https://github.com/Edward-L/Edward-L.github.io.git
  branch: master 

下面是我主题的_config.yml的配置文件

# Header
menu:
  Home: /
  Archives: /archives
  #rss: /atom.xml
  About me: /about-me

# Content
excerpt_link: Read More
fancybox: flase

# Sidebar
sidebar: right
widgets:
- category
- tag
- tagcloud
- archive
- recent_posts
- links

# Links
links:
  Old_Blog_Diandian : http://linzhexi.diandian.com/

# Miscellaneous
google_analytics: UA-56285224-2
favicon: /favicon.png
twitter:
google_plus:
fb_admins: 
fb_app_id:

# Duoshuo
duoshuo_shortname: edward7l

# Baidu share
baidushare: true

问题和解决

1.在安装各种东西的时候遇到报错,请首先考虑是否以管理员的权限运行。
2.hexo 2.x和3.x有一个区别,2.x 的blog的_config中deploy的type是github,而在3.x中要把type改成git,并运行

npm install hexo-deployer-git