{"id":13601498,"url":"https://github.com/ikeikeikeike/go-sitemap-generator","last_synced_at":"2025-12-15T14:23:02.079Z","repository":{"id":45282449,"uuid":"44119517","full_name":"ikeikeikeike/go-sitemap-generator","owner":"ikeikeikeike","description":"go-sitemap-generator is the easiest way to generate Sitemaps in Go","archived":false,"fork":false,"pushed_at":"2024-07-10T14:39:48.000Z","size":131,"stargazers_count":225,"open_issues_count":29,"forks_count":66,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T15:08:10.859Z","etag":null,"topics":["go","sitemap","sitemap-generator"],"latest_commit_sha":null,"homepage":"https://github.com/ikeikeikeike/go-sitemap-generator","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ikeikeikeike.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-12T16:23:13.000Z","updated_at":"2025-03-03T10:22:54.000Z","dependencies_parsed_at":"2024-06-18T13:31:39.556Z","dependency_job_id":"50ea2277-0dec-4fc1-b8e3-6fb4ffb4331a","html_url":"https://github.com/ikeikeikeike/go-sitemap-generator","commit_stats":{"total_commits":128,"total_committers":11,"mean_commits":"11.636363636363637","dds":0.1171875,"last_synced_commit":"c473e35ca5f0ce3059e2417fa95959adfd3428ce"},"previous_names":["ikeikeikeike/stmg"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikeikeikeike%2Fgo-sitemap-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikeikeikeike%2Fgo-sitemap-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikeikeikeike%2Fgo-sitemap-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikeikeikeike%2Fgo-sitemap-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ikeikeikeike","download_url":"https://codeload.github.com/ikeikeikeike/go-sitemap-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208190,"owners_count":20901570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","sitemap","sitemap-generator"],"created_at":"2024-08-01T18:01:03.632Z","updated_at":"2025-12-15T14:22:57.027Z","avatar_url":"https://github.com/ikeikeikeike.png","language":"Go","funding_links":[],"categories":["Utilities","Go","工具库`可以提升效率的通用代码库和工具`","工具库","实用工具","公用事业公司","Utility"],"sub_categories":["Utility/Miscellaneous","Fail injection","查询语","HTTP Clients","交流","Advanced Console UIs","实用程序/Miscellaneous","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"\nA go-sitemap-generator is the easiest way to generate Sitemaps in Go.\n\nAs of version 2.0.0, This Repo is available as a [Go module](https://github.com/golang/go/wiki/Modules).\n\n\n[![GoDoc](https://godoc.org/github.com/ikeikeikeike/go-sitemap-generator/stm?status.svg)](https://godoc.org/github.com/ikeikeikeike/go-sitemap-generator/stm) [![Build Status](https://travis-ci.org/ikeikeikeike/go-sitemap-generator.svg)](https://travis-ci.org/ikeikeikeike/go-sitemap-generator)\n\n```go\npackage main\n\nimport (\n\t\"github.com/ikeikeikeike/go-sitemap-generator/v2/stm\"\n)\n\n\nfunc main() {\n\tsm := stm.NewSitemap(1)\n\n\t// Create method must be called first before adding entries to\n\t// the sitemap.\n\tsm.Create()\n\n\tsm.Add(stm.URL{{\"loc\", \"home\"}, {\"changefreq\", \"always\"}, {\"mobile\", true}})\n\tsm.Add(stm.URL{{\"loc\", \"readme\"}})\n\tsm.Add(stm.URL{{\"loc\", \"aboutme\"}, {\"priority\", 0.1}})\n\n\tsm.Finalize().PingSearchEngines()\n}\n```\n\nThen\n\n```console\n$ go build\n```\n\n#### Installation (Legacy download instead of a [Go module](https://github.com/golang/go/wiki/Modules).)\n\n```console\n$ go get gopkg.in/ikeikeikeike/go-sitemap-generator.v1/stm\n$ go get gopkg.in/ikeikeikeike/go-sitemap-generator.v2/stm\n```\n\n### Features\n\nCurrent Features or To-Do\n\n- [ ] Supports: generate kind of some sitemaps.\n  - [x] [News sitemaps](#news-sitemaps)\n  - [x] [Video sitemaps](#video-sitemaps)\n  - [x] [Image sitemaps](#image-sitemaps)\n  - [x] [Geo sitemaps](#geo-sitemaps)\n  - [x] [Mobile sitemaps](#mobile-sitemaps)\n  - [ ] PageMap sitemap\n  - [x] Alternate Links\n- [ ] Supports: adapters for sitemap storage.\n  - [x] Filesystem\n  - [x] [S3](#upload-sitemap-to-s3)\n- [x] [Customizable sitemap working](#preventing-output)\n- [x] [Notifies search engines (Google, Bing) of new sitemaps](#pinging-search-engines)\n- [x] [Gives you complete control over your sitemap contents and naming scheme](#full-example)\n\n\n## Getting Started\n\n### Setting concurrency\nTo disable concurrency, set number of CPUs to 1.\n```go\nsm := stm.NewSitemap(1)\n```\n\nIf you want to set max CPUs that are available, set number of CPUs \u003c= 0.\n```go\nsm := stm.NewSitemap(0)\n```\n\n### Preventing Output\n\nTo disable all non-essential output you can set `sm.SetVerbose` to `false`.\nTo disable output inline use the following:\n\n```go\nsm := stm.NewSitemap(1)\nsm.SetVerbose(false)\n```\n\n### Pinging Search Engines\n\nPingSearchEngines notifies search engines of changes once a sitemap\nhas been generated or changed. The library will append Google and Bing to any engines passed in to the function.\n\n```go\nsm.Finalize().PingSearchEngines()\n```\n\nIf you want to add `new search engine`, you can pass that in to the function:\n\n```go\nsm.Finalize().PingSearchEngines(\"http://newengine.com/ping?url=%s\")\n```\n\n### Options\n\n```go\n// Your website's host name\nsm.SetDefaultHost(\"http://www.example.com\")\n\n// The remote host where your sitemaps will be hosted\nsm.SetSitemapsHost(\"http://s3.amazonaws.com/sitemap-generator/\")\n\n// The directory to write sitemaps to locally\nsm.SetPublicPath(\"tmp/\")\n\n// Set this to a directory/path if you don't want to upload to the root of your `SitemapsHost`\nsm.SetSitemapsPath(\"sitemaps/\")\n\n// Struct of `S3Adapter`\nsm.SetAdapter(\u0026stm.S3Adapter{Region: \"ap-northeast-1\", Bucket: \"your-bucket\", ACL: \"public-read\"})\n\n// Change the output filename\nsm.SetFilename(\"new_filename\")\n```\n\n### Upload sitemap to S3\n\nRecently I disabled this module [here](https://github.com/ikeikeikeike/go-sitemap-generator/blob/master/stm/_adapter_s3.go).\n\n```go\npackage main\n\nimport (\n\t\"github.com/aws/aws-sdk-go/aws/credentials\"\n\t\"github.com/ikeikeikeike/go-sitemap-generator/stm\"\n)\n\nfunc main() {\n\tsm := stm.NewSitemap(1)\n\tsm.SetDefaultHost(\"http://example.com\")\n\tsm.SetSitemapsPath(\"sitemap-generator\") // default: public\n\tsm.SetSitemapsHost(\"http://s3.amazonaws.com/sitemap-generator/\")\n\tsm.SetAdapter(\u0026stm.S3Adapter{\n\t\tRegion: \"ap-northeast-1\",\n\t\tBucket: \"your-bucket\",\n\t\tACL:    \"public-read\",\n\t\tCreds:  credentials.NewEnvCredentials(),\n\t})\n\n\tsm.Create()\n\n\tsm.Add(stm.URL{{\"loc\", \"home\"}, {\"changefreq\", \"always\"}, {\"mobile\", true}})\n\tsm.Add(stm.URL{{\"loc\", \"readme\"}})\n\tsm.Add(stm.URL{{\"loc\", \"aboutme\"}, {\"priority\", 0.1}})\n\n\tsm.Finalize().PingSearchEngines()\n}\n```\n\n### News sitemaps\n\n```go\nsm.Add(stm.URL{\n\t{\"loc\", \"/news\"},\n\t{\"news\", stm.URL{\n\t{\"publication\", stm.URL{\n\t\t{\"name\",     \"Example\"},\n\t\t{\"language\", \"en\"},\n\t},\n\t},\n\t{\"title\",            \"My Article\"},\n\t{\"keywords\",         \"my article, articles about myself\"},\n\t{\"stock_tickers\",    \"SAO:PETR3\"},\n\t{\"publication_date\", \"2011-08-22\"},\n\t{\"access\",           \"Subscription\"},\n\t{\"genres\",           \"PressRelease\"},\n},},})\n```\n\nLook at [Creating a Google News Sitemap](https://support.google.com/news/publisher/answer/74288) as required.\n\n### Video sitemaps\n\n```go\nsm.Add(stm.URL{\n\t{\"loc\", \"/videos\"},\n\t{\"video\", stm.URL{\n\t{\"thumbnail_loc\", \"http://www.example.com/video1_thumbnail.png\"},\n\t{\"title\",         \"Title\"},\n\t{\"description\",   \"Description\"},\n\t{\"content_loc\",   \"http://www.example.com/cool_video.mpg\"},\n\t{\"category\",      \"Category\"},\n\t{\"tag\",           []string{\"one\", \"two\", \"three\"}},\n    {\"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\"}},},\n},\n},\n})\n```\n\nLook at [Video sitemaps](https://support.google.com/webmasters/answer/80471) as required.\n\n### Image sitemaps\n\n```go\nsm.Add(stm.URL{\n\t{\"loc\", \"/images\"},\n\t{\"image\", []stm.URL{\n\t{{\"loc\", \"http://www.example.com/image.png\"}, {\"title\", \"Image\"}},\n\t{{\"loc\", \"http://www.example.com/image1.png\"}, {\"title\", \"Image1\"}},\n},},\n})\n\n```\n\nLook at [Image sitemaps](https://support.google.com/webmasters/answer/178636) as required.\n\n### Geo sitemaps\n\n```go\nsm.Add(stm.URL{\n\t{\"loc\", \"/geos\"},\n\t{\"geo\", stm.URL{\n\t{\"format\", \"kml\"},\n},},\n})\n```\n\nCouldn't find Geo sitemaps example, although it's similar to:\n\n```xml\n\u003curl\u003e\n\t\u003cloc\u003e/geos\u003c/loc\u003e\n\t\u003cgeo:geo\u003e\n\t\t\u003cgeo:format\u003ekml\u003c/geo:format\u003e\n\t\u003c/geo:geo\u003e\n\u003c/url\u003e\n```\n\n### Mobile sitemaps\n\n```go\nsm.Add(stm.URL{{\"loc\", \"mobiles\"}, {\"mobile\", true}})\n```\n\nLook at [Feature phone sitemaps](https://support.google.com/webmasters/answer/6082207) as required.\n\n\n### Full example\n\n```go\npackage main\n\nimport (\n\t\"github.com/ikeikeikeike/go-sitemap-generator/stm\"\n)\n\nfunc main() {\n\tsm := stm.NewSitemap(0)\n\tsm.SetDefaultHost(\"http://yourhost.com\")\n\tsm.SetSitemapsHost(\"http://s3.amazonaws.com/sitemaps/\")\n\tsm.SetSitemapsPath(\"sitemaps/\")\n\tsm.SetFilename(\"anothername\")\n\tsm.SetCompress(true)\n\tsm.SetVerbose(true)\n\tsm.SetAdapter(\u0026stm.S3Adapter{Region: \"ap-northeast-1\", Bucket: \"your-bucket\"})\n\n\tsm.Create()\n\n\tsm.Add(stm.URL{{\"loc\", \"/home\"}, {\"changefreq\", \"daily\"}})\n\n\tsm.Add(stm.URL{{\"loc\", \"/abouts\"}, {\"mobile\", true}})\n\n\tsm.Add(stm.URL{{\"loc\", \"/news\"},\n\t{\"news\", stm.URL{\n\t\t{\"publication\", stm.URL{\n\t\t\t{\"name\",     \"Example\"},\n\t\t\t{\"language\", \"en\"},\n\t\t},\n\t\t},\n\t\t{\"title\",            \"My Article\"},\n\t\t{\"keywords\",         \"my article, articles about myself\"},\n\t\t{\"stock_tickers\",    \"SAO:PETR3\"},\n\t\t{\"publication_date\", \"2011-08-22\"},\n\t\t{\"access\",           \"Subscription\"},\n\t\t{\"genres\",           \"PressRelease\"},\n\t},},\n\t})\n\n\tsm.Add(stm.URL{{\"loc\", \"/images\"},\n\t{\"image\", []stm.URL{\n\t\t{{\"loc\", \"http://www.example.com/image.png\"}, {\"title\", \"Image\"}},\n\t\t{{\"loc\", \"http://www.example.com/image1.png\"}, {\"title\", \"Image1\"}},\n\t},},\n\t})\n\n\tsm.Add(stm.URL{{\"loc\", \"/videos\"},\n\t{\"video\", stm.URL{\n\t\t{\"thumbnail_loc\", \"http://www.example.com/video1_thumbnail.png\"},\n\t\t{\"title\",         \"Title\"},\n\t\t{\"description\",   \"Description\"},\n\t\t{\"content_loc\",   \"http://www.example.com/cool_video.mpg\"},\n\t\t{\"category\",      \"Category\"},\n\t\t{\"tag\",           []string{\"one\", \"two\", \"three\"}},\n\t    {\"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\"}}},\n\t},},\n\t})\n\n\tsm.Add(stm.URL{{\"loc\", \"/geos\"},\n\t{\"geo\", stm.URL{\n\t\t{\"format\", \"kml\"},\n\t},},\n\t})\n\n\tsm.Finalize().PingSearchEngines(\"http://newengine.com/ping?url=%s\")\n}\n```\n\n### Webserver example\n\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/ikeikeikeike/go-sitemap-generator/stm\"\n)\n\nfunc buildSitemap() *stm.Sitemap {\n\tsm := stm.NewSitemap(1)\n\tsm.SetDefaultHost(\"http://example.com\")\n\n\tsm.Create()\n\tsm.Add(stm.URL{{\"loc\", \"/\"}, {\"changefreq\", \"daily\"}})\n\n\t// Note: Do not call `sm.Finalize()` because it flushes\n\t// the underlying data structure from memory to disk.\n\n\treturn sm\n}\n\nfunc main() {\n\tsm := buildSitemap()\n\n\tmux := http.NewServeMux()\n\tmux.HandleFunc(\"/sitemap.xml\", func(w http.ResponseWriter, r *http.Request) {\n\t\t// Go's webserver automatically sets the correct `Content-Type` header.\n\t\tw.Write(sm.XMLContent())\n\t\treturn\n\t})\n\n\tlog.Fatal(http.ListenAndServe(\":8080\", mux))\n}\n```\n\n\n### Documentation\n\n- [API Reference](https://godoc.org/github.com/ikeikeikeike/go-sitemap-generator/stm)\n- [sitemap_generator](http://github.com/kjvarga/sitemap_generator)\n\n### How to test.\n\nPreparation:\n\n```console\n$ go get github.com/clbanning/mxj\n```\n\nRun tests:\n\n```console\n$ go test -v -cover -race ./...\n```\n\n#### Inspired by [sitemap_generator](http://github.com/kjvarga/sitemap_generator)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikeikeikeike%2Fgo-sitemap-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fikeikeikeike%2Fgo-sitemap-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikeikeikeike%2Fgo-sitemap-generator/lists"}