All Projects → ikeikeikeike → Go Sitemap Generator

ikeikeikeike / Go Sitemap Generator

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

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to Go Sitemap Generator

Domain hunter
A Burp Suite Extension that try to find all sub-domain, similar-domain and related-domain of an organization automatically! 基于流量自动收集整个企业或组织的子域名、相似域名、相关域名的burp插件
Stars: ✭ 594 (+290.79%)
Mutual labels:  sitemap
Dctb Links
My Personal Links
Stars: ✭ 65 (-57.24%)
Mutual labels:  sitemap
Laravel Seo Tools
Laravel Seo package for Content writer/admin/web master who do not know programming but want to edit/update SEO tags from dashboard
Stars: ✭ 99 (-34.87%)
Mutual labels:  sitemap
Jekyll Sitemap
Jekyll plugin to silently generate a sitemaps.org compliant sitemap for your Jekyll site
Stars: ✭ 782 (+414.47%)
Mutual labels:  sitemap
Templates Using Bootstrap4
🌆 Here I've aggregated some of the most commonly used web-page templates made using Bootstrap4 🛒
Stars: ✭ 60 (-60.53%)
Mutual labels:  sitemap
Gatsby Advanced Starter
A high performance skeleton starter for GatsbyJS that focuses on SEO/Social features/development environment.
Stars: ✭ 1,224 (+705.26%)
Mutual labels:  sitemap
Sitemap Module
Sitemap Module for Nuxt
Stars: ✭ 539 (+254.61%)
Mutual labels:  sitemap
Sitemap
PHP XML Sitemap Generation
Stars: ✭ 128 (-15.79%)
Mutual labels:  sitemap
Android Sitemap
👓 Every link ever to Android Developer site.
Stars: ✭ 61 (-59.87%)
Mutual labels:  sitemap
Laravel Sitemap
Create and generate sitemaps with ease
Stars: ✭ 1,325 (+771.71%)
Mutual labels:  sitemap
Yii2 Pages Module
Application sitemap and navigation manager module for Yii 2.0 Framework
Stars: ✭ 30 (-80.26%)
Mutual labels:  sitemap
Sitemap
Site map creation support
Stars: ✭ 59 (-61.18%)
Mutual labels:  sitemap
Laravel Sitemap
Laravelium Sitemap generator for Laravel.
Stars: ✭ 1,231 (+709.87%)
Mutual labels:  sitemap
Rust Full Stack
Rust projects here are easy to use. There are blog posts for them also.
Stars: ✭ 745 (+390.13%)
Mutual labels:  sitemap
Vue Router Sitemap
Generate sitemap.xml by vue-router configuration
Stars: ✭ 102 (-32.89%)
Mutual labels:  sitemap
Pup
The Ultimate Boilerplate for Products.
Stars: ✭ 563 (+270.39%)
Mutual labels:  sitemap
Sitemap.js
Sitemap-generating framework for node.js
Stars: ✭ 1,159 (+662.5%)
Mutual labels:  sitemap
Craft Seomatic
SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.
Stars: ✭ 135 (-11.18%)
Mutual labels:  sitemap
Craft Sitemap
Craft plugin to generate a sitemap.
Stars: ✭ 105 (-30.92%)
Mutual labels:  sitemap
Sitemap
Sitemap is the easiest way to generate Sitemaps in Elixir.
Stars: ✭ 90 (-40.79%)
Mutual labels:  sitemap

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].