Modules@robinpath/sitemap
sitemap

@robinpath/sitemap

0.1.1Node.jsPublic

XML sitemap generation, parsing, validation, and manipulation with image/video/alternate support

Sitemap

XML sitemap generation, parsing, validation, and manipulation with image/video/alternate support

Package: @robinpath/sitemap | Category: Web | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the sitemap module when you need to:

  • Create XML sitemap -- Use sitemap.create to perform this operation
  • Create sitemap index -- Use sitemap.createIndex to perform this operation
  • Parse XML sitemap -- Use sitemap.parse to perform this operation
  • Parse sitemap index -- Use sitemap.parseIndex to perform this operation
  • Add URL to sitemap XML -- Use sitemap.addUrl to perform this operation

Quick Reference

FunctionDescriptionReturns
createCreate XML sitemapXML sitemap
createIndexCreate sitemap indexXML sitemap index
parseParse XML sitemapArray of URL objects
parseIndexParse sitemap indexArray of {loc, lastmod}
addUrlAdd URL to sitemap XMLUpdated XML
removeUrlRemove URL from sitemap XMLUpdated XML
filterByChangefreqFilter URLs by change frequencyFiltered URLs
filterByPriorityFilter URLs by priority rangeFiltered URLs
sortByPrioritySort URLs by prioritySorted URLs
sortByLastmodSort URLs by last modifiedSorted URLs
countCount URLs in sitemapURL count
extractLocsExtract all loc URLsArray of URL strings
validateValidate sitemap XML{valid, errors[], urlCount}

Functions

create

Create XML sitemap

Module: sitemap | Returns: string -- XML sitemap

sitemap.create [{"loc": "https://example.com/", "priority": 1.0}]
ParameterTypeRequiredDescription
urlsarrayYesArray of {loc, lastmod, changefreq, priority, images, videos, alternates}
optionsobjectNo{pretty}

createIndex

Create sitemap index

Module: sitemap | Returns: string -- XML sitemap index

sitemap.createIndex [{"loc": "https://example.com/sitemap1.xml"}]
ParameterTypeRequiredDescription
sitemapsarrayYesArray of {loc, lastmod}

parse

Parse XML sitemap

Module: sitemap | Returns: array -- Array of URL objects

sitemap.parse $xml
ParameterTypeRequiredDescription
xmlstringYesXML sitemap content

parseIndex

Parse sitemap index

Module: sitemap | Returns: array -- Array of {loc, lastmod}

sitemap.parseIndex $xml
ParameterTypeRequiredDescription
xmlstringYesXML sitemap index

addUrl

Add URL to sitemap XML

Module: sitemap | Returns: string -- Updated XML

sitemap.addUrl $xml {"loc": "https://example.com/new"}
ParameterTypeRequiredDescription
xmlstringYesExisting sitemap XML
urlobjectYesURL object

removeUrl

Remove URL from sitemap XML

Module: sitemap | Returns: string -- Updated XML

sitemap.removeUrl $xml "https://example.com/old"
ParameterTypeRequiredDescription
xmlstringYesSitemap XML
locstringYesURL to remove

filterByChangefreq

Filter URLs by change frequency

Module: sitemap | Returns: array -- Filtered URLs

sitemap.filterByChangefreq $urls "daily"
ParameterTypeRequiredDescription
urlsarrayYesParsed URLs
changefreqstringYesFrequency

filterByPriority

Filter URLs by priority range

Module: sitemap | Returns: array -- Filtered URLs

sitemap.filterByPriority $urls 0.8 1.0
ParameterTypeRequiredDescription
urlsarrayYesParsed URLs
minnumberYesMin priority
maxnumberNoMax priority

sortByPriority

Sort URLs by priority

Module: sitemap | Returns: array -- Sorted URLs

sitemap.sortByPriority $urls
ParameterTypeRequiredDescription
urlsarrayYesParsed URLs
descendingbooleanNoDescending (default true)

sortByLastmod

Sort URLs by last modified

Module: sitemap | Returns: array -- Sorted URLs

sitemap.sortByLastmod $urls
ParameterTypeRequiredDescription
urlsarrayYesParsed URLs
descendingbooleanNoDescending (default true)

count

Count URLs in sitemap

Module: sitemap | Returns: number -- URL count

sitemap.count $urls
ParameterTypeRequiredDescription
urlsarrayYesParsed URLs

extractLocs

Extract all loc URLs

Module: sitemap | Returns: array -- Array of URL strings

sitemap.extractLocs $urls
ParameterTypeRequiredDescription
urlsarrayYesParsed URLs

validate

Validate sitemap XML

Module: sitemap | Returns: object -- {valid, errors[], urlCount}

sitemap.validate $xml
ParameterTypeRequiredDescription
xmlstringYesSitemap XML

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "Create and validate result"
do
  set $result as sitemap.create [{"loc": "https://example.com/", "priority": 1.0}]
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Create a new item with create

Create a new resource and capture the result.

set $result as sitemap.create [{"loc": "https://example.com/", "priority": 1.0}]
print "Created: " + $result

2. Multi-step Sitemap workflow

Chain multiple sitemap operations together.

@desc "Create, create index, and more"
do
  set $r_create as sitemap.create [{"loc": "https://example.com/", "priority": 1.0}]
  set $r_createIndex as sitemap.createIndex [{"loc": "https://example.com/sitemap1.xml"}]
  set $r_parse as sitemap.parse $xml
  print "All operations complete"
enddo

3. Safe create with validation

Check results before proceeding.

@desc "Create and validate result"
do
  set $result as sitemap.create [{"loc": "https://example.com/", "priority": 1.0}]
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/sitemap

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size6.0 KB
Versions1
Weekly Downloads23
Total Downloads23
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

web