If you are as white as I am, congratulations!

After reading this article, you can have a blog like this too!

preface

  1. Welcome to leave a message at the end of the article, or click to join the QQ group 933583982 to communicate with each other.
  2. This article is licensed under CC BY-NC-SA 4.0.
  3. “Last update” link: www.simon96.online/2018/10/12/…

Blog set up

Prepare the environment

  1. Download node.js and install it. Detailed steps: www.simon96.online/2018/11/10/…

  2. Git download and install. Detailed steps: www.simon96.online/2018/11/10/…

  3. To install Hexo, run the following command on the command line (i.e., Git Bash) :

    npm install -g hexo-cli

  4. To initialize Hexo, run the following commands from the command line (i.e., Git Bash) :

    The following is the site directory where the Hexo initialization file is stored.

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

    These files and folders will be generated under the new path:

    . ├ ─ ─ _config. Yml ├ ─ ─ package. The json ├ ─ ─ scaffolds ├ ─ ─source| ├ ─ ─ _drafts | └ ─ ─ _posts └ ─ ─ themesCopy the code

    Note:

    • The hexo-related commands are all run in the site directory using Git Bash.

    • Site configuration file: _config.yml in the site directory.

      Path for < folder > \ _config yml

    • Theme configuration file: _config.yml in the Themes folder under the site directory.

      Path is

      \themes\< theme folder>\ _config.yml

  5. Start the server. Enter the following command from the command line (i.e. Git Bash) in the directory and run it:

    hexo server

  6. The web address for browser access is http://localhost:4000/

At this point, your Hexo blog is set up locally.

Implementation plan

Solution 1: GithubPages
  1. Create a Github account

  2. Create a repository named <Github account name >.github. IO

  3. Push the local Hexo blog to GithubPages

    3.1. Install the hexo-deployer-Git plug-in. Run the following command from the command line (i.e. Git Bash) :

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

    3.2. Add an SSH Key.

    • Create an SSH key. Enter the following command on the command line (i.e. Git Bash) and press enter three times:

      $ ssh-keygen -t rsa -C "Email address"
      Copy the code
    • Add to Github. Copy the contents of the Key file (for example, C:\Users\Administrator\.ssh\id_rsa.pub) and paste it into the New SSH Key.

    • Check whether the configuration is added successfully. Enter the following commands on the command line (Git Bash) to return “You’ve successfully authenticated” :

      $ ssh -T [email protected]
      $ yes
      Copy the code

    3.3. Modify _config.yml (in the site directory). At the end of the file:

    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
      type: git repo: [email protected]:<Github account name >/<Github account name >.github.ioCopy the code

    Note: The above warehouse address is written as SSH address, not HTTP address.

    3.4. Push to GithubPages. On the command line (Git Bash), run the following commands in sequence to return INFO Deploy done: Git the push is successful:

    $ hexo g
    $ hexo d
    Copy the code
  4. After about one minute, access the url https://github account name >.github

At this point, your Hexo blog is set up on GithubPages at https://

.github. IO.

Solution 2: GithubPages + domain name

Add a custom domain name (the domain name you purchased) based on scenario 1.

  1. Domain name resolution.

    Set the type to CNAME.

    Host record is the prefix of the domain name, enter WWW;

    Enter the record value as the user-defined domain name.

    Parse the line, TTL default.

  2. Warehouse Settings.

    2.1. Open the blog repository Settings: https://github.com/

    /

    .github

    2.2. Under Custom Domain, enter a Custom domain name and click Save.

    2.3. In the source folder of the site directory, create and open cname. TXT, write your domain name (such as www.simon96.online), save and rename it CNAME.

  3. Wait about 10 minutes.

    Browser access custom domain name.

    At this point, your Hexo blog has resolved to the custom domain name, and https://

    .github. IO is still available.

Solution 3: GithubPages + CodingPages + domain name

