What is the use of sitemap file? How to use?

What is sitemap

sitemap, the site address file, is usually named sitemap.xml.

What is the use of sitemap?

Sitemap is very friendly to search engines. If new files are generated on your website, using sitemap can allow search engines to quickly include them, which is the most commonly used method for website SEO.

8dfaf01afd2c40f6ac61338de8ac7d31

How is the sitemap file generated?

Sitemap files can be generated by tool software, and there are also websites that provide paid services for online generation.

Today, we are programming to generate the sitemap.xml file ourselves.

Of course, you first need to understand the format of the sitemap file.

Domestically, the most authoritative one is Baidu. We also submit sitemaps to it. The sitemap file format given by Baidu is as follows:

6d43b155e3bb4beb9a29f7330244da67

According to this introduction, we use NodeJS coding as follows:

f42951a57c1b4c42b15614da74c77be7

var sitemap_data = ""; var fs = require ("fs"); // Page directory fs.readdir ("./ article /", function (error, files) {// Sitemap fixed format, coding setting 
    sitemap_data = sitemap_data + '<? xml version = "1.0" encoding = "utf-8"?>' + "\ r \ n"; 
    sitemap_data = sitemap_data + '<urlset>' + "\ r \ n"; // Get each The article, and write it as a limited format 
    for (i = 0; i <files.length; i ++) { 
        sitemap_data = sitemap_data + '<url>' + "\ r \ n"; 
        sitemap_data = sitemap_data + '<loc>' + " Change to url address here "+ files [i] + '</ loc>' +" \ r \ n "; 
        sitemap_data = sitemap_data + '<lastmod> 2020-04-12 </ lastmod>' +" \ r \ n ";
        sitemap_data = sitemap_data + '</url>' + "\r\n";
    }
    
    sitemap_data = sitemap_data + '</urlset>';     
    // Write in sitemap.xml format
    fs.writeFileSync("sitemap.xml",sitemap_data);
})

Run, generate sitemap.xml file as follows:

5d51c0b892954956a7f82161fbf70ec5

Submit sitemap

Submit to your website:

e648568f74144838bd46dba58a027e9c

Then go to Baidu webmaster platform and submit to Baidu:

de3aad73ebbb40a9998349f4dd10226e

In this way, Baidu Crawler will quickly crawl related files to complete the collection. Then, naturally, the file can be searched.

Original articles, unlimited reprint. Welcome to share learning, everyone progress together.


Guess you like

Origin blog.51cto.com/14237227/2486657