Skip to content

Latest commit

 

History

History
82 lines (65 loc) · 1.83 KB

README.md

File metadata and controls

82 lines (65 loc) · 1.83 KB

Golang Sitemap Generator

Creates sitemap files

GoDoc Build Status

Usage

package main

import (
	"github.com/pahanini/go-sitemap-generator"
)

g := sitemap.New(sitemap.Options{
	Dir:         "sitemap",
	BaseURL:     "http://example.com/",
})
g.Open()
g.Add(sitemap.URL{Loc:`http://example.com`, Priority: `0.5`})
g.Add(sitemap.URL{Loc:`http://example.com/test`, Priority: `0.5`})
g.Close()

If you want to add some images you can use the following

package main

import (
	"github.com/pahanini/go-sitemap-generator"
)

g := sitemap.New(sitemap.Options{
	Dir:     "sitemap",
	BaseURL: "http://example.com/",
	XMLns: map[string]string{
		"xmlns:image": "http://www.google.com/schemas/sitemap-image/1.1",
	},
})

	images := []sitemap.Image{
	sitemap.Image{
		Loc:   "http://example.com/image",
		Title: "Image",
	}}
g.Open()
g.Add(sitemap.URL{Loc: `http://example.com`, Priority: `0.5`, Images: images})
g.Close()

Install

$ go get github.com/pahanini/go-sitemap-generator

Available Options

Sitemap comes with a variety of configuration options. Available Options:

type Options struct {
	// Filename is base file name for sitemap w/o extension
	// - single file <filename>.xml
	// - many files with sitemap index <filename>.xml index and <filename>-<n>.xml files
	Filename string
	// Max file size (default 10485760)
	MaxFileSize int
	// Max links in one file (default 50000)
	MaxURLs int
	// Dir keeps directory name for sitemap files
	Dir string
	// BaseURL used for generate sitemap index file
	BaseURL string
	// XML Namespaces
	XMLns map[string]string
}