为了更好的阅读体验,欢迎阅读原文。原文链接在此。
Part 1: Using Github Pages and Hexo to manage personal blogs.
Series
- Part 1: Using Github Pages and Hexo to manage personal blogs on Ubuntu.
- Part 2: Using Github Pages and Hexo to manage personal blogs on windows.
Hexo Tutorial
Github recommends us to use Jekyll to manage static pages, which is based on Ruby and is difficult for us to install and configure. So we use Hexo instead. Hexo is a static blog framework similar to Jekyll ,which is based on Node.js and easier for use to use.
use Github to create repo
-
create a new repo in github, name by
username
.github.io:kezunlin.github.io
-
Setting | Automatic Page Generator, choose a theame and deploy.
install by apt-get
sudo apt-get -y install nodejs
sudo apt-get -y install nodejs-legacy
sudo apt-get -y install npm
node -v
npm -v
install nodejs from source
# download and compile
wget https://nodejs.org/dist/v8.9.3/node-v8.9.3.tar.gz
tar xzvf node-v8.9.3.tar.gz
cd node-v8.9.3
./configure
make -j8
sudo make install
# link to /usr/bin
sudo ln -s /usr/local/bin/node /usr/bin/node
sudo ln -s /usr/local/bin/npm /usr/bin/npm
# check version
node -v
npm -v
test node
cat hello.js
console.log('Hello World');
node hello.js
Hello World
install hexo
# install hexo globally
sudo npm install hexo-cli -g
#sudo npm install hexo --save
# use cnpm from taobao instead of offical npm, which is slow for chinese users.
sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
use cnpm
instead of npm
(optional)
# cnpm install
sudo cnpm install hexo-cli -g
# check version
hexo -v
create hexo site
cd workspace
mkdir blog
cd blog
hexo init
#npm install
hexo generate
hexo server
now we can visit localhost:4000 and create posts.
deploy to github
vim blog/_config.yml
deploy:
type: git
repo: git@github.com:kezunlin/kezunlin.github.io.git
branch: master
generate ssh-key and copy to github
# generate ssh-key
cd ~
ssh-keygen
cat .ssh/id_rsa.pub
# copy content to github
# https://github.com/settings/keys
# install plungin and deploy to github
npm install hexo-deployer-git --save
hexo deploy
now we can visit https://kezunlin.github.io/
add README and skip render
-
add
README.md
to source folder -
edit
blog/_config.yml
to skip renderREADME.md
skip_render: - README.md
use hexo generate
to copy README.md
from source/ to public/
new post and deploy again
hexo new 'first post'
vim source/_posts/first-post.md
hexo generate
hexo server
hexo deploy
now we can visit https://kezunlin.github.io/ and see our first post.
Appendix
Hexo commands
Hexo common commands:
hexo new "postName" #new post
hexo new page "pageName" #new page
hexo generate #generate static files to public/
hexo server #start server on localhost:4000
hexo deploy #push .deploy_git/ to GitHub
hexo clean #clean files
Hexo short commands:
hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy
Hexo composite commands:
hexo server -g
hexo deploy -g
Post content
header template
---
title: Using Github Pages and Hexo to manage personal blogs
date: 2017-12-26 17:28:10
categories: tutorial
tags:
- github pages
- hexo
- nodejs
- npm
---
more to control web display
<!--more-->
Use static blog framework Hexo to manage site
-----------------------------------------------
Use next theme
cd blog
git clone https://github.com/iissnan/hexo-theme-next themes/next
vim blog/_config.yml
#theme: landscape
theme: next
Avatar
edit blog\themes\next\_config.yml
avatar: /images/avatar.jpg
Plugins
install plugin by
npm install <plugin-name> --save
hexo admin
cnpm install --save hexo-admin
now we can visit http://localhost:4000/admin/
git deployer
npm install hexo-deployer-git --save
hexo deploy
rss feed
npm install hexo-generator-feed --save
# visit http://localhost:4000/atom.xml
sitemap
npm install hexo-generator-sitemap --save
vim blog/_config.yml
sitemap: