All Projects → feross → express-sitemap-xml

feross / express-sitemap-xml

Licence: MIT license
Serve sitemap.xml from a list of URLs in Express

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to express-sitemap-xml

X.Web.Sitemap
Simple sitemap generator for .NET
Stars: ✭ 66 (+17.86%)
Mutual labels:  sitemap, sitemap-generator, sitemap-xml
grav-plugin-sitemap
Grav Sitemap Plugin
Stars: ✭ 34 (-39.29%)
Mutual labels:  sitemap, sitemap-generator, sitemap-xml
jsitemapgenerator
Java sitemap generator. This library generates a web sitemap, can ping Google, generate RSS feed, robots.txt and more with friendly, easy to use Java 8 functional style of programming
Stars: ✭ 38 (-32.14%)
Mutual labels:  sitemap, sitemap-generator
sitemap-plugin
Sitemap Plugin for Sylius eCommerce platform
Stars: ✭ 68 (+21.43%)
Mutual labels:  sitemap, sitemap-generator
ultimate-sitemap-parser
Ultimate Website Sitemap Parser
Stars: ✭ 118 (+110.71%)
Mutual labels:  sitemap, sitemap-xml
scrape
Depth controllable Web scraper and Sitemap Generator in Go
Stars: ✭ 19 (-66.07%)
Mutual labels:  sitemap, sitemap-generator
sitewriter
A rust library to generate sitemaps.
Stars: ✭ 18 (-67.86%)
Mutual labels:  sitemap, sitemap-generator
sitemapper
parses sitemaps for Node.JS
Stars: ✭ 70 (+25%)
Mutual labels:  sitemap, sitemap-xml
sitemap
A simple sitemap generator for Laravel Framework.
Stars: ✭ 32 (-42.86%)
Mutual labels:  sitemap, sitemap-generator
SitemapTools
A sitemap (sitemap.xml) querying and parsing library for .NET
Stars: ✭ 19 (-66.07%)
Mutual labels:  sitemap, sitemap-xml
php-sitemap
PHP Simple Sitemap Generator
Stars: ✭ 16 (-71.43%)
Mutual labels:  sitemap, sitemap-generator
vuepress-plugin-sitemap
Sitemap generator plugin for vuepress.
Stars: ✭ 92 (+64.29%)
Mutual labels:  sitemap
React Router Sitemap
Generate sitemap.xml by React Router configuration
Stars: ✭ 189 (+237.5%)
Mutual labels:  sitemap
Sitemap Generator Crawler
Script that generates a sitemap by crawling a given URL
Stars: ✭ 169 (+201.79%)
Mutual labels:  sitemap
Go Sitemap Generator
go-sitemap-generator is the easiest way to generate Sitemaps in Go
Stars: ✭ 152 (+171.43%)
Mutual labels:  sitemap
Bard
Developer friendly Bard that writes sitemap poetry in xml.
Stars: ✭ 47 (-16.07%)
Mutual labels:  sitemap
Craft Seomatic
SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.
Stars: ✭ 135 (+141.07%)
Mutual labels:  sitemap
Sitemap
PHP XML Sitemap Generation
Stars: ✭ 128 (+128.57%)
Mutual labels:  sitemap
sitemapper
Fast, stream based XML Sitemap generator in Elixir
Stars: ✭ 32 (-42.86%)
Mutual labels:  sitemap-generator
Craft Sitemap
Craft plugin to generate a sitemap.
Stars: ✭ 105 (+87.5%)
Mutual labels:  sitemap

express-sitemap-xml travis npm downloads javascript style guide

Express middleware to serve sitemap.xml from a list of URLs

Create an Express middleware that serves sitemap.xml from a list of URLs.

This package automatically handles sitemaps with more than 50,000 URLs. In these cases, multiple sitemap files will be generated along with a "sitemap index" to comply with the sitemap spec and requirements from search engines like Google.

If only one sitemap file is needed (i.e. there are less than 50,000 URLs) then it is served directly at /sitemap.xml. Otherwise, a sitemap index is served at /sitemap.xml and sitemaps at /sitemap-0.xml, /sitemap-1.xml, etc.

Install

npm install express-sitemap-xml

Demo

You can see this package in action on BitMidi, a site for listening to your favorite MIDI files.

Usage (with Express)

The easiest way to use this package is with the Express middleware.

const express = require('express')
const expressSitemapXml = require('express-sitemap-xml')

const app = express()

app.use(expressSitemapXml(getUrls, 'https://bitmidi.com'))

async function getUrls () {
  return await getUrlsFromDatabase()
}

Remember to add a Sitemap line to robots.txt like this:

Sitemap: https://bitmidi.com/sitemap.xml

Usage (without Express)

The package can also be used without the Express middleware.

const { buildSitemaps } = require('express-sitemap-xml')

async function run () {
  const urls = ['/1', '/2', '/3']
  const sitemaps = await buildSitemaps(urls, 'https://bitmidi.com')

  console.log(Object.keys(sitemaps))
  // ['/sitemap.xml']

  console.log(sitemaps['/sitemap.xml'])
  // `<?xml version="1.0" encoding="utf-8"?>
  //  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  //    <url>
  //      <loc>https://bitmidi.com/1</loc>
  //      <lastmod>${getTodayStr()}</lastmod>
  //    </url>
  //    <url>
  //      <loc>https://bitmidi.com/2</loc>
  //      <lastmod>${getTodayStr()}</lastmod>
  //    </url>
  //    <url>
  //      <loc>https://bitmidi.com/3</loc>
  //      <lastmod>${getTodayStr()}</lastmod>
  //    </url>
  //  </urlset>`
})

Remember to add a Sitemap line to robots.txt like this:

Sitemap: https://bitmidi.com/sitemap.xml

API

middleware = expressSitemapXml(getUrls, base)

Create a sitemap.xml middleware. Both arguments are required.

The getUrls argument specifies an async function that resolves to an array of URLs to be included in the sitemap. Each URL in the array can either be an absolute or relative URL string like '/1', or an object specifying additional options about the URL:

{
  url: '/1',
  lastMod: new Date('2000-02-02'), // optional (specify `true` for today's date)
  changeFreq: 'weekly' // optional
}

For more information about these options, see the sitemap spec. Note that the priority option is not supported because Google ignores it.

The getUrls function is called at most once per 24 hours. The resulting sitemap(s) are cached to make repeated HTTP requests faster.

The base argument specifies the base URL to be used in case any URLs are specified as relative URLs. The argument is also used if a sitemap index needs to be generated and sitemap locations need to be specified, e.g. ${base}/sitemap-0.xml becomes https://bitmidi.com/sitemap-0.xml.

sitemaps = expressSitemapXml.buildSitemaps(urls, base)

Create an object where the keys are sitemap URLs to be served by the server and the values are strings of sitemap XML content. (This function does no caching.)

The urls argument is an array of URLs to be included in the sitemap. Each URL in the array can either be an absolute or relative URL string like '/1', or an object specifying additional options about the URL. See above for more info about the options.

The base argument is the same as above.

The return value is an object that looks like this:

{
  '/sitemap.xml': '<?xml version="1.0" encoding="utf-8"?>...'
}

Or if multiple sitemaps are needed, then the return object looks like this:

{
  '/sitemap.xml': '<?xml version="1.0" encoding="utf-8"?>...',
  '/sitemap-0.xml': '<?xml version="1.0" encoding="utf-8"?>...',
  '/sitemap-1.xml': '<?xml version="1.0" encoding="utf-8"?>...'
}

License

MIT. Copyright (c) Feross Aboukhadijeh.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].