Skip to content

Instantly share code, notes, and snippets.

@balupton
Last active October 11, 2015 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save balupton/3898935 to your computer and use it in GitHub Desktop.
Save balupton/3898935 to your computer and use it in GitHub Desktop.
DocPad: Sitemap Generation

DocPad: Sitemap Genereation

Generates a sitemap.txt file your website. To use add the contents of the docpad.coffee 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.

templateData:
# Site Properties
site:
# The production url of our website
url: "http://bevry.me"
events:
# Write
writeAfter: (opts,next) ->
# Prepare
balUtil = require('bal-util')
docpad = @docpad
config = docpad.getConfig()
sitemap = []
sitemapPath = config.outPath+'/sitemap.txt'
siteUrl = config.templateData.site.url
# 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