配置环境
- Node.js
- Git
- Github
- Hexo
我的建议是首先删除Mac自带的node.js,因为版本太老以免出错,反正我是出错了全部删除重新装的,删除命令如下:
sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
sudo rm /opt/local/bin/node
sudo rm /opt/local/include/node
sudo rm -rf /opt/local/lib/node_modules
删除完毕之后去官网下载node.js地址:https://nodejs.org/ 下载默认安装之后npm自带也同时安装好了
准备好之后我们开始安装hexo,命令如下:
sudo npm install -g hexo
安装好Hexo之后,初始化hexo,在初始化之前切换到你所在的博客目录,命令如下:
cd /Users/edwin/Documents/blog
hexo init
blog目录结构
|
|-- _config.yml 配置文件
|-- db.json
|-- package.json
|-- node_modules
|-- public
|-- source 资源文件(务必保存)
|-- scaffolds
|-- themes
生产静态页面,命令如下:
hexo g
启动本地服务,访问http://localhost:4000 命令如下:
hexo server
配置hexo-deployer-git,命令如下:
npm install hexo-deployer-git --save
修改_config.yml文件,修改内容如下:
可参考官网文档:https://hexo.io/zh-cn/docs/configuration.html
deploy:
type: git
repository: https://github.com/why168/why168.github.io.git
branch: master
在Github上部署blog,命令如下:
执行完毕之后即可访问 https://why168.github.io/
hexo deploy
总结
一些常用命令:
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #将.deploy目录部署到GitHub
hexo help #查看帮助
hexo version #查看Hexo的版本
每次部署的步骤,命令如下:
hexo clean
hexo g -d
我给童鞋们看下我的_config.yml配置文件:
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site
title: Edwin's Blog
subtitle: Edwin's Blog to Android
description: Android,PHP,IOS,JavaScript
author: Edwin
language:
- zh-tw
- en
timezone: Asia/Shanghai
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://github.com/why168
root: /
permalink: :year/:month/:day/:title/:id/:category
permalink_defaults: https://github.com/why168/why168.github.io
# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:
# 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: true # 文章资源文件夹
relative_link: false
future: true
highlight:
enable: true
line_number: true
auto_detect: false
tab_replace:
# Category & Tag
default_category: 未分类
category_map:
tag_map:
# 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: YYYY-MM-DD
time_format: HH:mm:ss
# Pagination
## Set per_page to 0 to disable pagination
per_page: 5
pagination_dir: page
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
user: Edwin.Wu # 使用者名称
port: 22 # 默认值 22
delete: true # 除远程主机上的旧文件 true
verbose: true # 显示调试信息 true
ignore_errors: true # 忽略错误 false
type: git
repository: https://github.com/why168/why168.github.io.git
branch: master
message: 网站更新:{{ now('YYYY-MM-DD HH:mm:ss') }} # 自定义提交信息 (默认为 Site updated: {{ now('YYYY-MM-DD HH:mm:ss') }})