• Stars
    star
    214
  • Rank 178,063 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created over 8 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

go-sitemap-generator is the easiest way to generate Sitemaps in Go

A go-sitemap-generator is the easiest way to generate Sitemaps in Go.

As of version 2.0.0, This Repo is available as a Go module.

GoDoc Build Status

package main

import (
	"github.com/ikeikeikeike/go-sitemap-generator/v2/stm"
)


func main() {
	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.Finalize().PingSearchEngines()
}

Then

$ go build

Installation (Legacy download instead of a Go module.)

$ go get gopkg.in/ikeikeikeike/go-sitemap-generator.v1/stm
$ go get gopkg.in/ikeikeikeike/go-sitemap-generator.v2/stm

Features

Current Features or To-Do

Getting Started

Setting concurrency

To disable concurrency, set number of CPUs to 1.

sm := stm.NewSitemap(1)

If you want to set max CPUs that are available, set number of CPUs <= 0.

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:

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

Pinging Search Engines

PingSearchEngines notifies search engines of changes once a sitemap has been generated or changed. The library will append Google and Bing to any engines passed in to the function.

sm.Finalize().PingSearchEngines()

If you want to add new search engine, you can pass that in to the function:

sm.Finalize().PingSearchEngines("http://newengine.com/ping?url=%s")

Options

// Your website's host name
sm.SetDefaultHost("http://www.example.com")

// The remote host where your sitemaps will be hosted
sm.SetSitemapsHost("http://s3.amazonaws.com/sitemap-generator/")

// The directory to write sitemaps to locally
sm.SetPublicPath("tmp/")

// Set this to a directory/path if you don't want to upload to the root of your `SitemapsHost`
sm.SetSitemapsPath("sitemaps/")

// Struct of `S3Adapter`
sm.SetAdapter(&stm.S3Adapter{Region: "ap-northeast-1", Bucket: "your-bucket", ACL: "public-read"})

// Change the output filename
sm.SetFilename("new_filename")

Upload sitemap to S3

Recently I disabled this module here.

package main

import (
	"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/ikeikeikeike/go-sitemap-generator/stm"
)

func main() {
	sm := stm.NewSitemap(1)
	sm.SetDefaultHost("http://example.com")
	sm.SetSitemapsPath("sitemap-generator") // default: public
	sm.SetSitemapsHost("http://s3.amazonaws.com/sitemap-generator/")
	sm.SetAdapter(&stm.S3Adapter{
		Region: "ap-northeast-1",
		Bucket: "your-bucket",
		ACL:    "public-read",
		Creds:  credentials.NewEnvCredentials(),
	})

	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.Finalize().PingSearchEngines()
}

News sitemaps

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"},
},},})

Look at Creating a Google News Sitemap as required.

Video sitemaps

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 as required.

Image sitemaps

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"}},
},},
})

Look at Image sitemaps as required.

Geo sitemaps

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

Couldn't find Geo sitemaps example, although it's similar to:

<url>
	<loc>/geos</loc>
	<geo:geo>
		<geo:format>kml</geo:format>
	</geo:geo>
</url>

Mobile sitemaps

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

Look at Feature phone sitemaps as required.

Full example

package main

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

func main() {
	sm := stm.NewSitemap(0)
	sm.SetDefaultHost("http://yourhost.com")
	sm.SetSitemapsHost("http://s3.amazonaws.com/sitemaps/")
	sm.SetSitemapsPath("sitemaps/")
	sm.SetFilename("anothername")
	sm.SetCompress(true)
	sm.SetVerbose(true)
	sm.SetAdapter(&stm.S3Adapter{Region: "ap-northeast-1", Bucket: "your-bucket"})

	sm.Create()

	sm.Add(stm.URL{{"loc", "/home"}, {"changefreq", "daily"}})

	sm.Add(stm.URL{{"loc", "/abouts"}, {"mobile", true}})

	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"},
	},},
	})

	sm.Finalize().PingSearchEngines("http://newengine.com/ping?url=%s")
}

