sitemap

package module
v0.0.0-...-fe0794d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2016 License: BSD-3-Clause Imports: 4 Imported by: 2

README

Golang Sitemap Generator

Creates sitemap files

GoDoc Build Status

Usage

package main

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

g := sitemap.New(sitmap.Options{
	Dir:         "sitemap",
	BaseURL:     "http://example.com/",
})
g.Open()
g.Add(sitemap.URL{Location:`http://example.com`, Priority: `0.5`})
g.Add(sitemap.URL{Location:`http://example.com/test`, Priority: `0.5`})
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
}

Documentation

Index

Constants

View Source
const (
	ChangeFreqAlways  = "always"
	ChangeFreqHourly  = "hourly"
	ChangeFreqDaily   = "daily"
	ChangeFreqWeekly  = "weekly"
	ChangeFreqMonthly = "monthly"
	ChangeFreqYearly  = "yearly"
	ChangeFreqNever   = "never"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator is a service that provides functions for creating sitemap files

func New

func New(options ...Options) *Generator

New constructs a new Generator instance with the supplied options.

func (*Generator) Abort

func (g *Generator) Abort() error

Abort stops generator and clears all temporary files

func (*Generator) Add

func (g *Generator) Add(url SitemapURL) error

Add new url to sitemap

func (*Generator) Close

func (g *Generator) Close() error

Close finishes generation process, all temp files will removed

func (*Generator) Open

func (g *Generator) Open() (err error)

Open drops internal counters and checks you generator options

type Options

type Options struct {
	// Filename is base file name for sitemap w/o extension
	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
}

Options is a struct for specifying configuration options for the sitemap.Generator object.

type SitemapURL

type SitemapURL interface {
	SitemapLoc() string
	SitemapChangeFreq() string
	SitemapLastMod() string
	SitemapPriority() string
}

type URL

type URL struct {
	Loc        string
	ChangeFreq string
	LastMod    string
	Priority   string
}

func (URL) SitemapChangeFreq

func (u URL) SitemapChangeFreq() string

func (URL) SitemapLastMod

func (u URL) SitemapLastMod() string

func (URL) SitemapLoc

func (u URL) SitemapLoc() string

func (URL) SitemapPriority

func (u URL) SitemapPriority() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL