-此教程不僅面向計算機專業(yè)的同學(xué)茁肠,任何想搭建個人獨立博客的同學(xué)单寂,都可以來看看-
--By Y.R.H
前言
接上文看靠,經(jīng)過Windows下一步步搭建自己的獨立博客——使用 GitHub Pages + Hexo 基礎(chǔ)教程(二)的學(xué)習(xí)摔桦,相信大家都已經(jīng)將自己的個人域名和 GitHub Pages 搭建好的個人博客綁定起來了端朵,但是好芭,我們還是沒有發(fā)表一篇博文,連個人博客的設(shè)置都還是默認值冲呢,這可不是我們想要的舍败,所以,教程(三)將向大家介紹一下 Hexo 中的 _config.yml 配置文件,以及如何發(fā)表博文邻薯。
配置文件 _config.yml
個人博客配置一共用到兩個文件裙戏,一個是對整站的配置 Hexo(hexo 根目錄下)\ _config.yml,另一個是對主題的配置 Hexo\themes\xxx(主題名)\ _config.yml厕诡,我們來分別介紹累榜。
整站配置文件 Hexo \ _config.yml
該配置文件位于我們使用 hexo init 命令時的目錄下,如圖:
用文本編輯器打開后如圖(作者使用的是 Sublime Text 3):
接下來就來詳細的說一下這些都是做什么用的(可能與大家的有些許出入灵嫌,不存在的項就為默認值):
# Hexo Configuration
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site 基本配置
title: Coooooooooder_Y # 個人博客標(biāo)題(反映在網(wǎng)站左上角)
subtitle: 楊睿涵 個人博客 # 個人博客副標(biāo)題
description: This is a Personal Blog for Y.R.H # 個人博客的描述
author: Yang R.H. # 個人博客作者
language: zh-CN # 個人博客使用語言(默認為 English 信柿,簡體用 zh-CN ,繁體用 zh-TW)
email: coderyrh9236@gmail.com # 個人博客作者的聯(lián)系郵箱
# # URL #這項可以不配置醒第,綁定域名后渔嚷,欲創(chuàng)建sitemap.xml需要配置該項
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://www.yangruihan.com # 綁定的域名
root: / # 是否為根目錄顯示該博客,如過稠曼,你想使用 www.xxx.com/blog 來顯示博客 這項需要改成 /blog
permalink: :year/:month/:day/:title/
permalink_defaults:
# 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 文章布局形病、風(fēng)格,無需修改
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
future: true
highlight:
enable: true
line_number: true
tab_replace:
# Category & Tag
default_category: uncategorized
category_map:
tag_map:
# Archives 默認值為2霞幅,這里都修改為1漠吻,相應(yīng)界面就只會列出標(biāo)題,而非全文
## 2: Enable pagination
## 1: Disable pagination
## 0: Fully Disable
archives: 1
category: 1
tag: 1
# 日期格式無需修改
# 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 # 每頁顯示的文章數(shù)量
## Set per_page to 0 to disable pagination
per_page: 15
pagination_dir: page
# Disqus # 社會化評論 默認為disqus司恳,我這里換成了“多說”
# disqus_shortname: yangruihan
# 多說社會化評論
duoshuo_shortname: yangruihan
# Extensions # 個人博客使用的主題途乃,可以自行更換
## Plugins: http://hexo.io/plugins/
## Themes: http://hexo.io/themes/
theme: jacman
# Deployment # 個人博客部署到 GitHub
## Docs: http://hexo.io/docs/deployment.html
deploy:
type: git
repo: https://github.com/yangruihan/yangruihan.github.io.git
branch: master
message:
# Extensions # 使用的插件
Plugins:
- hexo-generator-feed
- hexo-generator-sitemap
# 插件配置
#Feed Atom
feed:
type: atom
path: atom.xml
limit: 20
#sitemap
sitemap:
path: sitemap.xml
大家可以根據(jù)自己的需要進行相應(yīng)的更改。
提示:如果還有什么不太明白扔傅,可以看 Hexo 官網(wǎng) 的說明
主題配置文件 Hexo\themes\xxx\_config.yml
小提示:由于主題的不同耍共,配置文件也或多或少有些區(qū)別,不過英文好的同學(xué)肯定能看懂每項的意思猎塞,大家可以試著改一改试读,然后在本地跑起來,可以直接看到效果荠耽。
該配置文件位于我們的 Hexo\themes\xxx\ 的目錄下钩骇,如圖:
用文本編輯器打開后如圖:
這里只介紹通用的一些選項:
##### Menu # 個人博客右上角顯示的導(dǎo)航欄,默認為英文(Home: /)可以手動改成中文
menu:
首頁: /
文章列表: /archives
關(guān)于: /about
## you can create `tags` and `categories` folders in `../source`.
## And create a `index.md` file in each of them.
## set `front-matter`as
## layout: tags (or categories)
## title: tags (or categories)
## ---
#### Widgets # 個人博客右邊欄
widgets:
- category
- tag
- links
- douban
- rss
## provide seven widgets:category,tag,rss,archive,tagcloud,links,weibo,douban
#### RSS
rss: /atom.xml # rss 源添加
#### Image # 網(wǎng)站用到的圖片資源索引
imglogo:
enable: false ## display image logo true/false.
src: img/logo.png ## `.svg` and `.png` are recommended,please put image into the theme folder `/jacman/source/img`.
favicon: img/favicon.ico ## size:32px*32px,`.ico` is recommended,please put image into the theme folder `/jacman/source/img`.
apple_icon: img/jacman.jpg ## size:114px*114px,please put image into the theme folder `/jacman/source/img`.
author_img: img/author.jpg ## size:220px*220px.display author avatar picture.if don't want to display,please don't set this.
banner_img: img/banner.jpg ## size:1920px*200px+. Banner Picture
### Theme Color
theme_color:
theme: '#4682b4' ##the defaut theme color is blue
#### index post is expanding or not
index: # 文章索引
expand: false # 文章在首頁是否展開 ## default is unexpanding,so you can only see the short description of each post.
excerpt_link: 閱讀全文 #
close_aside: false #close sidebar in post page if true
#### Author information
author: # 作者的信息
intro_line1: "Hello ,I'm Yangruihan." # 介紹作者的話 ## your introduction on the bottom of the page
intro_line2: "This is my blog, keep studying everyday." # 同上 ## the 2nd line
weibo: 3767425381 #微博號 ## e.g. wuchong1014 or 2176287895 for http://weibo.com/2176287895
weibo_verifier: # 微博show ## e.g. b3593ceb Your weibo-show widget verifier ,if you use weibo-show it is needed.
tsina: 3767425381 # 微博分享 ## e.g. 2176287895 Your weibo ID,It will be used in share button.
douban: # 豆瓣 ## e.g. wuchong1014 or your id for https://www.douban.com/people/wuchong1014
zhihu: yang-rui-han-68 # 知乎 ## e.g. jark for http://www.zhihu.com/people/jark
email: coderyrh9236@gmail.com # 郵箱 ## e.g. imjark@gmail.com
twitter: # twitter ## e.g. jarkwu for https://twitter.com/jarkwu
github: yangruihan # github 主頁 ## e.g. wuchong for https://github.com/wuchong
facebook: ## e.g. imjark for https://facebook.com/imjark
linkedin: ## e.g. wuchong1014 for https://www.linkedin.com/in/wuchong1014
google_plus: ## e.g. "111190881341800841449" for https://plus.google.com/u/0/111190881341800841449, the "" is needed!
stackoverflow: ## e.g. 3222790 for http://stackoverflow.com/users/3222790/jark
## if you set them, the corresponding share button will show on the footer
#### Links 個人博客底邊欄的鏈接
links:
我的GitHub: https://github.com/yangruihan,楊睿涵的個人GitHub
我的微博: http://weibo.com/3767425381,楊睿涵的個人新浪微博
我的知乎: http://www.zhihu.com/people/yang-rui-han-68,楊睿涵的個人知乎
配置文件就介紹到這里铝量。
發(fā)表博文
廢了這么半天功夫搭建了一個個人博客倘屹,最重要的當(dāng)然是寫博客啦。
新建博文
新建博文有兩種方法
方法一:使用命令新建一篇博文
使用 Git Shell 進入 Hexo 文件夾慢叨,輸入一下命令:
$ hexo new "文章題目"
當(dāng)出現(xiàn)如下圖提示時纽匙,表示新博文已經(jīng)創(chuàng)建完畢:
這時會發(fā)現(xiàn)在 Hexo\source\_posts 目錄中多了一個文件,如圖:
用文本編輯器打開后插爹,如下圖:
這里系統(tǒng)不會創(chuàng)建博文分類哄辣,如果想加上文章的類型请梢,可以在 “___” 上面自己加上一個標(biāo)簽:
categories: xxx # 文章文類
到此一篇新博文就創(chuàng)建成功了赠尾。
方法二:直接在文件夾中創(chuàng)建
直接進入目錄 Hexo\source\_posts 目錄中力穗,右鍵新建一個文本文檔,將名字改為 博文名.md 气嫁,用文本編輯器打開自行加上所需標(biāo)簽即可:
title: "測試博文"
date: 2015-03-23 19:33:59
tags:
---
寫博文
博文內(nèi)容寫在 "___" 后面当窗,如圖:
因為 Hexo 是支持 markdown 語法的,所以我們也要使用 markdown 來書寫博文寸宵,千萬不要覺得 markdown 像是 C崖面、C++、Java 這樣的編程語言梯影,又難學(xué)巫员,又難理解,markdown 的語法很簡單甲棍,但是功能十分強大简识,排版什么的分分鐘搞定,一旦你學(xué)會使用感猛,只剩下一句話七扰,根本停不下來!
由于篇幅原因這里就不詳細介紹 markdown 語法了陪白,請移步以下網(wǎng)站颈走,也可以自行搜索一下 markdown 語法:
獻給寫作者的 Markdown 新手指南
markdown專題
發(fā)博文
博文寫完后,還是在 Git Shell 中進入 Hexo 文件夾中使用那幾條命令咱士,將網(wǎng)頁自動生成并部署到 GitHub上:
$ hexo clean
$ hexo generate
(若要本地預(yù)覽就先執(zhí)行 hexo server)
$ hexo deploy
刷新個人博客網(wǎng)頁立由,就可以看到新鮮出爐的博文了,趕緊邀請小伙伴們來欣賞吧序厉。
補充
快捷命令方式
hexo g == hexo generate
hexo d == hexo deploy
hexo s == hexo server
hexo n == hexo new
# 還能組合使用拆吆,如:
hexo d -g
如何在博文中插圖
首先,注冊一個圖床賬號
本人使用的是七牛云存儲(如果有什么更好的推薦脂矫,請留言)枣耀,體驗用戶免費1G空間,認證免費用戶10G空間庭再,已經(jīng)足夠日常使用了捞奕,并且很穩(wěn)定。
將自己需要插入博文的圖片上傳到云空間拄轻,如圖:
在博文中輸入 ![](填寫剛才復(fù)制的地址) 颅围,就把圖片成功插入了
推薦使用 簡書 markdown 預(yù)覽編輯模式,可以實時看到自己寫到效果
如圖:
使用步驟:
P.S:如果發(fā)現(xiàn)文章中有明顯的錯誤和問題請在下面留言或者聯(lián)系本人恨搓,本人將及時改正院促,避免給大家?guī)聿槐匾恼`導(dǎo)筏养,謝謝~