Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
75 lines (55 sloc) 1.7 KB
title template slug
Generate sitemap.xml

Generate sitemap.xml

Create an XML sitemap file that can be submitted to Google, Bing and other search engines to help them crawl your website better.

Main index.js file

const Sphido = require('sphido');
const globby = require('globby');

(async () => {
  // 1. Get pages from directory
  const pages = await Sphido.getPages(await globby('content/**/*.md'), ...Sphido.extenders);
  // 2. save them (with default template)
  for await (const page of pages) {
        page.dir.replace('content', 'public')
  // 3.  Generate sitemap.xml
  await Sphido.template.toFile(
        pages: pages,  
        domain: ''

theme/sitemap.xml template

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="">
	{% for page in pages %}
		<loc>{{domain + page.url() | trim}}</loc>
		<priority>{{ '1.00' if page.url() === '/' else '0.80'}}</priority>
	{% endfor %}

Check out your results in public/sitemap.xml.

Modify theme/page.html and theme/pages.html

Add follow code inside your <head> tag:

<link rel="sitemap" type="application/xml" title="Sitemap" href="/sitemap.xml" />

Source code

Submit Your Sitemap