@letgowebtools/sitemap-generator
This package generates sitemap files with a limit of URLs per file given a list of URL.
Installing
npm install @letgowebteam/sitemap-generator
Usage
Parameter | Type | Purpose |
---|---|---|
sitemapRemoteLocationUrl | string | Root URL where the sitemaps should be hosted. |
outputFilename | string | Prefix filename of index file and the rest of the sitemaps. |
limitByFile | number | Maximum number of URLs in a single sitemap. |
urls | string[] | List of URLs to create the sitemaps from. |
outputDir | string | Destination folder where all the sitemaps are going to be stored. |
Example:
const sitemapGenerator = require('@letgowebtools/sitemap-generator');
(async() => {
const sitemapRemoteLocationUrl = 'https://www.letgo.com';
const outputFilename = 'my_amazing_sitemap';
const limitByFile = 50000;
const urls = [
'https://www.example.com/test_1',
'https://www.example.com/test_2'
];
const outputDir = '/tmp/';
await sitemapGenerator(
sitemapRemoteLocationUrl,
outputFilename,
limitByFile,
urls,
outputDir
);
})();
Will output:
/tmp/my_amazing_sitemap-index.xml.gz
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://www.letgo.com/my_amazing_sitemap-0.xml</loc>
</sitemap>
</sitemapindex>
/tmp/my_amazing_sitemap-0.xml.gz
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>https://www.example.com/test_1</loc>
</url>
<url>
<loc>https://www.example.com/test_2</loc>
</url>
</urlset>