Socket
Socket
Sign inDemoInstall

sitemaps

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sitemaps

A simple sitemap.xml generator.


Version published
Weekly downloads
309
increased by91.93%
Maintainers
1
Install size
11.1 kB
Created
Weekly downloads
 

Readme

Source

sitemaps

NPM Build Status

A simple sitemap.xml generator.

Installation

npm i sitemaps --save

Usage

createSitemap()

Generates a sitemap XML file with the custom URLs on the specified path.

import path from 'path';
import { createSitemap } from 'sitemaps';

createSitemap({
  filePath: path.join(__dirname, 'sitemap.xml'),
  urls: [
    {
      loc: 'https://example.com',
      lastmod: '2023-01-31',
      changefreq: 'weekly',
      priority: 1,
    },
    {
      loc: 'https://example.com/about',
      lastmod: '2022-10-21',
      changefreq: 'monthly',
      priority: 0.8,
    },
    {
      loc: 'https://example.com/contact',
      lastmod: '2021-04-30',
      changefreq: 'yearly',
      priority: 0.4,
    },
  ],
});

// The sitemap.xml file will be created in the specified path.
AttributeTypeDescription
locstring (required)URL of the page. This URL must begin with the protocol (such as http). This value must be less than 2,048 characters.
lastmodstring (optional)The date of last modification of the page. This date should be in W3C Datetime format. This format allows you to omit the time portion, if desired, and use YYYY-MM-DD.
changefreqenum (optional)How frequently the page is likely to change. Valid values are always, hourly, daily, weekly, monthly, yearly, and, never.
prioritynumber (optional)The priority of this URL relative to other URLs on your site. Valid values range from 0 to 1. The default priority of a page is 0.5.

createSitemapIndex()

Generates a sitemap index XML file with the custom sitemaps on the specified path.

import path from 'path';
import { createSitemapIndex } from 'sitemaps';

createSitemapIndex({
  filePath: path.join(__dirname, 'sitemap-index.xml'),
  sitemaps: [
    {
      loc: 'https://example.com/sitemap-1.xml',
      lastmod: '2023-01-31',
    },
    {
      loc: 'https://example.com/sitemap-2.xml',
      lastmod: '2023-01-31',
    },
  ],
});

// The sitemapIndex.xml file will be created in the specified path.
AttributeTypeDescription
locstring (required)Identifies the location of the Sitemap.
lastmodstring (optional)Identifies the time that the corresponding Sitemap file was modified. The value should be in W3C Datetime format.

License

Open source under the terms of the MIT License.

Maintained by Diogo Capela.

Keywords

FAQs

Last updated on 08 Aug 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc