Plugins You can find out about all the publicly available Grails plugins.

Sitemapper

1 vote
Dependency:
compile "org.grails.plugins:sitemapper:0.8.1"

 Documentation  Source  Issues

Summary

Autogeneration of sitemaps, see sitemaps.org for more information about sitemaps.

Installation

Add the following to your grails-app/conf/BuildConfig
plugins {
	//…
	compile ':sitemapper:0.9'
	//…
}

Change the version to reflect the actual version you would like to use.

Description

Quick Start

Create sitemap generator class by

grails create-sitemap
> Add pagination support? [y,n]
Select "y" if you exceed established limits (like 50 000 URLS per file) in one sitemap group.

Then script create sample artefact in grails-app/sitemaps folder,

Standard sitemap (single file):

import grails.plugin.sitemapper.Sitemapper

import static grails.plugin.sitemapper.ContentChangeFrequency.MONTHLY

class ForumSitemapper implements Sitemapper {

Date previousUpdate = new Date()

// The `withEntryWriter` method will be invoked each time the sitemap is requested. void withEntryWriter(EntryWriter entryWriter) { entryWriter.addEntry '/forum/topic1', new Date() - 1 entryWriter.addEntry '/forum/topic2', new Date(), MONTHLY, 0.5 // … }

}

Sitemaps group (multiple files):

import grails.plugin.sitemapper.EntryWriter
import grails.plugin.sitemapper.impl.PaginationSitemapper

class MessagesSitemapper extends PaginationSitemapper {

Date previousUpdate = new Date()

final int perPageCount = 50000

@Override long getTotalCount() { Message.count() }

@Override void withEntryWriter(EntryWriter entryWriter) { def items = Message.list([ max: perPageCount, offset: pageIndex * perPageCount, sort: 'createdDate', order: 'asc' ])

items.each { entryWriter.addEntry("/messages/${it.id}", it.createdDate) } }

}

Usage

On production mode plugin use gzip compression, so you can check sitemap index file by:

http://localhost:8080/sitemap.xml.gz
On the development mode directly:
http://localhost:8080/sitemap.xml

Config

To change sitemap filename (only filename, exclude extension), you can set the following in Config.groovy:

sitemap.prefix = 'mysitemap'
To disable gzip on production mode:
environments {
    production {
        sitemap.gzip = false
    }
}

Static files generation

Suggest use this plugin under proxy servers like nginx or Apache HTTP Server with enabled caching.

Anyway, plugin also support to generate static files by script:

grails generate-static-sitemaps
After running this script you can see result in target/sitemaps folder.