This is the 5th day of my participation in the August More Text Challenge

All about Hexo — My Hexo column

Zero foreword

SEO is Search Engine Optimization.

It is a way to use search engine rules to improve the site’s natural ranking within the relevant search engines.

Following on from domain binding, in this article we will talk about how to find your Hexo blog on Baidu. Because the content is too long, it is divided into two parts, mainly about:

A Solution

Since Baidu cannot crawl GitHub content, we need to find a code hosting platform that baidu can crawl and provide Pages service.

Then we only have two domestic platforms to choose from: Gitee and Coding 🙈

Although these two things cost money, but Gitee custom domain name more than 90 can buy a server, Coding is free for the first six months, after a month may be a few cents (if few people visit), it is a natural choice of Coding platform.

In addition, we can use Github + Coding dual deployment, domestic IP access to domestic Coding address, foreign IP access to Github address, of course, we can bother to only Coding.

Coding website

After registering, create a Git project and select web hosting in continuous Deployment (see the Help center for details).

The second deployment

  1. To deploy your blog to both repositories, add your project address to the root directory configuration file _config.yml:

     deploy:
     - type: git
       repository: [email protected]:username/username.github.io.git
       branch: master
     ​
     # Your coding project address
     - type: git
       repository: [email protected]:username/username.git
       branch: master
       
     # note that the two usernames may be different
    Copy the code
  2. Then go to the domain console, configure two CNAME resolution, enter your Coding project address in Baidu, enter your github. IO address in default:

  3. Also bind your domain name under the Coding site Settings.

  4. Then test whether Baidu can crawl to your website and type in the command line:

    The curl - A "Mozilla / 5.0 (compatible; Baiduspider / 2.0; + http://www.baidu.com/search/spider.html) "- o example. HTML your domain nameCopy the code
  5. In the command line directory, a file example.html is generated:

Baidu Included

  1. It is impossible to search baidu after the site is just built. We can search site: your domain name and submit the website to Baidu:

  2. After submission, click Add Website in Baidu Site Management, enter the domain name, and use CNAME to verify the website in the last step:

  3. Add the above records to domain name console resolution:

  4. Validation is complete and successful.

Four push resources

The last step we successfully let Baidu know the existence of the website, but Baidu does not know the content on our website, so to Baidu included push our content.

There are four methods: API submission, active push, Sitemap, automatic push, and manual submission.

Because manual submission is to copy and paste all the links in your blog into this interface for submission, I won’t go into details here.

API to submit

  1. Find the line in this screen and run the command as prompted:

  2. Success is returned after execution.

Take the initiative to push

  1. NPM install hexo-bidu-url-submit –save

  2. Open the site profile and add at the end:

     # add in the deploy TAB
     deploy:
     - type: baidu_url_submitter
     ​
     # Baidu actively push plug-ins
     baidu_url_submit:
       count: 80             # submit the latest link
       host: www.heeh.xyz    Your domain name
       token: xxxxxxx        
       path: baidu_urls.txt  The address of the text document in which the new link will be saved
    Copy the code
  3. Where the token is obtained in the previous API submission:

  4. The new link will be automatically pushed each time the hexo d is executed.

sitemap

  1. Install plug-in:

     npm install hexo-generator-sitemap --save 
     npm install hexo-generator-baidu-sitemap --save
    Copy the code
  2. After installation, hexo CL and hexo G-d will generate sitemap. XML (for other search engines) and baidusItemap. XML (for Baidu) files in the public directory.

  3. Once you have the baidusItemap. XML file, go to this screen and submit:

  1. After submission, the web page will show success status.

Automatic push

  1. Some topics support automatic push of Baidu search, which can be modified in the theme profile, such as matery:

     # Baidu search resource platform to submit links
     baiduPush: true
    Copy the code
  2. If not, add it to every HTML page that needs to be crawled by Baidu:

     <script>
     (function(){
         var bp = document.createElement('script');
         var curProtocol = window.location.protocol.split(':') [0];
         if (curProtocol === 'https') {
             bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
         }
         else {
             bp.src = 'http://push.zhanzhang.baidu.com/push.js';
         }
         var s = document.getElementsByTagName("script") [0]; s.parentNode.insertBefore(bp, s); }) (); </script>Copy the code

V. Sum up

In general, the automatic method is a little better and more efficient than the manual method.

  • Automatic way of active push is the fastest one, every day output of new links can be pushed to Baidu collection through this way.
  • Automatic push is the most convenient, when the deployment code page is visited will be automatically pushed to Baidu included.
  • Sitemap submission, Baidu will periodically grab check, so the inclusion speed is the slowest.

So in general I recommend active + automatic use together.

More practical content will be updated in the next post


More interesting articles: Mancuoj’s homepage – Articles – Nuggets (juejin. Cn)