首页 技术 正文
技术 2022年11月17日
0 收藏 480 点赞 3,780 浏览 12247 个字

为了更好的阅读体验,欢迎阅读原文。原文链接在此。

Part 1: Using Github Pages and Hexo to manage personal blogs.

Series

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

  1. create a new repo in github, name by username.github.io: kezunlin.github.io

  2. 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 bloghexo init
#npm install
hexo generate
hexo server

now we can visit localhost:https://www.shuzhiduo.com/A/gVdn7XQNzW/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

  1. add README.md to source folder

  2. edit blog/_config.yml to skip render README.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.mdhexo 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:https://www.shuzhiduo.com/A/gVdn7XQNzW/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:https://www.shuzhiduo.com/A/gVdn7XQNzW/4000/atom.xml

sitemap

npm install hexo-generator-sitemap --save

vim blog/_config.yml

sitemap:
path: sitemap.xml

now we can visit http://localhost:4000/sitemap.xml

baidu sitemap

npm install hexo-generator-baidu-sitemap --save

vim blog/_config.yml

baidusitemap:
path: baidusitemap.xml

now we can visit http://localhost:4000/baidusitemap.xml

perment link

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
---

index/archive/category/tag

npm install hexo-generator-index --save
npm install hexo-generator-archive --save
npm install hexo-generator-category --save
npm install hexo-generator-tag --save

tags list page

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/

categories list page

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/

local search

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: 1edit `_config.yml` search:
path: search.xml
field: post
format: html
limit: 10000

install_hexo_plugins.sh

#!/bin/bashcnpm install hexo-deployer-git --savecnpm install hexo-generator-feed --savecnpm install hexo-generator-sitemap --save
cnpm install hexo-generator-baidu-sitemap --savecnpm install hexo-generator-index --save
cnpm install hexo-generator-archive --save
cnpm install hexo-generator-category --save
cnpm install hexo-generator-tag --savecnpm install hexo-generator-search --save
cnpm install hexo-generator-searchdb --save

Upload images to cnblog

  1. install img-uploader chrome extension by here
  2. upload image and get url.
  3. use url in markdown.
![image here](http://images2017.cnblogs.com/.../123.png)

Multiple deploy

  • deploy to github.com: username.github.io
  • deploy to coding.net (gitcaffe): 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

Advanced

custom domain and https

  • blog: Github pages
  • SSL:CloudFlare
  • domain: Godaddy (dns nameservers from CloudFlare)

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
  • A: point to 185.199.109.153
  • CNAME: point to kezunlin.me

steps:

  1. get kezunlin.me from Godaddy.com
  2. add kezunlin.me to github blog’s blog\source\CNAME file
  3. register CloudFlare.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
  4. add dns nameservers dina.ns.cloudflare.com and paul.ns.cloudflare.com from here

wait for some seconds and we get results from CloudFlare

kezunlin.me
Status: ActiveThis 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

custom domain

  1. register domin in godaddy: kezunlin.me
  2. add kezunlin.me to dnspod and get dnspod nameservers.
  3. visit https://dcc.godaddy.com/manage/kezunlin.me/dns#divDnsManagement to add dnspod nameservers.
f1g1ns1.dnspod.net
f1g1ns2.dnspod.net
  1. add CNAME records in dnspod
    @ CNAME 207.97.227.245  # for github pages
  1. vim blog/source/CNAME
kezunlin.me

google analytics

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-***

google structured-data

  1. grep search for keywords
    grep -r Organization .
./themes/next/layout/_macro/post.swig: <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">

add logo for publisher

  1. edit themes\next\_config.yml and add

    logo: /images/logo.png

  2. 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>

baidu zhanzhang

get baidu-site-verification from https://ziyuan.baidu.com/ and add to themes/next/layout/_partials/head.swig

<meta name="baidu-site-verification" content="***" />

360 zhanzhang

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="***" />

gitment for comment

We can use github repo to store blog site’s comments in issues

register OAuth Application

  1. visit https://github.com/settings/applications/new
  2. fill in blanks, callback URL: https://kezunlin.me
  3. get client ID and client secret

gitment config

  1. create a new repo named gitment in Github for storing comments in issues
  2. edit blog\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

  • github_user: kezunlin
  • github_repo: gitment

init page comment

  1. hexo deploy to deploy blogs
  2. visit page and click button Initialize Comment
  3. post your first comment.

share

jiathis

register jiathis and get uid

jiathis and baidushare do not support https

baidushare (RE)

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:https://www.shuzhiduo.com/A/gVdn7XQNzW/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

stats

busuanzi

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:

hexo-all-minifier (not)

npm install hexo-all-minifier --save

edit blog\_config.yml

    all_minifier: true

Tips: not enable minifier currently because not stable.

hexo-neat

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'

403 error

edit themes/next/layout/_partials/head.swig

<meta name="referrer" content="no-referrer" />

optimize for speed

multiple deploy

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>

compress

use hexo-neat or hexo-all-minifier.

Tips: no use, it may cause longer time to load page.

cdn

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

  1. download gitmint files to themes\next\source\lib

     tree gitmint/
    gitmint/
    ├── dist
    │ └── gitmint.browser.js
    └── style
    └── default.css 2 directories, 2 files
  2. 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>
  1. edit _config.yml to skip gitmint file
    skip_render: # relative to source/ folder
- README.md
- lib/gitmint/dist/*.js
- lib/gitmint/style/*.css

faq

errors:

hexo -v
ERROR Local hexo not found in /home/kezunlin/git/blog

solution:

cd blog
rm node_modules
cnpm install --save

Reference

History

  • 2017/12/26: created.
  • 2017/12/27: add Appendix,use next theame,add tags/categories page.
  • 2017/12/28: add Advanced, use gitment,baidushare,local search,etc.
  • 2018/01/02: upload images to cnblogs.
  • 2018/01/03: hexo-neat to compress,cdn,etc.
  • 2018/01/22: add part2.
  • 2018/09/05: add ssl.
  • 2019/11/07: reorganize post contents.

Copyright

微信扫一扫

支付宝扫一扫

本文网址:https://www.zhankr.net/105330.html

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:875 阅读:5,070
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:806 阅读:3,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:565 阅读:4,316
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:730 阅读:4,310
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:4,910
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:3,098
发表评论
暂无评论

还没有评论呢,快来抢沙发~

助力内容变现

将您的收入提升到一个新的水平

点击联系客服

在线时间:8:00-16:00

客服电话

400-888-8888

客服邮箱

ceotheme@ceo.com

扫描二维码

关注微信公众号

扫描二维码

手机访问本站