ap-sitemap

1.1.0 • Public • Published

ap-sitemap

SiteMapGenerator is a Node.js module for generating sitemaps in XML format. It allows you to easily manage URLs and create sitemap files that comply with the sitemap protocol.

Installation

To use SiteMapGenerator, first install it via npm:

npm install ap-sitemap

Usage

create instance

const SiteMapGenerator = require('ap-sitemap');

const sitemap = new SiteMapGenerator({
  baseUrl: 'https://example.com',  // change with your website domain extension
  outDir: 'sitemaps', // default is build
  limit: 50000, // default is 50000
  removeIndexExtension: true, // remove /index.html or any extension from url
});

Add Pages

Use the addPages method to add pages to the sitemap. You need to pass an array of page objects, where each object contains url, updatedAt, changefreq, and priority.

sitemap.addPages([
  {
    url: 'https://example.com/page1',
    updatedAt: '2024-11-04T10:00:00Z',
    changefreq: 'daily',
    priority: 1.0,
  },
  {
    url: 'https://example.com/page2',
    updatedAt: '2024-11-03T10:00:00Z',
    changefreq: 'weekly',
    priority: 0.8,
  },
]);

Generate Sitemap

Once you've added all your pages, you can generate the sitemap(s) by calling the generate method:

const result = sitemap.generate();

// The result will contain both the sitemap URL and a message
console.log(result.sitemapLink); // Example output: 'https://example.com/sitemap.xml'
console.log(result.message);    // Example output: 'sitemap.xml generated successfully.'

Readme

Keywords

Package Sidebar

Install

npm i ap-sitemap

Weekly Downloads

2

Version

1.1.0

License

ISC

Unpacked Size

10.3 kB

Total Files

5

Last publish

Collaborators

  • amanpareek