← All @molecule/* packages · App templates

@molecule/api-sitemap-xml

Provider bond · sitemap · API (Node) · v1.0.1 · Apache-2.0

XML sitemap, RSS, and Atom feed provider for molecule.dev

npm install @molecule/api-sitemap-xml

npm · Source on GitHub · Implements @molecule/api-sitemap

How it works

@molecule/api-sitemap-xml is a provider bond on the API (Node) side: it implements the sitemap core interface (@molecule/api-sitemap) with a concrete vendor or library behind it.

Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.

import { setProvider, addUrl, generate } from '@molecule/api-sitemap'
import { provider } from '@molecule/api-sitemap-xml'

setProvider(provider)

addUrl({ loc: 'https://example.com/', changefreq: 'daily', priority: 1.0 })
const xml = await generate()

Works with: @molecule/api-sitemap

Reference

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

XML sitemap, RSS, and Atom feed provider for molecule.dev.

Implements the SitemapProvider interface using zero-dependency XML string generation. Produces valid XML sitemaps (with image and alternate language support), sitemap indexes, RSS 2.0 feeds, and Atom feeds.

Quick Start

import { setProvider, addUrl, generate } from '@molecule/api-sitemap'
import { provider } from '@molecule/api-sitemap-xml'

setProvider(provider)

addUrl({ loc: 'https://example.com/', changefreq: 'daily', priority: 1.0 })
const xml = await generate()

Type

provider

Installation

npm install @molecule/api-sitemap-xml @molecule/api-sitemap

API

Interfaces

XmlSitemapConfig

Configuration options for the XML sitemap provider.

interface XmlSitemapConfig {
  /** Whether to pretty-print the XML output with indentation. Defaults to `false`. */
  pretty?: boolean

  /** XML stylesheet URL to include in sitemap output (for browser rendering). */
  xslUrl?: string
}

Functions

createProvider(config)

Creates an XML sitemap provider.

function createProvider(config?: XmlSitemapConfig): SitemapProvider
  • config — Provider configuration.

Returns: A SitemapProvider backed by XML generation.

escapeXml(str)

Escapes special XML characters in a string.

function escapeXml(str: string): string
  • str — The string to escape.

Returns: The XML-safe string.

joinLines(lines, indent, level)

Joins non-empty lines, optionally with indentation.

function joinLines(lines: string[], indent: string, level: number): string
  • lines — Array of XML line strings (empty strings are filtered out).
  • indent — Indentation string per level.
  • level — Current indentation level.

Returns: Joined string.

toISODate(date)

Formats a Date or ISO string to an ISO 8601 date string (W3C format).

function toISODate(date: string | Date): string
  • date — A Date object or ISO 8601 string.

Returns: An ISO 8601 date string.

toRFC822(date)

Formats a Date or ISO string to RFC 822 date string (for RSS).

function toRFC822(date: string | Date): string
  • date — A Date object or ISO 8601 string.

Returns: An RFC 822 date string.

xmlElement(tag, content, attributes)

Wraps content in an XML element. If content is undefined or empty, returns empty string.

function xmlElement(tag: string, content?: string, attributes?: Record<string, string>): string
  • tag — The element tag name.
  • content — The element text content.
  • attributes — Optional element attributes.

Returns: The XML element string, or empty string if no content.

xmlSelfClosing(tag, attributes)

Creates a self-closing XML element with attributes.

function xmlSelfClosing(tag: string, attributes: Record<string, string>): string
  • tag — The element tag name.
  • attributes — Element attributes.

Returns: The self-closing XML element string.

Constants

provider

The provider implementation with default configuration.

const provider: SitemapProvider

Core Interface

Implements @molecule/api-sitemap interface.

Bond Wiring

Setup function to register this provider with the core interface:

import { setProvider } from '@molecule/api-sitemap'
import { provider } from '@molecule/api-sitemap-xml'

export function setupSitemapXml(): void {
  setProvider(provider)
}

Injection Notes

Requirements

Peer dependencies:

  • @molecule/api-sitemap ^1.0.1

Runtime Dependencies

  • @molecule/api-sitemap