[ubuntu篇] 使用Github Pages 和hexo 建立个人博客,自定义域名,https加密,搜索引擎google,baidu,360收录

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 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.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 :4000/admin/

git deployer npm install hexo-deployer-git --save hexo deploy rss feed npm install hexo-generator-feed --save # visit :4000/atom.xml sitemap npm install hexo-generator-sitemap --save

vim blog/_config.yml

sitemap: path: sitemap.xml

now we can visit :4000/sitemap.xml

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

vim blog/_config.yml

baidusitemap: path: baidusitemap.xml

now we can visit :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 :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 :4000/categories/

local search

install search plugin

cnpm install hexo-generator-search --save cnpm install hexo-generator-searchdb --save

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwxdwx.html