Git搭建個人博客
很多人都有寫博客的習慣,所以我這篇博客就講解一下如何在git上搭建一個個人的博客。
環境
搭建個人博客需要配置配置一下環境,這裏我是使用win10來搭建的,因爲像這種配置或者搭建東西,一般都是win系統比較麻煩,在mac和linux相對簡單一點。
一、git
需要在系統裏面安裝git。
具體的安裝步驟可以參考安裝git
二、安裝node.js
使用node.js來搭建相對比較方便,因爲node.js中的npm安裝模塊和框架比較方便,
具體的安裝步驟可以自己百度。
三、安裝hexo框架
hexo框架可以說是比較流行的博客框架,安裝直接
npm install hexo-cli -g
npm install hexo -g
第一步:創建倉庫。
第一步首先要在git中創建倉庫
這裏注意:Repository name 一般都是 username.github.io
然後就是點擊create repository就可以創建倉庫了。
第二步:配置hexo
首先要初始化一個博客,你要先創建創建一個hexo的文件夾,一般都是在github文件夾的目錄下面打開終端,初始化hexo
hexo init
在hexo框架裏面是可以自己選擇主題,具體有什麼主題可以去hexo官網去查看hexo官網
安裝主題
git clone https://github.com/iissnan/hexo-theme-next themes/next
然後再對hexo進行基礎的配置,在剛纔新建的hexo文件夾下面一個文件_config.yml
#博客名稱
title: 我的博客
#副標題
subtitle: 一天進步一點
#簡介
description: 記錄生活點滴
#博客作者(請修改)
author: John Doe
#博客語言
language: zh-Fans
#時區
timezone:
#博客地址,與申請的GitHub一致(請修改)
url: http://elfwalk.github.io
root: /
#博客鏈接格式
permalink: :year/:month/:day/:title/
permalink_defaults:
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:
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
auto_detect: true
tab_replace:
default_category: uncategorized
category_map:
tag_map:
#日期格式
date_format: YYYY-MM-DD
time_format: HH:mm:ss
#分頁,每頁文章數量
per_page: 5
pagination_dir: page
#博客主題
theme: landscape
#發佈設置
deploy:
type: git
#elfwalk改爲你的github用戶名(請修改)
repository: https://github.com/elfwalk/elfwalk.github.io.git
branch: master
在對git進行配置
在win10是一定需要這一步的,否則就會報錯
git config --global user.name “你的用戶名”
git config --global user.email “你註冊git的郵箱”
測試hexo
在終端裏面輸入
hexo g
hexo s
然後打開網址 http://localhost:4000
然後就是可以看到了自己的個人博客了,但是這樣還沒完
部署到git
安裝自動化部署工具
npm instal lhexo-deployer-git --save
然後在hexo文件夾下面的Git Bash中部署
hexo clean && hexo g && hexo d
然後在瀏覽器上輸入https://wwwxiaoming.github.io/
wwwxiaoming是你git的名字。
這樣就可以看到自己發佈的博客了。