• Stars
    star
    217
  • Rank 182,446 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created about 9 years ago
  • Updated 5 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
28
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
13
star
8

sitesx

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

django-spine

Spine plugin for Django
Python
10
star
10

bing_translator

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

celery-tracker

Receive/Sending event tracking data for the celery.
Python
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

pongor

Go
4
star
17

gopkg

thats convenient
Go
4
star
18

scrivener_esx

pagination
Elixir
3
star
19

scrapy-proxies

proxy utility
Python
3
star
20

python-eco

Python Eco Compiler
Python
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

cheapcdn

CDN Material
Go
3
star
24

rsyslog-monitor

search In realtime - from a browser.
2
star
25

gocore

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

extoon

Elixir
2
star
27

django-subcommand

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

wakaway

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

godic

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

exmail

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

redisank

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

cheapcdn-ansible

CDN Material
2
star
33

exantenna

Elixir
2
star
34

dotfiles

Python
2
star
35

rdtype

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

somequeue

Operate some queue system through sidekiq interface
Ruby
2
star
37

packer-ubuntu-12.04.3

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

go-googleimages

Google Image Search API (Deprecated) for Go
Go
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

docker-bastion

Dockerfile
1
star
48

drone-py

Python
1
star
49

wrapped-maps-jquery

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

prototype

Go
1
star
51

ikeikeikeike

1
star
52

speech-to-text

Dockerfile
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

clustertransport-base

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

boot-ads

Kotlin
1
star
60

lit-k8s

Shell
1
star
61

lit-terraform

HCL
1
star
62

speech_to_text_app

Dart
1
star
63

drone-ex

1
star
64

gocuration

Go
1
star
65

mad

scientist
Go
1
star
66

gocuration-api

Go
1
star
67

panglao-elixir

Client for panglao api
Elixir
1
star
68

go-scrap

Go
1
star
69

JapaneseTag

鬼
Objective-C
1
star
70

analytics-counter

Availability by Scrapy.
Python
1
star
71

martini-contrib

thats convenient
Go
1
star
72

ex_edited

Elixir
1
star
73

drone-scala

1
star
74

scrapy-2ch-summary-spiders

heh
Python
1
star
75

docker-sbt

1
star
76

terraform-starterkit

HCL
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

vectags

for virtual environment.
JavaScript
1
star
82

rust-gql

Rust GraphQL MySQL Simple
Rust
1
star
83

Camotes-iOS

Swift
1
star
84

go-apiactress

apiactress for Go
Go
1
star
85

coffee-serializers

Serializers for CoffeeScript.
CoffeeScript
1
star
86

memdtest

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

elle-terraform

HCL
1
star
88

ddrive

1
star
89

seg-test

Dockerfile
1
star
90

seread-sample

1
star
91

encoding-base94

Radix Conversion
Go
1
star
92

my-deps

1
star
93

my-deps-pipenv

1
star
94

ansible-playbook

custom roles
Ruby
1
star
95

skeleton-web

npm typescript webworker
JavaScript
1
star
96

boot-ads-terraform

HCL
1
star
97

docker-golang

1
star
98

drone-go

1
star
99

eck-ja-small

cloud-on-k8s no password
1
star
100

exblur

its f
Elixir
1
star