Hexo+Github build personal blog (2) – Configuration & Theme
hrwhisper
Baidu shares a solution that does not support HTTPS
Next

** Note: ** the following problem may not have occurred to you. I encountered it while working with the Next theme.

Do the basic configuration

Please refer to my previous post on Hexo+Github building personal blog (ii) – Configuration & Theme about Baidu sharing integration, and do the basic configuration first.

1. InSite profileIn, add a fieldbaidushareAnd has a value oftrue

I’m sure you know what a site profile is, but if you don’t see it in my last blog post.

baidushare: true # Baidu share function
Copy the code

In 2.Topic profile, found inbaidushareField to set its presentation

baidushare: 
  type: button Share the way show the button # baidu | slide
Copy the code

After completing the above two steps, when your Baidu share has not yet appeared, open the browser F12 and find a problem that prompts HTTPS to access HTTP resources. Then introduce how to solve baidu share in HTTPS use.

Baidu sharing in HTTPS

The main reason baidu Share doesn’t work is that it requests HTTP resources, a share.js. In this case, we can only think of putting this resource in a non-HTTP directory, or simply put it in our own directory. We can according to the solution provider [hrwhisper] (https://github.com/hrwhisper/baiduSh) are in accordance with his blog baidu share does not support HTTPS solution to do it, when a problem to go back to my blog, or you can do as I said directly.

  • Download the resource file and place it in the directory of your blog.

Github address: github.com/hrwhisper/b… I want to emphasize here that in the site configuration file, there is a source_dir field. This is the root directory from which you access the resource. For example, if I put a test.jpg file in sourc, the path to access it is /test.jpg

source_dir: source
Copy the code

Static decompress and drop it in the root directory of the site. Then modify the code in baidushare, I use the Next theme, this code is in the file F:\myblog\themes\ Next \layout_partials\share\baidushare.swing, If you can’t find it, search for baidushare in your theme folder.

.src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)]; Instead of < / script > SRC ='/static/api/js/share.js? v=89860593.js? cdnversion='+~(-new Date()/36e5)]; </script>Copy the code

Then restart the service and see if Baidu sharing appears. If so, congratulations, success. If not, please continue to read.

  • If you want to set the skip_render field in the configuration file of the site, you will find that the share. Js file has been successfully loaded, but the file fails. You go to ***F:\myblog.deploy_git\static\ API \js(mine because I put myblog under F:\myblog)***, open the share.js file and find that the end of the file is not fully loaded, Static \ API \js\share. Js: static\ API \js\share.

It turns out that Hexo renders all the files under /source

There are two ways to solve this problem: you can set the skip_rende field in the site configuration file to make hexo skip all files under static when rendering.

skip_rende: static/**

Skip_render: test/*
Skip_render: test/*.md
Skip_render: test/**
# multiple folders:
#skip_render:
# test1/*.html # Note the space in front of it, which stands under skip_render
# test2/**
Copy the code

You can also choose not to set this property and place the static file in the source directory of the theme file. Mine is (F: myblog\themes\next\source). After doing this, your Baidu share should already appear on your blog, Just Enjoy It. (PS: In addition to the above solutions to baidu’s use of HTTPS, there is another method is to use CDN. For specific methods, please refer to the skillful use of the image function of Quniu CDN to make Baidu share support HTTPS. One more word about the problem that JiaThis cannot support HTTPS. Personally, I think it can also be solved in the above way. You can study this by yourself. (PS Plus: That’s all for now.)