Socket
Socket
Sign inDemoInstall

@mongez/sitemap

Package Overview
Dependencies
2
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @mongez/sitemap

A simple Sitemap generator for Node.js


Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Sitemap Generator

A simple yet powerful sitemap generator written for Node.js.

Installation

Yarn

yarn add @mongez/sitemap

NPM

npm i @mongez/sitemap

PNPM

pnpm i @mongez/sitemap

BUN

bun add @mongez/sitemap

Usage

Import the sitemap class, pass the base url and locale codes to it, then add the pages to the sitemap.

import { Sitemap } from "@mongez/sitemap";

const sitemap = new Sitemap("https://example.com", ["en", "ar"]);

sitemap.add("/").add("/about-us").add("/contact-us");

await sitemap.saveTo("/path/to/sitemap.xml");

And that's it

This will create a sitemap with links, each link will have the original path along with the locale code as well.

Add more options to path

If you want to customize the path, you can pass an object to the add method.

sitemap.add({
  path: "/",
  lastModified: new Date(),
  changeFrequency: "daily",
  priority: 0.8,
});

The object can have the following properties:

type SitemapPath = {
  /**
   * The relative path to the website
   */
  path: string;
  /**
   * Last modification date
   */
  lastModified?: Date | string;
  /**
   * Change frequency
   */
  changeFrequency?: string;
  /**
   * Priority
   */
  priority?: number;
  /**
   * Hreflang
   * If you have multiple languages, you can add the hreflang, it will be used automatically if locale codes are set
   */
  hreflang?: {
    [localeCOde: string]: string;
  };
};

Generate Only

If you want just the xml sitemap without saving it to a file, you can use the generate method.

const xml = await sitemap.generate();

Alternatively, you can use the toXml method.

const xml = await sitemap.toXml();

ChangeLog

  • Fixed route path when generating sitemap.

Keywords

FAQs

Last updated on 11 Oct 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