您的位置:首页 > 编程语言

Hexo结合Github创建静态博客

2016-08-05 15:48 621 查看


环境部署

安装node.js,地址为:http://nodejs.org/download/
安装git,地址为:http://git-scm.com/download/
安装hexo,cmd中运行
$ npm install -g hexo

github上申请账号,并且创建仓库,仓库的名字必须为:你的账户名.github.io


创建hexo项目


首先初始化文件目录

$ hexo init


安装所需文件

$ npm install


运行文件

$ hexo server
浏览器输入localhost:4000,你就可以在本地查看到新建的项目。


创建新的文章

$ hexo new "文章题目"
进入路径 项目\source_posts\中手动编译文章页面,使用markdown模式。


部署到github上

在配置文件中(项目_config.yml)修改数据
# Deployment
## Docs: http://hexo.io/docs/deployment.html deploy:
type: github
repository: git@github.com:你的账户名/你的账户名.github.io.git
branch: master


或者
# Deployment
## Docs: http://hexo.io/docs/deployment.html deploy:
type: git
repository: https://github.com/你的账户名/你的账户名.github.com.git branch: master


然后执行命令

hexo clean
清除旧的内容

hexo g
或者
hexo
generate
生成新的内容

hexo d
或者
hexo
deploy
部署上传


查看成果

等一分钟,你就可以通过http://你的账户名.github.io/来访问你新创建的静态博客了。


配置文件介绍

# Hexo Configuration
## Docs: http://zespia.tw/hexo/docs/configure.html ## Source: https://github.com/tommy351/hexo/ 
# Site 这里的配置,哪项配置反映在哪里,可以参考我的博客
title: Zippera's blog #站点名,站点左上角
subtitle: Walk steps step by step #副标题,站点左上角
description: Walk steps step by step #给搜索引擎看的,对站点的描述,可以自定义
author: zippera #在站点左下角可以看到
email: #你的联系邮箱
language: zh-CN #中文显示

# URL #这项暂不配置,绑定域名后,欲创建sitemap.xml需要配置该项
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://zipperary.com root: /
permalink: :year/:month/:day/:title/
tag_dir: tags
archive_dir: archives
category_dir: categories

# Writing 文章布局、写作格式的定义,不修改
new_post_name: :title.md # File name of new posts
default_layout: post
auto_spacing: false # Add spaces between asian characters and western characters
titlecase: false # Transform title into titlecase
max_open_file: 100
filename_case: 0
highlight:
enable: true
backtick_code_block: true
line_number: true
tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Archives 默认值为2,这里都修改为1,相应页面就只会列出标题,而非全文
## 2: Enable pagination
## 1: Disable pagination
## 0: Fully Disable
archive: 1
category: 1
tag: 1

# 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
logger: false
logger_format:

# 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: 10
pagination_dir: page

# 多说评论插件
duoshuo_shortname:

#主题
## Plugins: http://hexo.io/plugins/ ## Themes: http://hexo.io/themes/ theme: light
exclude_generator:
plugins:
- hexo-generator-feed
- hexo-generator-sitemap

# Deployment 站点部署到github要配置,上一节中已经讲过
## Docs: http://zespia.tw/hexo/docs/deploy.html deploy:
type: github
repository: https://github.com/你的用户名/你的用户名.github.io.git branch: master


更换主题

hexo有很多的主题,你可以去网上下载,而且都有各种教程,每个主题都有自己的说明文档,能够更好的定制化你自己的博客网站,我所使用的是next主题。具体可以进入 http://theme-next.iissnan.com/ 页面查看。


备份

假如你想要在不同的电脑上写博客,除了都要安装环境外,你可以把项目提交到github上的另外一个仓库,或者该仓库的另外一个分支,每次换电脑都同步一下,非常的方便简单。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  HEXO