Skip to content
Permalink
Browse files

bump update with merge v2

  • Loading branch information...
ikeikeikeike committed Mar 26, 2019
1 parent 6fe4386 commit 6c48d31ace563179f911128a4e8ed9ffa9d7b401
Showing with 372 additions and 284 deletions.
  1. +107 −74 README.md
  2. +2 −2 go.mod
  3. +2 −2 go.sum
  4. +34 −10 stm/builder.go
  5. +1 −1 stm/builder_file.go
  6. +1 −1 stm/builder_indexfile.go
  7. +4 −4 stm/builder_test.go
  8. +12 −3 stm/builder_url.go
  9. +103 −103 stm/builder_url_test.go
  10. +6 −2 stm/sitemap.go
  11. +4 −4 stm/sitemap_test.go
  12. +91 −73 stm/utils.go
  13. +5 −5 stm/utils_test.go
181 README.md
@@ -7,20 +7,20 @@
package main
import (
"github.com/ikeikeikeike/go-sitemap-generator/stm"
"github.com/ikeikeikeike/go-sitemap-generator/v2/stm"
)
func main() {
sm := stm.NewSitemap()
sm := stm.NewSitemap(1)
// Create method must be called first before adding entries to
// the sitemap.
sm.Create()
sm.Add(stm.URL{"loc": "home", "changefreq": "always", "mobile": true})
sm.Add(stm.URL{"loc": "readme"})
sm.Add(stm.URL{"loc": "aboutme", "priority": 0.1})
sm.Add(stm.URL{{"loc", "home"}, {"changefreq", "always"}, {"mobile", true}})
sm.Add(stm.URL{{"loc", "readme"}})
sm.Add(stm.URL{{"loc", "aboutme"}, {"priority", 0.1}})
sm.Finalize().PingSearchEngines()
}
@@ -29,7 +29,7 @@ func main() {
### Installation

```console
$ go get github.com/ikeikeikeike/go-sitemap-generator/stm
$ go get github.com/ikeikeikeike/go-sitemap-generator/v2/stm
```

### Features
@@ -54,13 +54,24 @@ Current Features or To-Do

## Getting Started

### Setting concurrency
To disable concurrency, set number of CPUs to 1.
```go
sm := stm.NewSitemap(1)
```

If you want to set max CPUs that are available, set number of CPUs <= 0.
```go
sm := stm.NewSitemap(0)
```

### Preventing Output

To disable all non-essential output you can set `sm.SetVerbose` to `false`.
To disable output inline use the following:

```go
sm := stm.NewSitemap()
sm := stm.NewSitemap(1)
sm.SetVerbose(false)
```

@@ -114,7 +125,7 @@ import (
)
func main() {
sm := stm.NewSitemap()
sm := stm.NewSitemap(1)
sm.SetDefaultHost("http://example.com")
sm.SetSitemapsPath("sitemap-generator") // default: public
sm.SetSitemapsHost("http://s3.amazonaws.com/sitemap-generator/")
@@ -127,9 +138,9 @@ func main() {
sm.Create()
sm.Add(stm.URL{"loc": "home", "changefreq": "always", "mobile": true})
sm.Add(stm.URL{"loc": "readme"})
sm.Add(stm.URL{"loc": "aboutme", "priority": 0.1})
sm.Add(stm.URL{{"loc", "home"}, {"changefreq", "always"}, {"mobile", true}})
sm.Add(stm.URL{{"loc", "readme"}})
sm.Add(stm.URL{{"loc", "aboutme"}, {"priority", 0.1}})
sm.Finalize().PingSearchEngines()
}
@@ -138,45 +149,55 @@ func main() {
### News sitemaps

```go
sm.Add(stm.URL{"loc": "/news", "news": stm.URL{
"publication": stm.URL{
"name": "Example",
"language": "en",
sm.Add(stm.URL{
{"loc", "/news"},
{"news", stm.URL{
{"publication", stm.URL{
{"name", "Example"},
{"language", "en"},
},
},
"title": "My Article",
"keywords": "my article, articles about myself",
"stock_tickers": "SAO:PETR3",
"publication_date": "2011-08-22",
"access": "Subscription",
"genres": "PressRelease",
}})
{"title", "My Article"},
{"keywords", "my article, articles about myself"},
{"stock_tickers", "SAO:PETR3"},
{"publication_date", "2011-08-22"},
{"access", "Subscription"},
{"genres", "PressRelease"},
},},})
```

Look at [Creating a Google News Sitemap](https://support.google.com/news/publisher/answer/74288) as required.

### Video sitemaps

```go
sm.Add(stm.URL{"loc": "/videos", "video": stm.URL{
"thumbnail_loc": "http://www.example.com/video1_thumbnail.png",
"title": "Title",
"description": "Description",
"content_loc": "http://www.example.com/cool_video.mpg",
"category": "Category",
"tag": []string{"one", "two", "three"},
"player_loc": stm.Attrs{"https://example.com/p/flash/moogaloop/6.2.9/moogaloop.swf?clip_id=26", map[string]string{"allow_embed": "Yes", "autoplay": "autoplay=1"}},
}})
sm.Add(stm.URL{
{"loc", "/videos"},
{"video", stm.URL{
{"thumbnail_loc", "http://www.example.com/video1_thumbnail.png"},
{"title", "Title"},
{"description", "Description"},
{"content_loc", "http://www.example.com/cool_video.mpg"},
{"category", "Category"},
{"tag", []string{"one", "two", "three"}},
{"player_loc", stm.Attrs{"https://example.com/p/flash/moogaloop/6.2.9/moogaloop.swf?clip_id=26", map[string]string{"allow_embed": "Yes", "autoplay": "autoplay=1"}},},
},
},
})
```

Look at [Video sitemaps](https://support.google.com/webmasters/answer/80471) as required.

### Image sitemaps

```go
sm.Add(stm.URL{"loc": "/images", "image": []stm.URL{
{"loc": "http://www.example.com/image.png", "title": "Image"},
{"loc": "http://www.example.com/image1.png", "title": "Image1"},
}})
sm.Add(stm.URL{
{"loc", "/images"},
{"image", []stm.URL{
{{"loc", "http://www.example.com/image.png"}, {"title", "Image"}},
{{"loc", "http://www.example.com/image1.png"}, {"title", "Image1"}},
},},
})
```

@@ -185,9 +206,12 @@ Look at [Image sitemaps](https://support.google.com/webmasters/answer/178636) as
### Geo sitemaps

```go
sm.Add(stm.URL{"loc": "/geos", "geo": stm.URL{
"format": "kml",
}})
sm.Add(stm.URL{
{"loc", "/geos"},
{"geo", stm.URL{
{"format", "kml"},
},},
})
```

Couldn't find Geo sitemaps example, although it's similar to:
@@ -204,7 +228,7 @@ Couldn't find Geo sitemaps example, although it's similar to:
### Mobile sitemaps

```go
sm.Add(stm.URL{"loc": "mobiles", "mobile": true})
sm.Add(stm.URL{{"loc", "mobiles"}, {"mobile", true}})
```

Look at [Feature phone sitemaps](https://support.google.com/webmasters/answer/6082207) as required.
@@ -220,7 +244,7 @@ import (
)
func main() {
sm := stm.NewSitemap()
sm := stm.NewSitemap(0)
sm.SetDefaultHost("http://yourhost.com")
sm.SetSitemapsHost("http://s3.amazonaws.com/sitemaps/")
sm.SetSitemapsPath("sitemaps/")
@@ -231,41 +255,50 @@ func main() {
sm.Create()
sm.Add(stm.URL{"loc": "/home", "changefreq": "daily"})
sm.Add(stm.URL{{"loc", "/home"}, {"changefreq", "daily"}})
sm.Add(stm.URL{"loc": "/abouts", "mobile": true})
sm.Add(stm.URL{{"loc", "/abouts"}, {"mobile", true}})
sm.Add(stm.URL{"loc": "/news", "news": stm.URL{
"publication": stm.URL{
"name": "Example",
"language": "en",
sm.Add(stm.URL{{"loc", "/news"},
{"news", stm.URL{
{"publication", stm.URL{
{"name", "Example"},
{"language", "en"},
},
"title": "My Article",
"keywords": "my article, articles about myself",
"stock_tickers": "SAO:PETR3",
"publication_date": "2011-08-22",
"access": "Subscription",
"genres": "PressRelease",
}})
sm.Add(stm.URL{"loc": "/images", "image": []stm.URL{
{"loc": "http://www.example.com/image.png", "title": "Image"},
{"loc": "http://www.example.com/image1.png", "title": "Image1"},
}})
sm.Add(stm.URL{"loc": "/videos", "video": stm.URL{
"thumbnail_loc": "http://www.example.com/video1_thumbnail.png",
"title": "Title",
"description": "Description",
"content_loc": "http://www.example.com/cool_video.mpg",
"category": "Category",
"tag": []string{"one", "two", "three"},
"player_loc": stm.Attrs{"https://example.com/p/flash/moogaloop/6.2.9/moogaloop.swf?clip_id=26", map[string]string{"allow_embed": "Yes", "autoplay": "autoplay=1"}},
}})
sm.Add(stm.URL{"loc": "/geos", "geo": stm.URL{
"format": "kml",
}})
},
{"title", "My Article"},
{"keywords", "my article, articles about myself"},
{"stock_tickers", "SAO:PETR3"},
{"publication_date", "2011-08-22"},
{"access", "Subscription"},
{"genres", "PressRelease"},
},},
})
sm.Add(stm.URL{{"loc", "/images"},
{"image", []stm.URL{
{{"loc", "http://www.example.com/image.png"}, {"title", "Image"}},
{{"loc", "http://www.example.com/image1.png"}, {"title", "Image1"}},
},},
})
sm.Add(stm.URL{{"loc", "/videos"},
{"video", stm.URL{
{"thumbnail_loc", "http://www.example.com/video1_thumbnail.png"},
{"title", "Title"},
{"description", "Description"},
{"content_loc", "http://www.example.com/cool_video.mpg"},
{"category", "Category"},
{"tag", []string{"one", "two", "three"}},
{"player_loc", stm.Attrs{"https://example.com/p/flash/moogaloop/6.2.9/moogaloop.swf?clip_id=26", map[string]string{"allow_embed": "Yes", "autoplay": "autoplay=1"}}},
},},
})
sm.Add(stm.URL{{"loc", "/geos"},
{"geo", stm.URL{
{"format", "kml"},
},},
})
sm.Finalize().PingSearchEngines("http://newengine.com/ping?url=%s")
}
@@ -285,11 +318,11 @@ import (
)
func buildSitemap() *stm.Sitemap {
sm := stm.NewSitemap()
sm := stm.NewSitemap(1)
sm.SetDefaultHost("http://example.com")
sm.Create()
sm.Add(stm.URL{"loc": "/", "changefreq": "daily"})
sm.Add(stm.URL{{"loc", "/"}, {"changefreq", "daily"}})
// Note: Do not call `sm.Finalize()` because it flushes
// the underlying data structure from memory to disk.
4 go.mod
@@ -1,9 +1,9 @@
module github.com/ikeikeikeike/go-sitemap-generator
module github.com/ikeikeikeike/go-sitemap-generator/v2

go 1.9

require (
github.com/beevik/etree v1.1.0
github.com/clbanning/mxj v1.8.3
github.com/fatih/structs v1.1.0
github.com/imdario/mergo v0.3.7
)
4 go.sum
@@ -1,6 +1,6 @@
github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/clbanning/mxj v1.8.3 h1:2r/KCJi52w2MRz+K+UMa/1d7DdCjnLqYJfnbr7dYNWI=
github.com/clbanning/mxj v1.8.3/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI=
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
@@ -1,8 +1,6 @@
package stm

import (
"fmt"
)
import "fmt"

var poolBuffer = NewBufferPool()

@@ -32,16 +30,29 @@ type Attrs []interface{}
type Attr map[string]string

// URL User should use this typedef in main func.
type URL map[string]interface{}
type URL [][]interface{}

// URLJoinBy that's convenient.
func (u URL) URLJoinBy(key string, joins ...string) URL {
var values []string
for _, k := range joins {
values = append(values, fmt.Sprint(u[k]))
var vals interface{}
for _, v := range u {
if v[0] == k {
vals = v[1]
break
}
}
values = append(values, fmt.Sprint(vals))
}

u[key] = URLJoin("", values...)
var index int
var v []interface{}
for index, v = range u {
if v[0] == key {
break
}
}
u[index][1] = URLJoin("", values...)
return u
}

@@ -51,10 +62,23 @@ func (u *URL) BungURLJoinBy(key string, joins ...string) {

var values []string
for _, k := range joins {
values = append(values, fmt.Sprint(orig[k]))
var vals interface{}
for _, v := range *u {
if v[0] == k {
vals = v[1]
break
}
}
values = append(values, fmt.Sprint(vals))
}

orig[key] = URLJoin("", values...)
var index int
var v []interface{}
for index, v = range *u {
if v[0] == key {
break
}
}
orig[index][1] = URLJoin("", values...)
*u = orig
}

@@ -35,7 +35,7 @@ type BuilderFile struct {
// Add method joins old bytes with creates bytes by it calls from Sitemap.Add method.
func (b *BuilderFile) Add(url interface{}) BuilderError {
u := MergeMap(url.(URL),
URL{"host": b.loc.opts.defaultHost},
URL{{"host", b.loc.opts.defaultHost}},
)

b.linkcnt++

0 comments on commit 6c48d31

Please sign in to comment.
You can’t perform that action at this time.