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

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

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

  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.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:
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值