Skip to content

Instantly share code, notes, and snippets.

@balupton balupton/README.md
Last active Oct 11, 2015

Embed
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 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
You can’t perform that action at this time.