GithubPages is slower in China and not included by Baidu, while CodingPages is faster abroad. Therefore, on the basis of plan 2, add CodingPages.

  1. Create a Coding account

  2. Create a repository named <Coding account name >

  3. Enter the “Code” page in the project, click “one click to open static Pages”, wait for a moment, CodingPages can be deployed successfully.

  4. Push the local Hexo blog to CodingPages

    4.1. The public key was already generated when GithubPages was created. You can directly copy the contents of the key file (for example, C:\Users\Administrator\.ssh\id_rsa.pub) and paste it into the new public key.

    4.2. Test whether the configuration is added successfully. Enter the following commands on the command line (Git Bash) to return “You’ve successfully authenticated” :

    $ ssh -T [email protected]
    $ yes
    Copy the code

    4.3. Modify _config.yml (in the path where the Hexo initialization file is stored). At the end of the file:

    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    - type: git repo: [email protected]:<Github account name >/<Github account name >.github.iotype: git repo: [email protected]:<Coding account name >/<Coding account name >Copy the code

    4.4. Push to GithubPages. On the command line (Git Bash), run the following commands in sequence to return INFO Deploy done: Git the push is successful:

    $ hexo g
    $ hexo d
    Copy the code
  5. Domain name resolution

    1. Add CNAME record pointing to <Coding account name >.coding.me

      Set the type to CNAME.

      Host record is the prefix of the domain name, enter WWW;

      Enter the record value as the user-defined domain name.

      Parse the line, TTL default.

    2. Add two A records pointing to 192.30.252.153 and 192.30.252.154

      Select A as the type.

      Host record is the prefix of the domain name. Enter @.

      The record values are 192.30.252.153 and 192.30.252.154.

      Parse lines, foreign or Google.

    3. In the “Pages” service Settings page (https://dev.tencent.com/u/ < Coding account name > / p < > Coding account name/git/Pages/Settings) in binding custom domain name.

At this point, your Hexo blog has resolved to the custom domain name, with https://

.github. IO and https://

.code.me still available.

Solution 4: Cloud server + domain name

This solution requires the purchase of cloud servers and domain names.

  1. Install Git and Nginx on a cloud server. (Git for versioning and deployment, Nginx for static blog hosting.)

    Log in as user root and run:

    $ yum -y update
    $ yum install -y git nginx
    Copy the code
  2. Nginx configuration

    2.1. Create file directory (for storing files of blog site)

    cd /usr/local/
    mkdir hexo
    chmod 775 -R /usr/local/hexo/
    Copy the code

    2.2. Add index. HTML (used to check whether Nginx was successfully configured)

    vim /usr/local/hexo/index.html
    Copy the code

    Add the following code and save.

    
            
    <html>
      <head>
        <title></title>
        <meta charset="UTF-8">
      </head>
      <body>
        <p>Nginx running</p>
      </body>
    </html>
    Copy the code

    2.3. Configure the Nginx server

    vim /etc/nginx/nginx.conf
    Copy the code

    Change server_name and root:

    server {
          listen       80 default_server;
          listen       [::]:80 default_server;
          server_name  www.baidu.com; # Fill in your domain name
          root         /usr/local/hexo/;
      }      
    Copy the code

    2.4. Start the Nginx service.

    service nginx start
    Copy the code

    2.5. If the cloud server browser accesses the personal domain name or IP address, skip to index.html, the configuration is complete; otherwise, check the previous configuration.

  3. Git configuration

    3.1. Create a file directory for setting up a private Git repository, and change the read and write permission of the directory.

    cd /usr/local/
    mkdir hexoRepo
    chmod 775 -R /usr/local/hexoRepo/
    Copy the code

    3.2. Git initializes the bare library.

    cd hexoRepo/
    git init --bare hexo.git
    Copy the code

    Create Git hooks.

    vim /usr/local/hexoRepo/hexo.git/hooks/post-receive
    Copy the code

    3.4. Enter the following information to specify the Git source code and Git configuration file.

    #! /bin/bash
    git --work-tree=/usr/local/hexo --git-dir=/usr/local/hexoRepo/hexo.git checkout -f
    Copy the code

    3.5. After saving and exiting the file, add executable permission to the file.

    chmod +x /usr/local/hexoRepo/hexo.git/hooks/post-receive
    Copy the code
  4. Local blogs are pushed to the cloud server

    4.1. Install the Hexo-deployer-Git plug-in. Run the following command from the command line (i.e. Git Bash) :

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

    4.2. Adding an SSH Key.

    • Create an SSH key. Enter the following command on the command line (i.e. Git Bash) and press enter three times:

      $ ssh-keygen -t rsa -C "Email address"
      Copy the code
    • Add to Github. Copy the contents of the Key file (for example, C:\Users\Administrator\.ssh\id_rsa.pub) and paste it into the New SSH Key.

    • Check whether the configuration is added successfully. Enter the following commands on the command line (Git Bash) to return “You’ve successfully authenticated” :

      $ ssh -T [email protected]
      $ yes
      Copy the code

    4.3. Modify _config.yml (in the site directory). At the end of the file:

    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
      type: git
      repo: [email protected]:/usr/local/hexoRepo/hexo // User name@Domain name or IP address :/usr/local/hexoRepo/hexo
      branch: master
    Copy the code

    Note: The above warehouse address is written as SSH address, not HTTP address.

    4.4. Push to GithubPages. On the command line (Git Bash), run the following commands in sequence to return INFO Deploy done: Git the push is successful:

    $ hexo g
    $ hexo d
    Copy the code
  5. Wait about 1 minute before the browser accesses the personal domain name.

    At this point, your Hexo blog is set up on a cloud server with a personal domain name.

Subject to optimize

Choose a topic

The default theme for Hexo is landscape, and the following themes are recommended:

  1. snippet
  2. Hiero
  3. JSimple
  4. BlueLake

Application of theme

  1. Download the theme
  2. Paste the downloaded theme folder into the site directorythemesUnder.
  3. Change the site configuration file_config.ymlThe theme field for the theme folder name:
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/Theme: < the name of the theme folder >Copy the code

Subject to optimize

Detailed documentation is available for the above topics. This section mainly addresses common issues related to topic optimization.

Theme optimization generally includes:

  • Set “RSS”

  • The Tags page is added

  • The Category page is added

  • Set “Font”

    Problem: Slow to reference foreign font images.

    Solution: you can use domestic. Change fonts.google.com to fonts.lug.ustc.edu.cn in \themes\*\layout_partials\head external-fonts. Swig.

  • Set the Code Highlighting theme

  • Sidebar social links

    Question: Where can I find the icon?

    Solution: Font Awesome

  • Enable the tipping function

    Problem: Wechat Alipay QR code is not beautiful, different specifications.

    Solution: Generate qr code online

  • Set up a link

  • Tencent Philanthropy 404 page

  • Site establishment time

  • Subscribe to wechat official account

  • Set “Animation”

    Problem: Slow, wait until the JavaScript script has fully loaded before displaying the content. Solution: Turn off animation by setting the use_motion field value to false in the theme configuration file _config.yml.

  • Set “Background Animation”

Theme optimization also includes:

Add background

Add the following code in themes/*/source/ CSS /_custom/custom.styl:

body{
    background:url(/images/bg.jpg);
    background-size:cover;
    background-repeat:no-repeat;
    background-attachment:fixed;
    background-position:center;
}
Copy the code
Modifying the Logo Font

Add the following code in themes/*/source/ CSS /_custom/custom.styl:

@font-face { font-family: Zitiming; src: url('/fonts/Zitiming.ttf'); } .site-title { font-size: 40px ! important; font-family: 'Zitiming' ! important; }Copy the code

The font file is in the themes/next/source/fonts directory, there is a.gitkeep hidden file, open and write the font file you want to keep, like mine is Zitiming. TTF, the specific font library can be downloaded from the Internet.

Changes the width of the content area

Edit the source/ CSS /_variables/custom.styl file for the theme and add the following variables:

$content-desktop = 700px; $content-desktop = 900px when the window exceeds 1600pxCopy the code
Site title bar background color
.site-meta { background: $blue; // Change to your favorite color}Copy the code
Custom mouse styles

Open the themes/*/source/ CSS /_custom/custom.styl and write the following code inside:

Style * {/ / mouse cursor: url (" http://om8u46rmb.bkt.clouddn.com/sword2.ico "), auto! important } :active { cursor: url("http://om8u46rmb.bkt.clouddn.com/sword1.ico"),auto! important }Copy the code
Article encrypted access

Open the themes/*/layout/_partials/head.swig file and insert the code before {% endif %} under {% if theme. Pace %} tag:

< script > (function () {if (' {{page. The password}} ') {if (prompt (" please enter the password). == '{{page. Password}}'){alert(' password error '); history.back(); }}}) (); </script>Copy the code

Add password: * :

---
title: 2018
date: 2018-10-25 16:10:03
password: 123456
---
Copy the code
Click to achieve the heart effect
  1. in/themes/*/source/js/srcI’m gonna go ahead and create a new fileclick.jsAnd then paste the following intoclick.jsFile. The code is as follows:
!function(e,t,a){function n(){c(".heart{width: 10px; height: 10px; position: fixed; background: #f00; transform: rotate(45deg); -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); }.heart:after,.heart:before{content: ''; width: inherit; height: inherit; background: inherit; border-radius: 50%; -webkit-border-radius: 50%; -moz-border-radius: 50%; position: fixed; }.heart:after{top: -5px; }.heart:before{left: -5px; }"),o(),r()}function r() {for(var e=0; e<d.length; e++)d[e].alpha<=0? (t.body.removeChild(d[e].el),d.splice(e,1)):(d[e].y--,d[e].scale+=.004,d[e].alpha-=.013,d[e].el.style.cssText="left:"+d[e].x+"px; top:"+d[e].y+"px; opacity:"+d[e].alpha+"; transform:scale("+d[e].scale+","+d[e].scale+") rotate(45deg); background:"+d[e].color+"; z-index:99999"); requestAnimationFrame(r)}function o(){var t="function"==typeof e.onclick&&e.onclick; e.onclick=function(e){t&&t(),i(e)}}function i(e){var a=t.createElement("div"); a.className="heart",d.push({el:a,x:e.clientX-5,y:e.clientY-5,scale:1,alpha:1,color:s()}),t.body.appendChild(a)}function c(e){var a=t.createElement("style"); a.type="text/css"; try{a.appendChild(t.createTextNode(e))}catch(t){a.styleSheet.cssText=e}t.getElementsByTagName("head")[0].appendChild(a)}function s() {return"rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"}var d=[]; e.requestAnimationFrame=function() {returne.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msReques tAnimationFrame||function(e){setTimeout(e,1e3/60)}}(),n()}(window,document);

Copy the code
  1. in\themes\*\layout\_layout.swigAdd:
<! <script > <scripttype="text/javascript" src="/js/src/clicklove.js"></script>

Copy the code
Static resource compression

In the site directory:

$ npm install gulp -g
Copy the code

To install the Gulp plug-in:

npm install gulp-minify-css --save
npm install gulp-uglify --save
npm install gulp-htmlmin --save
npm install gulp-htmlclean --save
npm install gulp-imagemin --save
Copy the code

Create a gulpfile.js file under the Hexo site. The file contents are as follows:

var gulp = require('gulp'); var minifycss = require('gulp-minify-css'); var uglify = require('gulp-uglify'); var htmlmin = require('gulp-htmlmin'); var htmlclean = require('gulp-htmlclean'); var imagemin = require('gulp-imagemin'); Gulp.task ('minify- CSS ', function() { return gulp.src('./public/**/*.css') .pipe(minifycss()) .pipe(gulp.dest('./public')); }); Gulp.task ('minify- HTML ', function() { return gulp.src('./public/**/*.html') .pipe(htmlclean()) .pipe(htmlmin({ removeComments: true, minifyJS: true, minifyCSS: true, minifyURLs: true, })) .pipe(gulp.dest('./public')) }); Gulp. Task ('minify-js', function() { return gulp.src(['./public/**/.js','!./public/js/**/*min.js']) .pipe(uglify()) .pipe(gulp.dest('./public')); }); Gulp.task ('minify-images', function() { gulp.src('./public/demo/**/*.*') .pipe(imagemin({ optimizationLevel: 5, // Type: Number Default: 3 Value range: 0-7 (optimization level) Progressive: true, // Type: Boolean Default: false Lossless compression JPG image Interlaced: False, // Type: Boolean Default: false Interlaced scan GIF for rendering multipass: False, // Type: Boolean Default: false Optimize SVG several times until it is fully optimized}). Pipe (gulp.dest('./public/uploads')); }); // Default gulp.task('default', ['minify-html','minify-css','minify-js','minify-images']);Copy the code

To compress static resources, run the gulp command after generate. After the compression is complete, run the deploy command to synchronize the compression to the server:

hexo g
gulp
hexo d
Copy the code
Change the access URL path

The default URL is domain/2018/10/18/ About this site, change to domain/About/ About this site. Edit the _config.yml file under the Hexo site and change the permalink field:

permalink: :category/:title/
Copy the code
Post top
  1. Installing a plug-in

    npm install hexo-generator-index-pin-top –save

Then add top to the front-matter of the article:

---
title: 2018
date: 2018-10-25 16:10:03
top: 10
---

Copy the code
  1. Set the top sign

Open: /themes/*/layout/_macro/post.swig and go to

, insert the following code:

      {% if post.top %}
        <i class="fa fa-thumb-tack"Word-wrap: break-word! Important; ">< span style =" font-size: 14px"post-meta-divider">|</span>
      {% endif %}

Copy the code
Fork me on Github in the upper right or left corner
  1. Select the style GitHub Ribbons,
  2. Modify the image jump link that will<a href="https://github.com/you">Replace the Github link with your own:
  3. Open thethemes/next/layout/_layout.swigFile, copy the code to<div class="headband"></div>The following.
Added a border shadow effect to the main page article

Themes /*/source/ CSS /_custom/custom.styl

Margin-top: 0px; margin-top: 0px; margin-bottom: 60px; padding: 25px; -webkit-box-shadow: 0 0 5px rgba(202, 203, 203, .5); -moz-box-shadow: 0 0 5px rgba(202, 203, 204, .5); }Copy the code
The current browsing progress is displayed

Change themes/*/_config.yml from false to true:

# Back to top in sidebar
b2t: true

# Scroll percent label in b2t button
scrollpercent: true
Copy the code
Create category page

In the terminal window, go to the Hexo site directory and create:

$CD < site directory > $hexo new Page CategoriesCopy the code
Join the advertising

There are two main types: Baidu SSP and Google Adsense. The methods are similar:

  1. Sign up and copy the AD code

  2. Deploy to the web site.

    Create a new theme/*/layout/_custom/google_ad.swig and paste the code from AdSense into it

    2.2. The head. Paste a copy in theme/*/layout/_custom/head.swig

    2.3. Every blog. In theme/*/layout/post.swig, add:

    {% include '_custom/google_ad.swig' %}
    
    Copy the code

    {% block content %}
      <div id="posts" class="posts-expand">
        {{ post_template.render(page) }}
        {% include '_custom/google_ad.swig' %}
      </div>
    {% endblock %}
    
    Copy the code
  3. Wait for the approval. If you fail, you can reapply.

Add a lovely
  1. Installing a plug-in

    npm install --save hexo-helper-live2d
    
    Copy the code
  2. Copy your favorite model name:

    Epsilon2.1

    Gantzert_Felixander

    haru

    miku

    ni-j

    nico

    nietzche

    nipsilon

    nito

    shizuku

    tsumiki

    wanko

    z16

    hibiki

    koharu

    haruto

    Unitychan

    tororo

    hijiki

  3. Add the following code to the theme configuration file _config.yml and change < your preferred model name > :

    live2d:
      enable: true
      scriptFrom: local
      pluginRootPath: live2dw/
      pluginJsPath: lib/
      pluginModelPath: assets/
      tagMode: false
      log: falseModel: use: live2D-widget-model -< you like model name > display: position: right width: 150 height: 300true
    
    Copy the code
  4. Creating a configuration file

    4.1. Create the live2D_Models folder in the site directory,

    4.2. Create a folder under live2d_Models < Name of your favorite model >,

    4.3. Create a json file under < Your favorite model name >.model.json

  5. Install the model. Run the following command from the command line (i.e. Git Bash) :

    NPM install — Save live2D-widget-model — < name of your favorite model >

  6. Run the following command on the command line (i.e., Git Bash) to view the test results at http://127.0.0.1:4000/ :

    hexo clean && hexo g && hexo s

The plug-in configuration

Choose one of the following plug-ins (comment system, statistics and analysis, content sharing service, search service).

Review system

Recommend index advantages disadvantages
Valine 4 30,000 reviews per day, 10GB of storage Author comments are not identified
Will force/in livere 4 Login with multiple accounts Comments cannot be exported
News soufangwang 3 beautiful Domain name must be registered
gitment 3 concise You can only comment on Github
Disqus 1 Need to get over the wall
Valine

1.1. Obtain the APP ID and APP Key

Log in or register with LeanCloud, go to the console and click in the lower left corner to create an app,

Go to the APP you just created, choose Settings > APP Key in the lower left corner, and you will see your APP ID and APP Key.

1.2. Enter the APP ID and APP Key into the theme configuration file _config.yml

1.3. Run hexo g&&hexo d to push to the blog.

Will force/in livere

2.1. Login to get your LiveRe UID.

2.2. Fill in the LiveRe UID file to the topic configuration file _config.yml

News soufangwang

3.1. Obtain the APP ID and APP Key

Please log in or sign up for Freetalk, click “Get Freetalk Now”,

To create a new site, go to Manage, go to Comment Plug-in > Comment Management,

Click on background Overview, and you’ll see your APP ID and APP Key.

3.2. Enter the APP ID and APP Key to the theme configuration file _config.yml

3.3. Run hexo g&&hexo d to push to the blog.

gitment

4.1. Plug-in installation:

npm i –save gitment

4.2. Apply for an Application

Apply a key to your blog in the New OAuth App:

This is an Application name that you can use with your Homepage URL. This is an Application name that you can use with Authorization callback URL: This must be your blog addressCopy the code

4.3. The configuration

Edit themes/*/_config.yml:

# Gitment
# Introduction: https://imsun.net/posts/gitment-introduction/
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: false # Comments lazy loading with a button
  cleanly: false # Hide 'Powered by ... ' on footer, and more
  language: # Force language, or auto switch by themeGithub_user: {you github user id} github_repo: public git repository, comments will be the issue of that project client_id: {just requested ClientID} client_secret: {Secret} proxy_gateway:# Address of api proxy, See: https://github.com/aimingoo/intersect
  redirect_protocol: # Protocol of redirect_uri with force_redirect_pro

Copy the code
Disqus

Edit themes/*/_config.yml, set enable under disqus to true, and provide your shortname. Count specifies whether to display the number of comments.

disqus:
  enable: false
  shortname:
  count: true

Copy the code

Data statistics and analysis

Recommend index advantages disadvantages
Garlic no children 4 The number of visits can be directly displayed on your web page (or not displayed) Only count
Baidu statistics 3 Included slow
Garlic no children

Edit the busuanzi_count configuration item in themes/*/_config.yml.

  • whenenable: true“, indicates that the global switch is enabled.
  • ifsite_uv(Number of visitors),site_pv(Number of visitors),page_pv(the total amount of reading) isfalseWhen, the garlic is only recorded and will not be displayed on the page.

Note:

The original domain name "dn-lbatics.qbox.me" (expected to expire in early October 2018) has expired, and the customer service communication several times without any result, even if I proposed to pay for it, I can only change the domain name to "busuanzi.ibruce.info"!Copy the code

The solution:

  1. Find the swiG file in which the theme is called. In “\ * \ layout_third themes – party \ analytics \ busuanzi – counter. Swig.” “

  2. Change the domain name

    Put the original: <script async SRC ="/ / dn - lbstatics. Qbox. Me/busuanzi / 2.3 / busuanzi. Pure. The mini. Js." "Word-wrap: break-word! Important; ">< span style =" max-width: 100%"/ / busuanzi. Ibruce. Info/busuanzi / 2.3 / busuanzi. Pure. The mini. Js." "></script>
    
    Copy the code
Baidu statistics
  1. Log in to Baidu statistics, locate the site to obtain the code page
  2. Copy statistics script ID, as shown in figure:
  3. Edit the topic configuration filethemes/*/_config.yml, modify the fieldgoogle_analytics, the value is set to your statistics script ID.

Content sharing service

Recommend index advantages disadvantages
Baidu’s share 4 stable Not very beautiful
need-more-share2 4 beautiful Updated late (such as wechat sharing API)
Baidu’s share

Edit the theme configuration file and add/modify the field baidushare to true.

# Baidu Sharing service
baidushare: true

Copy the code
need-more-share2

To edit the theme configuration file, add/modify needmoreshare2 and set the value to true.

needmoreshare2:
  enable: true

Copy the code

Search service

Recommend index advantages disadvantages
Local Search 4 Configuration is convenient
Swiftype 2 Need to register
Algolia 2 Need to register
Local Search

Add baidu/Google/local custom site content search

  1. Install hexo-Generator-searchdb and run the following command in the root directory of your site:

    $ npm install hexo-generator-searchdb --save
    
    Copy the code
  2. Edit the site configuration file and add the following content anywhere:

    search:
      path: search.xml
      field: post
      format: html
      limit: 10000
    
    Copy the code
  3. Edit the topic profile to enable local search:

    # Local search
    local_search:
      enable: true
    
    Copy the code

Error analysis

If you run into the same problem with Hexo, here are some solutions to common problems.

YAML Parsing Error

JS-YAML: incomplete explicit mapping pair; a key node is missed at line 18, column 29:
      last_updated: Last updated: %s

Copy the code
  1. If the parameter contains colons, use quotation marks, for exampleLast updated: %s
Js-yaml: Bad indentation of a mapping entry at line 18, column 31: last_updated:"Last updated: %s"

Copy the code
  1. The colon after the field must be the English colon, such as: last_updated:
  2. Field colons must be followed by a space, such as: last_updated: “Last updated: %s”

EMFILE Error

Error: EMFILE, too many open files

Copy the code

When generating a large number of files, you may encounter an EMFILE error.

You can run the following command to increase the number of synchronous I/O operations allowed.

$ ulimit -n 10000

Copy the code

Process Out of Memory

The following error was encountered while hexo g:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

Copy the code

Below, change the first line of the hexo-CLI file to increase the nodeJS heap memory. This bug has been fixed in a new version.

#! /usr/bin/env node --max_old_space_size=8192

Copy the code

Git Deployment Problems

  1. RPC failed
error: RPC failed; result=22, HTTP code = 403

fatal: 'username.github.io' does not appear to be a git repository

Copy the code

Make sure you have git set up correctly on your computer or try using the HTTPS repository URL.

  1. Error: ENOENT: no such file or directory

This requires some git knowledge, because it is possible to write the wrong tag, category, or file name, which causes local and Github conflicts. Git cannot automatically merge this change, so it breaks the automatic branch.

The solution:

  1. Check the tags and categories of your posts to make sure they are the same locally and on Github.
  2. Merge branches (Commit).
  3. Clear, refactor. In the site directory, the command line (that is, Git Bash) runshexo cleanandhexo g
  4. Manually set the site directorypublicFolder copied to your desktop
  5. Switch from your master branch to your local branch.
  6. Copy from desktoppublicFolder to the local branch.
  7. Merge branches on Github (Commit).
  8. Switch back to the master branch.

Server Problems

Error: listen EADDRINUSE

Copy the code

You might use the same port and have two Hexo servers open at the same time. If you want to enable both, you can try to modify the port Settings:

$ hexo server -p 5000

Copy the code

Plugin Installation Problems

npm ERR! node-waf configure build

Copy the code

This error can occur when you try to install a plug-in written in Cc++ or another javascript language. Make sure you have the correct compiler installed on your computer.

Error with DTrace (Mac OS X)

{ [Error: Cannot find module './build/Release/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/default/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/Debug/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }

Copy the code

DTrace installation may have problems, reinstall:

$ npm install hexo --no-optional

Copy the code

See # 1326

Iterate Data Model on Jade or Swig

Hexo uses the warehouse’s data model. This is not an array, so you may need to convert the object to iterable.

{% for post in site.posts.toArray() %}
{% endfor %}

Copy the code

Data Not Updated

Some data cannot be updated or the last version of the newly generated file is exactly the same. Clear the cache and try again:

$ hexo clean

Copy the code

No command is executed

When you cannot use the command line other than help, init, and version (i.e. Git Bash), it is possible to use the package.json file in the site directory without hexo, as follows:

{
  "hexo": {
    "version": "3.2.2"}}Copy the code

Escape Contents

Hexo uses Nunjucks to render pages. {{}} or {% %} will parse and may cause trouble, if you want to appear in a blog post, you must use three quotes:

​```
{% raw %}
Hello {{ sensitive }}
{% endraw %}
​```

Copy the code

ENOSPC Error (Linux)

If running the command $hexo server returns an error:

Error: watch ENOSPC ...

Copy the code

This can be done by running $NPM dedupe or the following command line (Git Bash) :

$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Copy the code

To increase the number of files you can see during the test.

EMPERM Error (Windows Subsystem for Linux)

If running the command $hexo server from Windows Subsystem for Linux returns this error:

Error: watch /path/to/hexo/theme/ EMPERM

Copy the code

Because currently in Windows Subsystem for Linux, some content changes cannot be updated in real time to the Hexo server.

So you need to recompile and restart the server:

$ hexo generate
$ hexo server -s

Copy the code

Template render error

Sometimes running the command $hexo generate returns an error:

FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Template render error: (unknown path)

Copy the code

This means that some unrecognizable words are in your file, and most likely in your new blog post, or in the configuration file _config.yml, such as indenting errors:

Examples of mistakes:

plugins:
hexo-generator-feed
hexo-generator-sitemap

Copy the code

Common operations

To create the article

Command:

$ hexo new [layout] <title>

Copy the code

Parameter description:

  • [layout] can be the following three:
Parameter names function The article path
post The new post source/_posts
page Create a new page (e.g. 404, category) source
draft The draft source/_drafts

A draft can be published with the following command:

$ hexo publish [layout] <title>

Copy the code
  • The title note:

    Not the title of a blog post,

    Is the name of the blog markdown file,

    Link to blog suffix (such as https://www.simon96.online/2018/10/12/hexo-tutorial/ in hexo – tutorial)

The article template

  • Create a template

    When a new article is created, Hexo creates a file based on the corresponding file in the Scaffolds folder, such as:

$ hexo new blog “simon”

When executing this line of instruction, Hexo attempts to find blog.md in the Scaffolds folder and build an article based on its contents.

  • Modify the parameters

    Here are the variables you can use in a template:

variable describe
layout layout
title The title
date File creation date

Front-matter

It’s the section at the top of a blog post separated by –.

The default front-matter can be used:

parameter describe The default value
layout layout
title The title
date Set up the date File creation date
updated Updated date File update date
comments Enable the comment function of the article true
tags Tags (not for pagination)
categories Sorting (not for pagination)
permalink Cover article url

Thank you for support