This is the 21st day of my participation in the August More Text Challenge

In order to successfully attract the attention of search engines, we actively generate files for them to crawl. This article describes hexo blog’s approach to creating sitemap.

To generate a Sitemap

Installing a plug-in

Install common sitemap and Baidu Sitemap:

npm install hexo-generator-sitemap --save
npm install hexo-generator-baidu-sitemap --save
Copy the code

Modifying a Configuration File

Modify the site configuration file and add:

plugins: 
  hexo-generator-baidu-sitemap
  hexo-generator-sitemap

baidusitemap:
    path: baidusitemap.xml
sitemap:
    path: sitemap.xml
Copy the code

Verify that the URL and root in the site configuration are correct, and the site map will generate a complete link based on the URL

Optional operation

Modify the Next theme profile to open the site map in the menu field:

menu:
  sitemap: /sitemap.xml || sitemap
Copy the code

Modify themes/next/languages/ zh-hans. yml and add the following fields:

menu:
  sitemap: Site map
Copy the code

Generating an XML file

Generating the Hexo site creates baidusItemap. XML and sitemap.xml files in the public folder

In the browser type www.zywvvd.com/sitemap.xml and www.zywvvd.com/baidusitema. You can now see your site map.

Submit to Google Webmaster

With Sitemap it is easier to be indexed than without, but it is much less efficient than submitting the map to search engines, so we submit the generated map to Google first

Check to see if your site is included in Google

Google search site: domain name:

Add the url

Enter The Google Search Console and log in with the Google account. At this time, we need to select the type of url to add the Search. The domain name we apply for is generally domain level, such as my Zywvvd.com.

To prevent malicious use of this function, we need to verify domain ownership. The default mode is DNS authentication. We use this method:

Add Google TXT to @ resolution of domain name:

Wait a moment and click verify to pass:

Adding a site map

Select a prefixed address:

Select the sitemap and add the sitemap.xml you just generated

You can see that the sitemap is successfully parsed:

Submit to Baidu Webmaster

Domestic or Baidu had better use, we also give the map to Baidu webmaster.

Reference: zhuanlan.zhihu.com/p/100922816

Check to see if the site is included

Baidu search site: domain name can be viewed

Add the url

Baidu submit url entry, with Baidu account login, or the process of adding a website

After adding personal information, come to the first step to enter the website, suggested as WWW prefix:

The second step is to fill in the information according to your personal situation. You can only change it once a month.

The third step is to select the CNAME verification that we are familiar with, and establish the resolution according to the given prefix. The type is CNAME and the value is ziyuan.baidu.com

Click to verify:

Submit baidu search in different ways

Baidu provides automatic submission and manual submission. Automatic submission is divided into active push, automatic push and Sitemap. The following is the official explanation:

  • Active push: the fastest way to submit, it is recommended that you immediately push the new output links of the site to Baidu through this way, to ensure that the new links can be timely included by Baidu
  • Automatic push: it is a lightweight link submission component that places the JS code automatically pushed in the source code of each page of the site. When the page is visited, the page link will be automatically pushed to Baidu, which is conducive to the faster discovery of the new page by Baidu
  • Sitemap: You can periodically put website links into Sitemap and then submit sitemap to Baidu. Baidu will periodically grab and check the sitemap you submit and process the links in it, but the inclusion speed is slower than active push
  • Manual submission: If you do not want to submit through the program, then you can use this way, manually submit the link to Baidu

Comparison of the four submission methods:

Take the initiative to push

Installing a plug-in

Install plug-in:

npm install hexo-baidu-url-submit --save
Copy the code

Configure the site profile

Add:


baidu_url_submit:
  count: 1              # Submit the latest number of links
  host: www.zywvvd.com    # Domain name added in Baidu webmaster platform
  token: YQlkVp*******      # the secret key
  path: baidu_urls.txt   The address of the text document in which the new link will be saved
Copy the code

The token can be found in [link submission] – [automatic submission] – [active push]. The token= XXXXX is your token

Add new deployer:

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
- type: git
  repo: [email protected]:zywvvd/zywvvd.github.io.git
  branch: master
- type: baidu_url_submitter  
Copy the code

Push the url

Each time after that, Hexo D would push the latest URL to Baidu, with the following logo:

{"remain":2997,"success":1}
Copy the code

That’s one successful tweet, and I have 2,997 tweets today.

Automatic push

Add the following code to the site:

{% if theme.baidu_push %}
<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> {% endif %}Copy the code

This code is integrated in the Next theme. In 7.7.1, the code is in themes/ Next /layout/_third-party/ bidu-pusher. Swig.

# Enable baidu push so that the blog will push the url to baidu automatically which is very helpful for SEO.
baidu_push: true
Copy the code

Submit a Sitemap

Select the search service’s link to submit:

Just add our sitemap link to autosubmit – sitemap: