環(huán)境配置
安裝homebrew
安裝git和node
brew install git
brew install node //node中已經(jīng)包含npm
cd到博客根目錄,安裝hexo命令行工具h(yuǎn)exo-cli
npm install hexo-cli -g
cd到博客根目錄,初始化hexo
hexo init
安裝Hexo主題,以edinburgh為例
$ git clone https://github.com/sharvaridesai/hexo-theme-edinburgh themes/edinburgh
修改_config.yml文件中關(guān)于主題的配置
update your blog's main _config.yml to set the theme to edinburgh:
# Extensions
## Plugins: http://hexo.io/plugins/
## Themes: http://hexo.io/themes/
theme: edinburgh
新建一篇文章
hexo new post "post_name"
根據(jù)當(dāng)前目錄下文件生成靜態(tài)網(wǎng)頁(yè)
hexo g //g == generate
啟動(dòng)本地服務(wù)器預(yù)覽
localhost:4000
在Mac terminal下按ctrl+C結(jié)束
hexo s //s == server
創(chuàng)建User Pages倉(cāng)庫(kù)
URL for User Pages
1、每一個(gè)Github賬戶只能有一個(gè)User Pages,主要用來(lái)展示一個(gè)賬戶中最最重要的項(xiàng)目
2、命名為username.github.io的repo中的內(nèi)容將會(huì)出現(xiàn)在username.github.io上
3、Repository Name的格式必須為:username.github.io
然后根據(jù)提示一直下一步即可
部署到GitHub
cd到博客根目錄,安裝插件
npm install hexo-deployer-git --save
注:其他插件根據(jù)需要,可自行安裝
安裝其他依賴:npm install
更新
_config.yml
,進(jìn)行如下修改
hexo clean #清空public文件夾下生成的靜態(tài)文件和db.json文件
hexo generate #重新生成靜態(tài)文件和db.json
hexo deploy #或者h(yuǎn)exo d,按照配置文件_config.yml發(fā)布到 github pages 服務(wù)器上
目錄結(jié)構(gòu)
.
├── .deploy #需要部署的文件
├── node_modules #Hexo插件
├── public #生成的靜態(tài)網(wǎng)頁(yè)文件
├── scaffolds #模板
├── source #博客正文和其他源文件,404、favicon、CNAME 都應(yīng)該放在這里
| ├── _drafts #草稿
| └── _posts #文章
├── themes #主題
├── _config.yml #全局配置文件
└── package.json
全局配置 _config.yml
# Hexo Configuration
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site #站點(diǎn)信息
title: #標(biāo)題
subtitle: #副標(biāo)題
description: #站點(diǎn)描述,給搜索引擎看的
author: #作者
email: #電子郵箱
language: zh-CN #語(yǔ)言
# URL #鏈接格式
url: #網(wǎng)址
root: / #根目錄
permalink: :year/:month/:day/:title/ #文章的鏈接格式
tag_dir: tags #標(biāo)簽?zāi)夸?archive_dir: archives #存檔目錄
category_dir: categories #分類目錄
code_dir: downloads/code
permalink_defaults:
# Directory #目錄
source_dir: source #源文件目錄
public_dir: public #生成的網(wǎng)頁(yè)文件目錄
# Writing #寫(xiě)作
new_post_name: :title.md #新文章標(biāo)題
default_layout: post #默認(rèn)的模板,包括 post、page、photo、draft(文章、頁(yè)面、照片、草稿)
titlecase: false #標(biāo)題轉(zhuǎn)換成大寫(xiě)
external_link: true #在新選項(xiàng)卡中打開(kāi)連接
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
highlight: #語(yǔ)法高亮
enable: true #是否啟用
line_number: true #顯示行號(hào)
tab_replace:
# Category & Tag #分類和標(biāo)簽
default_category: uncategorized #默認(rèn)分類
category_map:
tag_map:
# Archives
2: 開(kāi)啟分頁(yè)
1: 禁用分頁(yè)
0: 全部禁用
archive: 2
category: 2
tag: 2
# Server #本地服務(wù)器
port: 4000 #端口號(hào)
server_ip: localhost #IP 地址
logger: false
logger_format: dev
# Date / Time format #日期時(shí)間格式
date_format: YYYY-MM-DD #參考http://momentjs.com/docs/#/displaying/format/
time_format: H:mm:ss
# Pagination #分頁(yè)
per_page: 10 #每頁(yè)文章數(shù),設(shè)置成 0 禁用分頁(yè)
pagination_dir: page
# Disqus #Disqus評(píng)論,替換為多說(shuō)
disqus_shortname:
# Extensions #拓展插件
theme: landscape-plus #主題
exclude_generator:
plugins: #插件,例如生成 RSS 和站點(diǎn)地圖的
- hexo-generator-feed
- hexo-generator-sitemap
# Deployment #部署,將 lmintlcx 改成用戶名
deploy:
type: git
repo: github創(chuàng)庫(kù)地址.git
branch: master
Hexo命令行使用
常用命令:
hexo help #查看幫助
hexo init #初始化一個(gè)目錄
hexo new "postName" #新建文章
hexo new page "pageName" #新建頁(yè)面
hexo generate #生成網(wǎng)頁(yè),可以在 public 目錄查看整個(gè)網(wǎng)站的文件
hexo server #本地預(yù)覽,'Ctrl+C'關(guān)閉
hexo deploy #部署.deploy目錄
hexo clean #清除緩存,強(qiáng)烈建議每次執(zhí)行命令前先清理緩存,每次部署前先刪除 .deploy 文件夾
簡(jiǎn)寫(xiě):
hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy