使用hexo在Github上搭建blog

前言
安裝hexo前需要先檢查電腦是否安裝了node、npm、git。
在命令行工具中,分別輸入一下命令:

node -v
npm -v
git --version

hexo簡(jiǎn)介

[hexo][1]是一個(gè)基于node.js的靜態(tài)博客程序,可以方便的生成靜態(tài)網(wǎng)頁(yè)并托管到github上。
[1]: https://hexo.io

hexo安裝

npm install hexo -g #-g表示全局安裝

hexo使用

hexo init <foider>  #執(zhí)行init命令初始化hexo 到你指定的目錄
hexo generate #自動(dòng)根據(jù)當(dāng)前目錄下的文件,生成靜態(tài)網(wǎng)頁(yè)??梢月詫憺椋篽exo g
hexo server #運(yùn)行本地服務(wù)??梢月詫憺椋篽exo s .在瀏覽器中輸入http://localhost:4000就可以看到效果了
hexo deploy #部署到github上,可以略寫為:hexo d

添加博文

hexo new "postname" #新建博文,其中postname是博文的題目

博文會(huì)自動(dòng)生成在博客目錄下source/_posts/postname.md

#文件自動(dòng)生成格式:
title: "It Starts with iGaze: Visual Attention Driven Networkingwith Smart Glasses"  #博文題目
date: 2014-11-21 11:25:38      #生成時(shí)間
tags: Paper                    #標(biāo)簽, 多個(gè)標(biāo)簽使用格式[Paper1, Paper2, Paper3,...]
---

如果想實(shí)現(xiàn)博客內(nèi)容在首頁(yè)顯示一部分,并出現(xiàn)閱讀全文按鈕效果,則需要下首頁(yè)顯示內(nèi)容下添加

此處及以上的內(nèi)容會(huì)在首頁(yè)顯示
<!--more-->
以下內(nèi)容在首頁(yè)隱藏

根目錄下的_config.yml文件設(shè)置

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

# Site
title:    #博客名
subtitle:   #博客副標(biāo)題
description:          #網(wǎng)站描述, 用于爬蟲(chóng)抓取的關(guān)鍵詞
author:     #作者名稱
email:   #作者郵箱
language: zh-CN       #網(wǎng)頁(yè)編碼,中文

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://andrewliu.tk   #用于綁定域名, 其他的不需要配置
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, 設(shè)置生成博文的默認(rèn)格式,不修改
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
#Archives 默認(rèn)值為2,修改為1,Archives頁(yè)面就只會(huì)列出標(biāo)題,而非全文
## 2: Enable pagination
## 1: Disable pagination
## 0: Fully Disable
archive: 1
category: 1
tag: 1

# Server服務(wù)器設(shè)置, 不修改
## 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 分頁(yè), 設(shè)置每頁(yè)顯示多少篇博文
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Disqus  disqus評(píng)論,  與多說(shuō)類似, 國(guó)內(nèi)一般使用多說(shuō)
disqus_shortname: 

# Extensions
## Plugins: https://github.com/hexojs/hexo/wiki/Plugins
## Themes: https://github.com/hexojs/hexo/wiki/Themes
theme: yilia    #主題設(shè)置
exclude_generator:

# Deployment  站點(diǎn)部署到github要配置這里, 非常重要
## Docs: http://hexo.io/docs/deployment.html
deploy:
  type: github    #部署類型, 本文使用Github
  repository: git@github.com:niumew/niumew.github.io.git  #部署的倉(cāng)庫(kù)的SSH
  branch: master   #部署分支,一般使用master主分支
plugins: 
- hexo-generator-feed   #此插件用于RSS訂閱, 以后有時(shí)間再介紹

在本地設(shè)置好之后,就可以使用 hexo d 部署到github上,然后就可以使用 github用戶名.github.io 訪問(wèn)了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容