Webserver example

package main

import (
	"log"
	"net/http"

	"github.com/ikeikeikeike/go-sitemap-generator/stm"
)

func buildSitemap() *stm.Sitemap {
	sm := stm.NewSitemap(1)
	sm.SetDefaultHost("http://example.com")

	sm.Create()
	sm.Add(stm.URL{{"loc", "/"}, {"changefreq", "daily"}})

	// Note: Do not call `sm.Finalize()` because it flushes
	// the underlying data structure from memory to disk.

	return sm
}

func main() {
	sm := buildSitemap()

	mux := http.NewServeMux()
	mux.HandleFunc("/sitemap.xml", func(w http.ResponseWriter, r *http.Request) {
		// Go's webserver automatically sets the correct `Content-Type` header.
		w.Write(sm.XMLContent())
		return
	})

	log.Fatal(http.ListenAndServe(":8080", mux))
}

Documentation

How to test.

Preparation:

$ go get github.com/clbanning/mxj

Run tests:

$ go test -v -cover -race ./...

Inspired by sitemap_generator

More Repositories

1

sitemap

Sitemap is the easiest way to generate Sitemaps in Elixir.
Elixir
104
star
2

phoenix_html_simplified_helpers

Some helpers for phoenix html( truncate, time_ago_in_words, number_with_delimiter, url_for, current_page? )
Elixir
31
star
3

beego-samples

auth
Go
28
star
4

esx

A client for the Elasticsearch with Ecto, written in Elixir
Elixir
27
star
5

tastypie-queryset-client

Client for Tastypie. Provide operation similar to the Django Model API .
Python
16
star
6

social-bookmark-counter-on-google-search

https://github.com/ikeikeikeike/bookmarkhub
JavaScript
14
star
7

exkanji

A Elixir library for translating between hiragana, katakana, romaji, kanji and sound. It uses Mecab.
Elixir
12
star
8

django-spine

Spine plugin for Django
Python
10
star
9

celery-tracker

Receive/Sending event tracking data for the celery.
Python
9
star
10

sitesx

A Phoenix SubDomainer which makes subdomain using DigitalOcean, Cloudflare, etc. API and contains convenient view helper interface along with Plug and Ecto.
Elixir
9
star
11

bing_translator

A simple Elixir interface to Bing's translation API.
Elixir
9
star
12

bookmarkhub

https://github.com/ikeikeikeike/social-bookmark-counter-on-google-search
CoffeeScript
9
star
13

fluent-plugin-gstore

Google Cloud Storage, Fluentd Plugin.
Ruby
8
star
14

exromaji

A Elixir library for translating between hiragana, katakana, romaji and sound.
Elixir
8
star
15

exfavicon

Elixir library for discovering favicons
Elixir
7
star
16

gopkg

thats convenient
Go
4
star
17

pongor

Go
3
star
18

scrapy-proxies

proxy utility
Python
3
star
19

python-eco

Python Eco Compiler
Python
3
star
20

cheapcdn

CDN Material
Go
3
star
21

django-impala-backend

Unofficial impala backend package for Django.
Python
3
star
22

common_device_detector

Detect devices that desktop, mobile, smartphone and tablet form User Agent.
Elixir
3
star
23

rsyslog-monitor

search In realtime - from a browser.
2
star
24

extoon

Elixir
2
star
25

scrivener_esx

pagination
Elixir
2
star
26

django-subcommand

Add sub command to The Django manage command.
Python
2
star
27

godic

Base code for Git based wiki like a Encyclopedia (named dic subdomain) service in japan.
CSS
2
star
28

exmail

Email Delivery, Admin, Analyzer For Marketing
Elixir
2
star
29

redisank

A common ranking system on Redis with Plug.
Elixir
2
star
30

gocore

This is common package powered by https://github.com/uber-go/dig dependency injection toolkit.
Go
2
star
31

cheapcdn-ansible

CDN Material
2
star
32

exantenna

Elixir
2
star
33

dotfiles

Python
2
star
34

