sitemap

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

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

Go to latest
Published: Sep 7, 2015 License: BSD-2-Clause Imports: 2 Imported by: 0

README

sitemap

Is a package that generate XML sitemap from the given page objects.

It implement the sitemap page and sitemap index.

Documentation can be found at: http://godoc.org/github.com/alexandreStein/sitemap

Example:

package main

import (
	"fmt"
	"time"

	"github.com/alexandreStein/sitemap"
)

func main() {
	// Set the last modification to now
	now := time.Now()

	// Initialize a standard sitemap
	sMap := sitemap.Page{
		Urlset: []*sitemap.Sitemap{
			&sitemap.Sitemap{
				Loc:        "https://www.test.com",
				LastMod:    &now,
				Changefreq: sitemap.Daily,
				Priority:   0.5,
			},
		},
	}
	// Build the XML output
	x, err := sMap.GetXML()
	fmt.Println(string(x), err)

	// Initialize an index sitemap
	sMapi := sitemap.IndexPage{
		Urlset: []*sitemap.Sitemap{
			&sitemap.Sitemap{
				Loc: "https://www.test.com/sitemap.xml",
			},
		},
	}
	// Same as sitemap page build the XML using GetXML
	x, err = sMapi.GetXML()
	fmt.Println(string(x), err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeFreq

type ChangeFreq string

ChangeFreq is a type to only permit coerant choice

const (
	Always  ChangeFreq = "always"
	Hourly  ChangeFreq = "hourly"
	Daily   ChangeFreq = "daily"
	Weekly  ChangeFreq = "weekly"
	Monthly ChangeFreq = "monthly"
	Yearly  ChangeFreq = "yearly"
	Never   ChangeFreq = "never"
)

Those values represent the posible change frequences

type IndexPage

type IndexPage struct {
	Page
	// Set the name of the element
	XMLName xml.Name   `xml:"sitemapindex"`
	Urlset  []*Sitemap `xml:"sitemap"`
}

IndexPage represent the sitemap index element

func (*IndexPage) GetXML

func (p *IndexPage) GetXML() ([]byte, error)

GetXML return the corresponding sitemap XML

type Page

type Page struct {
	// Set the name of the element
	XMLName xml.Name   `xml:"urlset"`
	Urlset  []*Sitemap `xml:"url"`
	Xmlns   string     `xml:"xmlns,attr"`
}

Page is the XML page

func (*Page) GetXML

func (p *Page) GetXML() ([]byte, error)

GetXML return the corresponding sitemap XML

type Sitemap

type Sitemap struct {
	Loc        string     `xml:"loc"`
	LastMod    *time.Time `xml:"lastmod,omitempty"`
	Changefreq ChangeFreq `xml:"changefreq,omitempty"`
	Priority   float32    `xml:"priority,omitempty"`
}

Sitemap is actualy the real sitemap element

Jump to

Keyboard shortcuts

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