sitemap

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

README

Sitemap Format

godoc Go Report Card Coverage

Simple sitemap formatting, with a little syntactic sugar.

Install

go get github.com/mingard/sitemap-format

Usage


// Examples to come

Documentation

Index

Constants

View Source
const (
	// TagLimit is the number of permitted video tags.
	TagLimit = 32
	// MaxDescriptionLength is the maximum length of the video:description.
	MaxDescriptionLength = 2048
	// DurationMin is the minimum video duration of 1 second.
	DurationMin int = 1
	// DurationMax is the maximum video duration length in seconds (8 hours).
	DurationMax int = 28800
	// RatingLow is the lowest posible rating.
	RatingLow float32 = 0.0
	// RatingHigh is the highest posible rating.
	RatingHigh float32 = 5.0
)

Variables

View Source
var (
	// Allow is the allow attribute.
	Allow = &xml.Attr{
		Name:  xml.Name{Local: "relationship"},
		Value: "allow",
	}
	// Deny is the deny attribute.
	Deny = &xml.Attr{
		Name:  xml.Name{Local: "relationship"},
		Value: "deny",
	}
)
View Source
var (
	// XMLNSDefault is the default XML Namespace type.
	XMLNSDefault = &xml.Attr{
		Name:  xml.Name{Local: "xmlns"},
		Value: "http://www.sitemaps.org/schemas/sitemap/0.9",
	}
	// XMLNSNews is the XML Namespace type for news.
	XMLNSNews = &xml.Attr{
		Name:  xml.Name{Local: "xmlns:news"},
		Value: "http://www.google.com/schemas/sitemap-news/0.9",
	}
	// XMLNSXHTML is the XML Namespace type for XHTML.
	XMLNSXHTML = &xml.Attr{
		Name:  xml.Name{Local: "xmlns"},
		Value: "http://www.w3.org/1999/xhtml",
	}
	// XMLNSMobile is the XML Namespace type for mobile-only content.
	XMLNSMobile = &xml.Attr{
		Name:  xml.Name{Local: "xmlns:mobile"},
		Value: "http://www.google.com/schemas/sitemap-mobile/1.0",
	}
	// XMLNSImage is the XML Namespace type for images.
	XMLNSImage = &xml.Attr{
		Name:  xml.Name{Local: "xmlns:image"},
		Value: "http://www.google.com/schemas/sitemap-image/1.1",
	}
	// XMLNSVideo is the XML Namespace type for videos.
	XMLNSVideo = &xml.Attr{
		Name:  xml.Name{Local: "xmlns:image"},
		Value: "http://www.google.com/schemas/sitemap-video/1.1",
	}
)

Functions

This section is empty.

Types

type BoolStr

type BoolStr string
const (
	Yes BoolStr = "yes"
	No  BoolStr = "no"
)

type Image

type Image struct {
	XMLName xml.Name `xml:"image:image"`
	// Loc is the location of the image
	Loc string `xml:"image:loc"`
}

Image stores image entry data.

func NewImage

func NewImage() *Image

NewImage returns a new instance of the default Image extension.

func (*Image) SetLoc

func (i *Image) SetLoc(l string) *Image

SetLoc sets the image location.

type Lang