wakaway

There're §Walker's Alias Method§ and §Weighted Choice§ that providing weighted random choice algorism in two ways.
Elixir
2
star
35

somequeue

Operate some queue system through sidekiq interface
Ruby
2
star
36

rdtype

Calling Redis Data Types in easily way.
Elixir
2
star
37

go-googleimages

Google Image Search API (Deprecated) for Go
Go
2
star
38

packer-ubuntu-12.04.3

For Virtualbox. Next: https://github.com/ikeikeikeike/vagrant-rbenv-virtualenv
Shell
2
star
39

beego-loggers

ses,mailcatcher
Go
1
star
40

hubot-sarcasmlink

Sarcasm link for hubot.
CoffeeScript
1
star
41

scrape-django-app

for example as a django application
Python
1
star
42

boot-ads-k8s

Shell
1
star
43

peerdrive

[WIP] Some of them synchronization by tiny code.
Go
1
star
44

vpn-mesh

Fuzzy VPN Mesh by tiny code.
Go
1
star
45

drone-rb

1
star
46

elle-k8s

Shell
1
star
47

prototype

Go
1
star
48

docker-bastion

Dockerfile
1
star
49

drone-py

Python
1
star
50

wrapped-maps-jquery

A jQuery plugin for Google maps api v3.
CoffeeScript
1
star
51

ikeikeikeike

1
star
52

clustertransport-base

Message passing based client(transport) on cluster systems.
Go
1
star
53

rust-gqls

Rust GraphQL MySQL Diesel
Rust
1
star
54

panglao-scraper

CDN Material
Python
1
star
55

panglao

Elixir
1
star
56

charneoapo

Go
1
star
57

shuffler

Go
1
star
58

boot-ads

Kotlin
1
star
59

lit-k8s

Shell
1
star
60

lit-terraform

HCL
1
star
61

speech_to_text_app

Dart
1
star
62

drone-ex

1
star
63

gocuration

Go
1
star
64

mad

scientist
Go
1
star
65

gocuration-api

Go
1
star
66

panglao-elixir

Client for panglao api
Elixir
1
star
67

go-scrap

Go
1
star
68

martini-contrib

thats convenient
Go
1
star
69

JapaneseTag

鬼
Objective-C
1
star
70

analytics-counter

Availability by Scrapy.
Python
1
star
71

ex_edited

Elixir
1
star
72

drone-scala

1
star
73

terraform-starterkit

HCL
1
star
74

scrapy-2ch-summary-spiders

heh
Python
1
star
75

vagrant-rbenv-virtualenv

Prev: https://github.com/ikeikeikeike/packer-ubuntu-12.04.3
Ruby
1
star
76

docker-sbt

1
star
77

cheapcdn-terraform

CDN Material
HCL
1
star
78

ansible-playbooks

my playbooks for Ubuntu
1
star
79

boot-ads-admin

Python
1
star
80

ikeikeikeike.github.com

posterous
1
star
81

rust-gql

Rust GraphQL MySQL Simple
Rust
1
star
82

Camotes-iOS

Swift
1
star
83

go-apiactress

apiactress for Go
Go
1
star
84

memdtest

There's golang for testing with memcached that concerns a own personally.
Go
1
star
85

coffee-serializers

Serializers for CoffeeScript.
CoffeeScript
1
star
86

elle-terraform

HCL
1
star
87

ddrive

1
star
88

seg-test

Dockerfile
1
star
89

seread-sample

1
star
90

encoding-base94

Radix Conversion
Go
1
star
91

my-deps

1
star
92

my-deps-pipenv

1
star
93

ansible-playbook

custom roles
Ruby
1
star
94

skeleton-web

npm typescript webworker
JavaScript
1
star
95

boot-ads-terraform

HCL
1
star
96

docker-golang

1
star
97

drone-go

1
star
98

eck-ja-small

cloud-on-k8s no password
1
star
99

exblur

its f
Elixir
1
star
100

template

Template for new projects.
Ruby
1
star