sitemap

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: MIT Imports: 2 Imported by: 0

README

go-sitemap-generator

GitHub Repo stars GitHub issues GitHub License GitHub release (with filter) Go Report Card All Contributors

go-sitemap-generator A sitemap generator in Go. It can generate a sitemap in XML format.

English | 中文简体

Installation

go get github.com/chenmingyong0423/go-sitemap-generator

Usage

err := NewSitemap().
    Url(
        "https://xxx.cn/posts/1",
        WithLastMod("2024-05-17"),
        WithChangeFreq("weekly"),
        WithPriority(1.0),
    ).
    Url("https://xxx.cn/posts/2").Output("sitemap.xml").
    GenerateXml()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sitemap

type Sitemap struct {
	UrlSet UrlSet
	// contains filtered or unexported fields
}

func NewSitemap

func NewSitemap() *Sitemap

NewSitemap creates a new Sitemap the xmlns is defaulted to https://www.sitemaps.org/schemas/sitemap/0.9 you can change it by calling Sitemap.Xmlns Method

func (*Sitemap) GenerateXml

func (s *Sitemap) GenerateXml() error

func (*Sitemap) Output

func (s *Sitemap) Output(value string) *Sitemap

func (*Sitemap) Url

func (s *Sitemap) Url(loc string, opts ...URLOption) *Sitemap

func (*Sitemap) Xmlns

func (s *Sitemap) Xmlns(value string) *Sitemap

func (*Sitemap) XmlnsImage added in v1.0.1

func (s *Sitemap) XmlnsImage(value string) *Sitemap

type URL

type URL struct {
	Loc        string    `xml:"loc" opt:"-"`
	LastMod    string    `xml:"lastmod,omitempty"`
	ChangeFreq string    `xml:"changefreq,omitempty"`
	Priority   float64   `xml:"priority,omitempty"`
	Image      *UrlImage `xml:"image:image,omitempty"`
}

func NewURL

func NewURL(loc string, opts ...URLOption) *URL

type URLOption

type URLOption func(*URL)

func WithChangeFreq

func WithChangeFreq(changeFreq string) URLOption

func WithImage added in v1.0.0

func WithImage(image *UrlImage) URLOption

func WithLastMod

func WithLastMod(lastMod string) URLOption

func WithPriority

func WithPriority(priority float64) URLOption

type UrlImage added in v1.0.0

type UrlImage struct {
	Loc string `xml:"image:loc"`
}

func NewUrlImage added in v1.0.0

func NewUrlImage(ioc string) *UrlImage

type UrlSet

type UrlSet struct {
	XMLName    xml.Name `xml:"urlset"`
	Xmlns      string   `xml:"xmlns,attr"`
	XmlnsImage string   `xml:"xmlns:image,attr"`
	Urls       []URL    `xml:"url"`
}

func (*UrlSet) Marshal added in v1.2.0

func (urlSet *UrlSet) Marshal() ([]byte, error)

Jump to

Keyboard shortcuts

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