type Lang string
const (
	// 'en' is the default language.
	LanguageDefault Lang = Language_EN
	Language_AA     Lang = "aa"
	Language_AB     Lang = "ab"
	Language_AE     Lang = "ae"
	Language_AF     Lang = "af"
	Language_AK     Lang = "ak"
	Language_AM     Lang = "am"
	Language_AN     Lang = "an"
	Language_AR     Lang = "ar"
	Language_AS     Lang = "as"
	Language_AV     Lang = "av"
	Language_AY     Lang = "ay"
	Language_AZ     Lang = "az"
	Language_BA     Lang = "ba"
	Language_BE     Lang = "be"
	Language_BG     Lang = "bg"
	Language_BH     Lang = "bh"
	Language_BI     Lang = "bi"
	Language_BM     Lang = "bm"
	Language_BN     Lang = "bn"
	Language_BO     Lang = "bo"
	Language_BR     Lang = "br"
	Language_BS     Lang = "bs"
	Language_CA     Lang = "ca"
	Language_CE     Lang = "ce"
	Language_CH     Lang = "ch"
	Language_CO     Lang = "co"
	Language_CR     Lang = "cr"
	Language_CS     Lang = "cs"
	Language_CU     Lang = "cu"
	Language_CV     Lang = "cv"
	Language_CY     Lang = "cy"
	Language_DA     Lang = "da"
	Language_DE     Lang = "de"
	Language_DV     Lang = "dv"
	Language_DZ     Lang = "dz"
	Language_EE     Lang = "ee"
	Language_EL     Lang = "el"
	Language_EN     Lang = "en"
	Language_EO     Lang = "eo"
	Language_ES     Lang = "es"
	Language_ET     Lang = "et"
	Language_EU     Lang = "eu"
	Language_FA     Lang = "fa"
	Language_FF     Lang = "ff"
	Language_FI     Lang = "fi"
	Language_FJ     Lang = "fj"
	Language_FO     Lang = "fo"
	Language_FR     Lang = "fr"
	Language_FY     Lang = "fy"
	Language_GA     Lang = "ga"
	Language_GD     Lang = "gd"
	Language_GL     Lang = "gl"
	Language_GN     Lang = "gn"
	Language_GU     Lang = "gu"
	Language_GV     Lang = "gv"
	Language_HA     Lang = "ha"
	Language_HE     Lang = "he"
	Language_HI     Lang = "hi"
	Language_HO     Lang = "ho"
	Language_HR     Lang = "hr"
	Language_HT     Lang = "ht"
	Language_HU     Lang = "hu"
	Language_HY     Lang = "hy"
	Language_HZ     Lang = "hz"
	Language_IA     Lang = "ia"
	Language_ID     Lang = "id"
	Language_IE     Lang = "ie"
	Language_IG     Lang = "ig"
	Language_II     Lang = "ii"
	Language_IK     Lang = "ik"
	Language_IO     Lang = "io"
	Language_IS     Lang = "is"
	Language_IT     Lang = "it"
	Language_IU     Lang = "iu"
	Language_JA     Lang = "ja"
	Language_JV     Lang = "jv"
	Language_KA     Lang = "ka"
	Language_KG     Lang = "kg"
	Language_KI     Lang = "ki"
	Language_KJ     Lang = "kj"
	Language_KK     Lang = "kk"
	Language_KL     Lang = "kl"
	Language_KM     Lang = "km"
	Language_KN     Lang = "kn"
	Language_KO     Lang = "ko"
	Language_KR     Lang = "kr"
	Language_KS     Lang = "ks"
	Language_KU     Lang = "ku"
	Language_KV     Lang = "kv"
	Language_KW     Lang = "kw"
	Language_KY     Lang = "ky"
	Language_LA     Lang = "la"
	Language_LB     Lang = "lb"
	Language_LG     Lang = "lg"
	Language_LI     Lang = "li"
	Language_LN     Lang = "ln"
	Language_LO     Lang = "lo"
	Language_LT     Lang = "lt"
	Language_LU     Lang = "lu"
	Language_LV     Lang = "lv"
	Language_MG     Lang = "mg"
	Language_MH     Lang = "mh"
	Language_MI     Lang = "mi"
	Language_MK     Lang = "mk"
	Language_ML     Lang = "ml"
	Language_MN     Lang = "mn"
	Language_MR     Lang = "mr"
	Language_MS     Lang = "ms"
	Language_MT     Lang = "mt"
	Language_MY     Lang = "my"
	Language_NA     Lang = "na"
	Language_NB     Lang = "nb"
	Language_ND     Lang = "nd"
	Language_NE     Lang = "ne"
	Language_NG     Lang = "ng"
	Language_NL     Lang = "nl"
	Language_NN     Lang = "nn"
	Language_NO     Lang = "no"
	Language_NR     Lang = "nr"
	Language_NV     Lang = "nv"
	Language_NY     Lang = "ny"
	Language_OC     Lang = "oc"
	Language_OJ     Lang = "oj"
	Language_OM     Lang = "om"
	Language_OR     Lang = "or"
	Language_OS     Lang = "os"
	Language_PA     Lang = "pa"
	Language_PI     Lang = "pi"
	Language_PL     Lang = "pl"
	Language_PS     Lang = "ps"
	Language_PT     Lang = "pt"
	Language_QU     Lang = "qu"
	Language_RM     Lang = "rm"
	Language_RN     Lang = "rn"
	Language_RO     Lang = "ro"
	Language_RU     Lang = "ru"
	Language_RW     Lang = "rw"
	Language_SA     Lang = "sa"
	Language_SC     Lang = "sc"
	Language_SD     Lang = "sd"
	Language_SE     Lang = "se"
	Language_SG     Lang = "sg"
	Language_SI     Lang = "si"
	Language_SK     Lang = "sk"
	Language_SL     Lang = "sl"
	Language_SM     Lang = "sm"
	Language_SN     Lang = "sn"
	Language_SO     Lang = "so"
	Language_SQ     Lang = "sq"
	Language_SR     Lang = "sr"
	Language_SS     Lang = "ss"
	Language_ST     Lang = "st"
	Language_SU     Lang = "su"
	Language_SV     Lang = "sv"
	Language_SW     Lang = "sw"
	Language_TA     Lang = "ta"
	Language_TE     Lang = "te"
	Language_TG     Lang = "tg"
	Language_TH     Lang = "th"
	Language_TI     Lang = "ti"
	Language_TK     Lang = "tk"
	Language_TL     Lang = "tl"
	Language_TN     Lang = "tn"
	Language_TO     Lang = "to"
	Language_TR     Lang = "tr"
	Language_TS     Lang = "ts"
	Language_TT     Lang = "tt"
	Language_TW     Lang = "tw"
	Language_TY     Lang = "ty"
	Language_UG     Lang = "ug"
	Language_UK     Lang = "uk"
	Language_UR     Lang = "ur"
	Language_UZ     Lang = "uz"
	Language_VE     Lang = "ve"
	Language_VI     Lang = "vi"
	Language_VO     Lang = "vo"
	Language_WA     Lang = "wa"
	Language_WO     Lang = "wo"
	Language_XH     Lang = "xh"
	Language_YI     Lang = "yi"
	Language_YO     Lang = "yo"
	Language_ZA     Lang = "za"
	Language_ZH     Lang = "zh"
	Language_ZU     Lang = "zu"
)

