爲了更好的閱讀體驗,歡迎閱讀原文。原文連接在此。css
Part 1: Using Github Pages and Hexo to manage personal blogs.html
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.node
create a new repo in github, name by username
.github.io: kezunlin.github.io
jquery
Setting | Automatic Page Generator, choose a theame and deploy.git
sudo apt-get -y install nodejs
sudo apt-get -y install nodejs-legacy
sudo apt-get -y install npm
node -v
npm -v
複製代碼
# 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
複製代碼
cat hello.js
console.log('Hello World');
node hello.js
Hello World
複製代碼
# 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)github
# cnpm install
sudo cnpm install hexo-cli -g
# check version
hexo -v
複製代碼
cd workspace
mkdir blog
cd blog
hexo init
#npm install
hexo generate
hexo server
複製代碼
now we can visit localhost:4000 and create posts.web
vim blog/_config.yml
chrome
deploy:
type: git
repo: git@github.com:kezunlin/kezunlin.github.io.git
branch: master
複製代碼
generate ssh-key and copy to github
npm
# 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 kezunlin.github.io/vim
add README.md
to source folder
edit blog/_config.yml
to skip render README.md
skip_render:
- README.md
複製代碼
use hexo generate
to copy README.md
from source/ to public/
hexo new 'first post'
vim source/_posts/first-post.md
hexo generate
hexo server
hexo deploy
複製代碼
now we can visit kezunlin.github.io/ and see our first post.
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
複製代碼
---
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-->
Use static blog framework Hexo to manage site
-----------------------------------------------
複製代碼
cd blog
git clone https://github.com/iissnan/hexo-theme-next themes/next
複製代碼
vim blog/_config.yml
#theme: landscape
theme: next
複製代碼
edit blog\themes\next\_config.yml
avatar: /images/avatar.jpg
複製代碼
install plugin by
npm install <plugin-name> --save
複製代碼
cnpm install --save hexo-admin
複製代碼
now we can visit http://localhost:4000/admin/
npm install hexo-deployer-git --save
hexo deploy
複製代碼
npm install hexo-generator-feed --save
# visit http://localhost:4000/atom.xml
複製代碼
npm install hexo-generator-sitemap --save
複製代碼
vim blog/_config.yml
sitemap:
path: sitemap.xml
複製代碼
now we can visit http://localhost:4000/sitemap.xml
npm install hexo-generator-baidu-sitemap --save
複製代碼
vim blog/_config.yml
baidusitemap:
path: baidusitemap.xml
複製代碼
now we can visit http://localhost:4000/baidusitemap.xml
cnpm install hexo-abbrlink --save
複製代碼
edit blog\_config.yml
permalink: post/:abbrlink/
abbrlink:
alg: crc32 # crc16(default) and crc32
rep: hex # dec(default) and hex
複製代碼
will fill abbrlink
in your post.md
---
title: Hello World
categories:
- tutorial
tags:
- hexo
abbrlink: 4a17b156
date: 2017-12-26 17:20:10
---
複製代碼
npm install hexo-generator-index --save
npm install hexo-generator-archive --save
npm install hexo-generator-category --save
npm install hexo-generator-tag --save
複製代碼
hexo new page "tags"
# generate source/tags/index.md
複製代碼
edit source/tags/index.md
---
title: tags
date: 2017-12-27 15:46:09
type: "tags"
---
複製代碼
now we can visit http://localhost:4000/tags/
hexo new page "categories"
# generate source/categories/index.md
複製代碼
edit source/categories/index.md
---
title: categories
date: 2017-12-27 15:46:03
type: "categories"
---
複製代碼
now we can visit http://localhost:4000/categories/
install search plugin
cnpm install hexo-generator-search --save
cnpm install hexo-generator-searchdb --save
複製代碼
edit themes\next\_config.yml
local_search:
enable: true # create a new 'Search' button next to 'Archives'
# if auto, trigger search by changing input
# if manual, trigger search by pressing enter key or search button
trigger: auto
# show top n results per article, show all results by setting to -1
top_n_per_article: 1
edit `_config.yml`
search:
path: search.xml
field: post
format: html
limit: 10000
複製代碼
#!/bin/bash
cnpm install hexo-deployer-git --save
cnpm install hexo-generator-feed --save
cnpm install hexo-generator-sitemap --save
cnpm install hexo-generator-baidu-sitemap --save
cnpm install hexo-generator-index --save
cnpm install hexo-generator-archive --save
cnpm install hexo-generator-category --save
cnpm install hexo-generator-tag --save
cnpm install hexo-generator-search --save
cnpm install hexo-generator-searchdb --save
複製代碼
![image here](http://images2017.cnblogs.com/.../123.png)
複製代碼
username.github.io
username
vim blog/_config.yml
deploy:
type: git
repo:
github: git@github.com:<username>/<username>.github.io.git,master
coding: git@git.coding.net:<username>/<username>.git,master
複製代碼
get ips by
dig kezunlin.github.io +noall +answer
複製代碼
we get
185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
複製代碼
steps:
kezunlin.me
from Godaddy.com
kezunlin.me
to github blog's blog\source\CNAME
fileCloudFlare.com
and add A
record with github page IP 185.199.109.153
and get dns nameservers dina.ns.cloudflare.com
and paul.ns.cloudflare.com
dina.ns.cloudflare.com
and paul.ns.cloudflare.com
from herewait for some seconds and we get results from CloudFlare
kezunlin.me
Status: Active
This website is active on Cloudflare.
Universal SSL Status Active Certificate
複製代碼
Active
means nameservers take effect.
configure
Crypto | Always use HTTPS
Page Rules| 2 rules for Always use HTTPS
複製代碼
godaddy
: kezunlin.me
kezunlin.me
to dnspod and get dnspod nameservers.https://dcc.godaddy.com/manage/kezunlin.me/dns#divDnsManagement
to add dnspod nameservers.f1g1ns1.dnspod.net
f1g1ns2.dnspod.net
複製代碼
@ CNAME 207.97.227.245 # for github pages
複製代碼
blog/source/CNAME
kezunlin.me
複製代碼
get google-site-verification
from google search console and add to themes/next/layout/_partials/head.swig
<meta name="google-site-verification" content="***" />
複製代碼
get google_analytics
and edit themes\next\_config.yml
google_analytics: UA-***
複製代碼
grep -r Organization .
./themes/next/layout/_macro/post.swig: <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
複製代碼
add logo
for publisher
edit themes\next\_config.yml
and add
logo: /images/logo.png
edit ./themes/next/layout/_macro/post.swig
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="{{ config.title }}">
<img itemprop="logo" src="{{ url_for( theme.logo ) }}" />
#<img itemprop="logo" src="/images/logo.png" />
</span>
複製代碼
get baidu-site-verification
from https://ziyuan.baidu.com/
and add to themes/next/layout/_partials/head.swig
<meta name="baidu-site-verification" content="***" />
複製代碼
get 360-site-verification
from http://zhanzhang.so.com/sitetool/
and add to themes/next/layout/_partials/head.swig
<meta name="360-site-verification" content="***" />
複製代碼
We can use github repo to store blog site's comments in issues
https://kezunlin.me
client ID
and client secret
gitment
in Github for storing comments in issuesblog\themes\next\_config.yml
gitment:
enable: true
mint: true # RECOMMEND, A mint on Gitment, to support count, language and proxy_gateway
count: true # Show comments count in post meta area
lazy: true # Comments lazy loading with a button
cleanly: false # Hide 'Powered by ...' on footer, and more
language: zh-Hans # Force language, or auto switch by theme
github_user: kezunlin # MUST HAVE, Your Github ID
github_repo: gitment # MUST HAVE, The repo you use to store Gitment comments
client_id: <***> # MUST HAVE, Github client id for the Gitment
client_secret: <***> # EITHER this or proxy_gateway, Github access secret token for the Gitment
proxy_gateway: # Address of api proxy, See: https://github.com/aimingoo/intersect
redirect_protocol: # Protocol of redirect_uri with force_redirect_protocol when mint enabled
複製代碼
Notice
hexo deploy
to deploy blogsInitialize Comment
register jiathis and get uid
jiathis
and baidushare
do not support https
fix to support https
cd blog
git clone https://github.com/hrwhisper/baiduShare.git
mv baiduShare source
#rm -rf baiduShare
# make sure we can access localhost:4000/baiduShare/static/api/js/share.js
# edit baidushare.swig
grep -r 'bdimg.share.baidu.com' .
vim ./themes/next/layout/_partials/share/baidushare.swig
# change //bdimg.share.baidu.com/ to /baiduShare
<script>
with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='/baiduShare/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>
# there exists a bug in share.js
hexo generate
hexo server
複製代碼
edit blog\themes\next\_config.yml
busuanzi_count:
# count values only if the other configs are false
enable: true
# custom uv span for the whole site
site_uv: true
site_uv_header: <i class="fa fa-user"></i> 訪問人數
site_uv_footer:
# custom pv span for the whole site
site_pv: true
site_pv_header: <i class="fa fa-eye"></i> 總訪問量
site_pv_footer:
# custom pv span for one page only
page_pv: true
page_pv_header: <i class="fa fa-eye"></i> 閱讀次數
page_pv_footer:
複製代碼
npm install hexo-all-minifier --save
複製代碼
edit blog\_config.yml
all_minifier: true
複製代碼
Tips: not enable minifier currently because not stable.
npm install hexo-neat --save
複製代碼
edit blog\_config.yml
# hexo-neat
neat_enable: true
neat_html:
enable: true
exclude:
neat_css:
enable: true
exclude:
- '*.min.css'
neat_js:
enable: true
mangle: true
output:
compress:
exclude:
- '*.min.js'
複製代碼
edit themes/next/layout/_partials/head.swig
<meta name="referrer" content="no-referrer" />
複製代碼
deploy to coding.net
.
vim themes/next/layout/_partials/footer.swig
<p>Hosted by <a href="https://pages.coding.me" style="font-weight: bold">Coding Pages</a></p>
複製代碼
use hexo-neat
or hexo-all-minifier
.
Tips: no use, it may cause longer time to load page.
NOTICE:
We can not use fourth level `####` for header,
otherwise post page will not display properly.
複製代碼
jquery
jquery: https://cdn.jsdelivr.net/jquery/2.1.3/jquery.min.js
複製代碼
gitmint
download gitmint files to themes\next\source\lib
tree gitmint/
gitmint/
├── dist
│ └── gitmint.browser.js
└── style
└── default.css
2 directories, 2 files
複製代碼
edit ./themes/next/layout/_third-party/comments/gitment.swig
#<link rel="stylesheet" href="/lib/gitmint/style/default.css">
#<script src="/lib/gitmint/dist/gitmint.browser.js"></script>
複製代碼
_config.yml
to skip gitmint fileskip_render: # relative to source/ folder
- README.md
- lib/gitmint/dist/*.js
- lib/gitmint/style/*.css
複製代碼
errors:
hexo -v
ERROR Local hexo not found in /home/kezunlin/git/blog
複製代碼
solution:
cd blog
rm node_modules
cnpm install --save
複製代碼