In the case of personal blogs,Blog address

The preparatory work

The installation

$ npm install -g hexo-cli
Copy the code

Initialize the

$ hexo init <folder>
$ cd <folder>
$ npm install
Copy the code

Create a new article

$ hexo new "My New Post"
Copy the code

Running the development environment

$ hexo server
$ hexo s
Copy the code

build

$ hexo generate
$ hexo g
Copy the code

The deployment of

$ hexo deploy
$ hexo d
Copy the code

For detailed preparations, check out hexo’s website

Install the themecactus, a very programmer’s theme, recommend!

Clone the repository and copy the source files to the blog projectthemesdirectory

git clone https://github.com/probberechts/hexo-theme-cactus.git themes/cactus

Copy the code

themes/cactus/_config.ymlFor details about the configuration, see the official documents

# home Projects URL
projects_url: https://github.com/xiaobinwu
Set the page orientation
direction: ltr
# Home navigation
# $hexo new Page about
nav:
  home: /
  about: /about/
  articles: /archives/
  categories: /categories/
  search: /search/
# Social links
social_links:
  github: https://github.com/xiaobinwu
  mail: mailto:[email protected]
# Open TAB shortcut
tags_overview: true
# Number of pieces of Writing displayed on the home page
posts_overview:
  show_all_posts: false
  post_count: 5
  sort_updated: false
# Arrangement mode
archive:
  sort_updated: false
post:
  show_updated: false
# logo set
logo:
  enabled: true
  width: 50
  height: 50
  url: /images/logo.png
  gravatar: false
Set # ico
favicon:
  desktop:
    url: /images/favicon.ico
    gravatar: false
  android:
    url: /images/favicon-192x192.png
    gravatar: false
  apple:
    url: /images/apple-touch-icon.png
    gravatar: false
# highlight syntax
highlight: kimbie.dark
# Blog theme color, Dark, Light, Classic, White
colorscheme: dark
page_width: 48
# set RSS
rss: atom.xml
open_graph:
  fb_app_id:
  fb_admins:
  twitter_id:
  google_plus:
# disqus comments, not enabled by default, need to climb the wall
disqus:
  enabled: false
  shortname: cactus-1
# Google Stats
google_analytics:
  enabled: false
  id: UA-86660611-1
# Baidu statistics
baidu_analytics:
  enabled: false
  id: 2e6da3c375c8a87f5b664cea6d4cb29c

gravatar:
  email: [email protected]

valine:
  enable: true
  app_id: xxxxxx
  app_key: xxxxxxx
Copy the code

Valine comment system

themes/cactus/_config.ymlApp_id and app_key are required to configure Valine

valine:
  enable: true
  app_id: xxxx
  app_key: xxxx
Copy the code

themes/cactus/layout/_partial/comments.ejs, write

The < %if(theme.valine.enable) { %>
    <script src="/ / cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
    <script src='//unpkg.com/valine/dist/Valine.min.js'></script>
    <div id="vcomments" class="blog-post-comments"></div>
    <script>
        new Valine({
            el: '#vcomments',
            visitor: true,
            appId: '<%=theme.valine.app_id %>',
            appKey: '<%=theme.valine.app_key %>',
            placeholder: 'ヾ Blue ≧∀≦) O Come, cheer! ',
            avatar: 'robohash'
        })
    </script>
<% } %>
Copy the code

Automatically deploy Hexo blog to Ali Cloud server

Create a repository (create a Git repository on a remote server) and log in to the cloud server using SSH

mkdir blog.git && cd blog.git
git init --bare
Copy the code

Hexo configuration

deploy:
  type: git
  message: update
  repo: [email protected]:/www/wwwroot/blog.git,master
Copy the code

Plug-in installation

npm install hexo-deployer-git --save
Copy the code

Automatic deployment

Go to the hooks directory in the Git repository and create the hook post-receive

cd /www/wwwroot/blog.git/hooks
touch post-receive
vim post-receive
Copy the code

Enter the following script:

#! /bin/bash -l
GIT_REPO=/www/wwwroot/blog.git
TMP_GIT_CLONE=/www/wwwroot/tmp/blog
PUBLIC_WWW=/www/wwwroot/blog
rm -rf ${TMP_GIT_CLONE}
mkdir ${TMP_GIT_CLONE}
git clone $GIT_REPO $TMP_GIT_CLONE
rm -rf ${PUBLIC_WWW}/*
cp -rf ${TMP_GIT_CLONE}/ *${PUBLIC_WWW}
Copy the code

Change the permissions

chmod +x post-receive
chmod 777 -R /www/wwwroot/blog
chmod 777 -R /www/wwwroot/tmp/blog
Copy the code

The last deployment

$ hexo g -d
Copy the code