type News

type News struct {
	XMLName         xml.Name     `xml:"news:news"`
	Name            string       `xml:"news:name"`
	Publication     *Publication `xml:"news:publication"`
	PublicationDate time.Time    `xml:"news:publication_date"`
	Title           string       `xml:"news:title"`
}

News stores news entry data.

func NewNews

func NewNews() *News

NewNews returns a new instance of the default News extension.

func (*News) SetLanguage

func (n *News) SetLanguage(l Lang) *News

SetLanguage sets the news extensions Publication.NewsLanguage parameter. Must be Lang.

func (*News) SetName added in v1.0.1

func (n *News) SetName(na string) *News

SetName sets the news extensions name parameter.

func (*News) SetPublicationDate

func (n *News) SetPublicationDate(t time.Time) *News

SetPublicationDate sets the news extensions PublicationDate parameter.

func (*News) SetTitle

func (n *News) SetTitle(t string) *News

SetTitle sets the news extensions title parameter.

type Platform

type Platform struct {
	XMLName      xml.Name  `xml:"video:restriction,omitempty"`
	Relationship *xml.Attr `xml:",attr,omitempty"`
	Value        string    `xml:",chardata"`
}

Platform stores allowed and restricted platforms.

type PlatformName

type PlatformName string

PlatformName is a string name for a platform.

const (
	Web    PlatformName = "web"
	Mobile PlatformName = "mobile"
	TV     PlatformName = "tv"
)

type Publication

type Publication struct {
	XMLName      xml.Name `xml:"news:publication"`
	NewsName     string   `xml:"news:name,omitempty"`
	NewsLanguage Lang     `xml:"news:language,omitempty"`
}

Publication is the news publication sub-component to News.

type Restriction

type Restriction struct {
	XMLName      xml.Name  `xml:"video:restriction,omitempty"`
	Relationship *xml.Attr `xml:",attr,omitempty"`
	Value        string    `xml:",chardata"`
}

Restriction stores country restriction details

type SitemapXML

type SitemapXML struct {
	UrlSet []*UrlSet `xml:"urlset,omitempty"`
	// contains filtered or unexported fields
}

SitemapXML is the top level XML node for the sitemap

func New

func New() *SitemapXML

New returns a new instance of the default XML.

func (*SitemapXML) AddUrl

func (s *SitemapXML) AddUrl(u *Url)

AddUrl inserts a URL node into the XML's UrlSet node.

func (*SitemapXML) Output

