Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sitemaps

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sitemaps

A simple sitemap.xml generator.

  • 2.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
304
increased by6.29%
Maintainers
1
Weekly downloads
 
Created
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 sitemap-index.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

Package last updated on 24 May 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc