Skip to content

Instantly share code, notes, and snippets.



Last active Oct 11, 2015
What would you like to do?
DocPad: Sitemap Generation

DocPad: Sitemap Genereation

Generates a sitemap.txt file your website. To use add the contents of the file of this gist into your docpad configuration file.

Note: There is now the Sitemap Plugin which generates a proper sitemap.xml file for you automatically instead of the basic sitemap.txt file this gist creates.

# Site Properties
# The production url of our website
url: ""
# Write
writeAfter: (opts,next) ->
# Prepare
balUtil = require('bal-util')
docpad = @docpad
config = docpad.getConfig()
sitemap = []
sitemapPath = config.outPath+'/sitemap.txt'
siteUrl =
# Get all the html files
docpad.getCollection('html').forEach (document) ->
if document.get('sitemap') isnt false and document.get('write') isnt false and document.get('ignored') isnt true and document.get('body')
sitemap.push siteUrl+document.get('url')
# Write the sitemap file
balUtil.writeFile(sitemapPath, sitemap.sort().join('\n'), next)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.