func (s *SitemapXML) Output() ([]byte, error)

Output returns the output value as bytes

func (*SitemapXML) OutputPrettyString

func (s *SitemapXML) OutputPrettyString(prefix, indent string) (string, error)

OutputPrettyString returns the output as a string with prettified rules. Empty if there's an error.

func (*SitemapXML) OutputString

func (s *SitemapXML) OutputString() (string, error)

OutputString returns the output as a string. Empty if there's an error.

func (*SitemapXML) PrettyFormat

func (s *SitemapXML) PrettyFormat(prefix, indent string)

Pretty sets the output to use a prettified format.

func (*SitemapXML) SetType

func (s *SitemapXML) SetType(t *xml.Attr)

SetType sets the urlset type and creates a default urlset if necessary.

type Uploader

type Uploader struct {
	XMLName xml.Name `xml:"video:uploader,omitempty"`
	// Info (optional) specifies the URL of a webpage with additional information about this uploader.
	Info string `xml:"info,attr,omitempty"`
	// Value is the video uploader's name, a string with a maximum of 255 characters.
	Value string `xml:",chardata"`
}

Uploader stores the uploader of the video.

type Url

type Url struct {
	XMLName          xml.Name  `xml:"url,omitempty"`
	Location         string    `xml:"loc,omitempty"`
	ChangeFrequency  string    `xml:"changefreq,omitempty"`
	Priority         string    `xml:"priority,omitempty"`
	LastModifiedDate time.Time `xml:"lastmod,omitempty"`
	News             *News     `xml:"news:news,omitempty"`
	Images           []*Image  `xml:"image:image,omitempty"`
	Videos           []*Video  `xml:"video:video,omitempty"`
}

Url is a url block to be nested under UrlSet.

func NewUrl

func NewUrl() *Url

NewUrl returns a new instance of the default URL.

func (*Url) AddImage

func (u *Url) AddImage(i ...*Image) *Url

AddImage adds one or more image block value.

func (*Url) AddVideo

func (u *Url) AddVideo(v ...*Video) *Url

AddVideo adds one or more video block value.

func (*Url) SetLastModified

func (u *Url) SetLastModified(t time.Time) *Url

SetLastModified sets the value of the modified date field.

func (*Url) SetLocation

func (u *Url) SetLocation(l string) *Url

SetLocation sets the url's location parameter

func (*Url) SetNews

func (u *Url) SetNews(n *News) *Url

SetNews sets the news value.

type UrlSet

type UrlSet struct {
	XMLName    xml.Name    `xml:"urlset"`
	Attributes []*xml.Attr `xml:",attr,omitempty"`
	Url        []*Url      `xml:"url,omitempty"`
}

func NewUrlSet

func NewUrlSet() *UrlSet

NewUrlSet returns a new instance of the default UrlSet.

func (*UrlSet) AddUrl

func (u *UrlSet) AddUrl(url *Url)

AddUrl inserts a URL node into the XML's UrlSet node.

func (*UrlSet) SetType

func (u *UrlSet) SetType(t *xml.Attr)

SetType sets the urlset xml namespace type.

type Video

type Video struct {
	XMLName xml.Name `xml:"video:video"`

	// Title HTML entities must be escaped or wrapped in a CDATA block.
	Title string `xml:"video:title"`
	// Description Maximum {{MaxDescriptionLength}} characters. All HTML entities must be escaped or wrapped in a CDATA block. It must match the description displayed on the web page (it doesn't need to be a word-for-word match).
	Description  string `xml:"video:description,omitempty"`
	ThumbnailLoc string `xml:"video:thumbnail_loc,omitempty"`
	// ContentLoc HTML and Flash aren't supported formats.
	ContentLoc string `xml:"video:content_loc,omitempty"`
	// Can be used instead of or alongside ContentLoc.
	PlayerLoc string `xml:"video:player_loc,omitempty"`

	// Duration value must be from {{DurationMin}} to {{DurationMax}} inclusive.
	Duration int `xml:"video:duration,omitempty"`
	// ExpirationDate format either YYYY-MM-DD or YYYY-MM-DDThh:mm:ss+TZD
	ExpirationDate time.Time `xml:"video:expiration_date,omitempty"`

	// Rating values are float numbers in the range {{RatingLow}} (low) to {{RatingHigh}} (high), inclusive.
	Rating          float32   `xml:"video:rating,omitempty"`
	ViewCount       int       `xml:"video:view_count,omitempty"`
	PublicationDate time.Time `xml:"video:publication_date,omitempty"`
	// FamilyFriendly whether the video is available with SafeSearch.
	FamilyFriendly BoolStr        `xml:"video:family_friendly,omitempty"`
	Restrictions   []*Restriction `xml:"video:restriction,omitempty"`
	Platforms      []*Platform    `xml:"video:platform,omitempty"`
	// RequiresSubscription indicates whether a subscription is required to view the video.
	RequiresSubscription BoolStr   `xml:"video:requires_subscription,omitempty"`
	Uploader             *Uploader `xml:"video:uploader,omitempty"`
	// Live indicates whether the video is a live stream
	Live BoolStr `xml:"video:live,omitempty"`
	// Tags are limited to a max of {{TagLimit}}.
	Tags []string `xml:"video:tag,omitempty"`
}

