Sitemap

Generate a sitemap automatically for your site

Options See on deno.land

filename string

The sitemap file name

Default:
"/sitemap.xml"
query string

The query to search pages included in the sitemap

Default:
""
sort string

The values to sort the sitemap

Default:
"url=asc"
lastmod string function

The key to use for the lastmod field or a custom function

Default:
"date"
changefreq string function

The key to use for the changefreq field or a custom function

priority string function

The key to use for the priority field or a custom function

Description

This plugin generates a sitemap.xml file automatically with all your pages, which is useful for SEO. See the Sitemaps XML format specification for more info.

It also creates a robots.txt file that include a link to the sitemap file, so it's easier to discover for the search engines.

Installation

Import this plugin in your _config.ts file to use it:

import lume from "lume/mod.ts";
import sitemap from "lume/plugins/sitemap.ts";

const site = lume();

site.use(sitemap(/* Options */));

export default site;

Configuration

Internally, this plugin uses Search to search and return the pages. By default, all pages are included in the sitemap (except the 404 page) and sorted by URL. You can setup a different configuration:

site.use(sitemap({
  filename: "my-sitemap.xml", // to change the sitemap filename
  query: "indexable=true", // Select only pages with the indexable attribute as true
  sort: "date=desc", // To sort by data in ascendent order
}));

Multilanguage

It's possible generate sitemaps for sites with multiple languages using the multilanguage plugin:

import lume from "lume/mod.ts";
import multilanguage from "lume/plugins/multilanguage.ts";
import sitemap from "lume/plugins/sitemap.ts";

const site = lume();

site.use(multilanguage({
  languages: ["en", "gl", "es"],
}));
site.use(sitemap(/* Options */));

export default site;