Video stores video entry data.

func NewVideo

func NewVideo() *Video

NewVideo returns a new instance of the default Video extension.

func (*Video) AllowCountries

func (v *Video) AllowCountries(c string) *Video

AllowCountries creates a list of allowed countries.

func (*Video) AllowPlatforms

func (v *Video) AllowPlatforms(p ...PlatformName) *Video

AllowPlatforms creates a list of allowed platforms.

func (*Video) DenyCountries

func (v *Video) DenyCountries(c string) *Video

DenyCountries creates a list of denied countries.

func (*Video) DenyPlatforms

func (v *Video) DenyPlatforms(p ...PlatformName) *Video

DenyPlatforms creates a list of denied platforms.

func (*Video) IsFamilyFriendly

func (v *Video) IsFamilyFriendly() *Video

IsFamilyFriendly sets the family friendly option to 'yes'

func (*Video) IsLive

func (v *Video) IsLive() *Video

IsLive sets the live option to 'yes'

func (*Video) NotFamilyFriendly

func (v *Video) NotFamilyFriendly() *Video

NotFamilyFriendly sets the family friendly option to 'no'

func (*Video) NotLive

func (v *Video) NotLive() *Video

NotLive sets the live option to 'no'

func (*Video) SetContentLoc

func (v *Video) SetContentLoc(c string) *Video

SetContentLoc sets the video content location parameter.

func (*Video) SetDescription

func (v *Video) SetDescription(d string) *Video

SetDescription sets the video extensions description parameter.

func (*Video) SetDuration

func (v *Video) SetDuration(d int) *Video

SetDuration sets the video duration parameter.

func (*Video) SetExpirationDate

func (v *Video) SetExpirationDate(t time.Time) *Video

SetExpirationDate sets the video ExpirationDate parameter.

func (*Video) SetPlayerLoc

func (v *Video) SetPlayerLoc(p string) *Video

SetPlayerLoc sets the video player location parameter.

func (*Video) SetPublicationDate

func (v *Video) SetPublicationDate(t time.Time) *Video

SetPublicationDate sets the video extensions PublicationDate parameter.

func (*Video) SetRating

func (v *Video) SetRating(r float32) *Video

SetRating sets the video rating.

func (*Video) SetTags

func (v *Video) SetTags(t ...string) *Video

SetTags sets tag values

func (*Video) SetThumbnailLoc

func (v *Video) SetThumbnailLoc(t string) *Video

SetThumbnailLoc sets the video thumbnail location parameter.

func (*Video) SetTitle

func (v *Video) SetTitle(t string) *Video

SetTitle sets the video extensions title parameter.

func (*Video) SetUploader

func (v *Video) SetUploader(u *Uploader) *Video

SetUploader sets the uploader

func (*Video) SetUploaderInfo

func (v *Video) SetUploaderInfo(i string) *Video

SetUploaderInfo sets the uploader

func (*Video) SetUploaderVal

func (v *Video) SetUploaderVal(val string) *Video

SetUploaderVal sets the uploader value

func (*Video) SetViewCount

func (v *Video) SetViewCount(vc int) *Video

SetViewCount sets the video view_count.

func (*Video) SubNotRequired

func (v *Video) SubNotRequired() *Video

SubNotRequired sets the requires_subscription option to 'no'

func (*Video) SubRequired

func (v *Video) SubRequired() *Video

SubRequired sets the requires_subscription option to 'yes'

Jump to

Keyboard shortcuts

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