{"id":20544390,"url":"https://github.com/sabloger/sitemap-generator","last_synced_at":"2025-04-14T09:52:29.939Z","repository":{"id":40386432,"uuid":"457340743","full_name":"sabloger/sitemap-generator","owner":"sabloger","description":"An awesome Go Sitemap generator module","archived":false,"fork":false,"pushed_at":"2024-07-22T12:19:37.000Z","size":72,"stargazers_count":36,"open_issues_count":1,"forks_count":13,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T23:11:19.775Z","etag":null,"topics":["go","golang","sitemap","sitemap-builder","sitemap-generator","sitemap-xml","xml"],"latest_commit_sha":null,"homepage":"","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/sabloger.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":"2022-02-09T12:02:26.000Z","updated_at":"2025-01-06T09:50:21.000Z","dependencies_parsed_at":"2024-06-19T22:49:46.229Z","dependency_job_id":"32c0dc05-1be3-4e34-95c8-30909d2395de","html_url":"https://github.com/sabloger/sitemap-generator","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabloger%2Fsitemap-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabloger%2Fsitemap-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabloger%2Fsitemap-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabloger%2Fsitemap-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sabloger","download_url":"https://codeload.github.com/sabloger/sitemap-generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860015,"owners_count":21173339,"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","golang","sitemap","sitemap-builder","sitemap-generator","sitemap-xml","xml"],"created_at":"2024-11-16T01:44:10.783Z","updated_at":"2025-04-14T09:52:29.915Z","avatar_url":"https://github.com/sabloger.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"sitemap-generator\n=================\n\n[![GoDoc](https://godoc.org/github.com/sabloger/sitemap-generator?status.svg)](https://godoc.org/github.com/sabloger/sitemap-generator)\n[![Go Report Card](https://goreportcard.com/badge/github.com/sabloger/sitemap-generator)](https://goreportcard.com/report/github.com/sabloger/sitemap-generator)\n\nA high-performance sitemap-generator Go module which is a comprehensive tool to create\nand manage sitemap_index and sitemap files in a beautiful way. :)\n\nPlease see http://www.sitemaps.org/ for description of sitemap contents.\n\n## Installation\nUse `go get`:\n\n`go get github.com/sabloger/sitemap-generator`\n\n# How to Use sitemap-generator\n\nYou can use the module in either Single-file sitemap or Multiple-files \nsitemaps with a sitemap_index file.\n\n### Single sitemap usage\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"github.com/sabloger/sitemap-generator/smg\"\n  \"log\"\n  \"time\"\n)\n\nfunc main() {\n  now := time.Now().UTC()\n\n  sm := smg.NewSitemap(true) // The argument is PrettyPrint which must be set on initializing\n  sm.SetName(\"single_sitemap\") // Optional\n  sm.SetHostname(\"https://www.example.com\")\n  sm.SetOutputPath(\"./some/path\")\n  sm.SetLastMod(\u0026now)\n  sm.SetCompress(false) // Default is true\n  sm.SetMaxURLsCount(25000) // Default maximum number of URLs in each file is 50,000 to break\n\n  // Adding URL items\n  err := sm.Add(\u0026smg.SitemapLoc{\n    Loc:        \"some/uri.html\",\n    LastMod:    \u0026now,\n    ChangeFreq: smg.Always,\n    Priority:   0.4,\n\t\tImages:     []*SitemapImage{{\"/path-to-image.jpg\"}, {\"/path-to-image-2.jpg\"}},\n  })\n  if err != nil {\n    log.Fatal(\"Unable to add SitemapLoc:\", err)\n  }\n\n  // Save func saves the xml files and returns more than one filename in case of split large files.\n  filenames, err := sm.Save()\n  if err != nil {\n    log.Fatal(\"Unable to Save Sitemap:\", err)\n  }\n  for i, filename := range filenames {\n    fmt.Println(\"file no.\", i+1, filename)\n  }\n}\n```\n`single_sitemap.xml` will look like:\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003curlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\u003e\n\u003curl\u003e\n  \u003cloc\u003ehttps://www.example.com/some/uri.html\u003c/loc\u003e\n  \u003clastmod\u003e2022-02-12T16:29:46.45013Z\u003c/lastmod\u003e\n  \u003cchangefreq\u003ealways\u003c/changefreq\u003e\n  \u003cpriority\u003e0.4\u003c/priority\u003e\n  \u003cimage:image\u003e\n    \u003cimage:loc\u003ehttps://www.example.com/path-to-image.jpg\u003c/image:loc\u003e\n  \u003c/image:image\u003e\n  \u003cimage:image\u003e\n    \u003cimage:loc\u003ehttps://www.example.com/path-to-image-2.jpg\u003c/image:loc\u003e\n  \u003c/image:image\u003e\n\u003c/url\u003e\n\u003c/urlset\u003e\n```\n\n\n### SitemapIndex usage\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"github.com/sabloger/sitemap-generator/smg\"\n  \"log\"\n  \"time\"\n)\n\nfunc main() {\n  now := time.Now().UTC()\n\n  smi := smg.NewSitemapIndex(true)\n  smi.SetCompress(false)\n  smi.SetSitemapIndexName(\"an_optional_name_for_sitemap_index\")\n  smi.SetHostname(\"https://www.example.com\")\n  smi.SetOutputPath(\"./sitemap_index_example/\")\n  smi.SetServerURI(\"/sitemaps/\") // Optional\n\n  smBlog := smi.NewSitemap()\n  smBlog.SetName(\"blog_sitemap\")\n  smBlog.SetLastMod(\u0026now)\n  err := smBlog.Add(\u0026smg.SitemapLoc{\n    Loc:        \"blog/post/1231\",\n    LastMod:    \u0026now,\n    ChangeFreq: smg.Weekly,\n    Priority:   0.8,\n  })\n  if err != nil {\n    log.Fatal(\"Unable to add SitemapLoc:\", err)\n  }\n\n  smNews := smi.NewSitemap()\n  smNews.SetLastMod(\u0026now)\n  err = smNews.Add(\u0026smg.SitemapLoc{\n    Loc:        \"news/2021-01-05/a-news-page\",\n    LastMod:    \u0026now,\n    ChangeFreq: smg.Weekly,\n    Priority:   1,\n  })\n  if err != nil {\n    log.Fatal(\"Unable to add SitemapLoc:\", err)\n  }\n\n  filename, err := smi.Save()\n  if err != nil {\n    log.Fatal(\"Unable to Save Sitemap:\", err)\n  }\n\n  // Pings the Search engines. default Google and Bing, But you can add any other ping URL's\n  // in this format: http://www.google.com/webmasters/tools/ping?sitemap=%s\n  smi.PingSearchEngines()\n\n  fmt.Println(\"sitemap_index file:\", filename)\n}\n```\nthe output directory will be like this:\n```\nsitemap_index_example\n├── an_optional_name_for_sitemap_index.xml\n├── blog_sitemap.xml\n└── sitemap2.xml\n```\n`an_optional_name_for_sitemap_index.xml` will look like:\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003csitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\u003e\n  \u003csitemap\u003e\n    \u003cloc\u003ehttps:/www.example.com/sitemaps/blog_sitemap.xml\u003c/loc\u003e\n    \u003clastmod\u003e2022-02-12T18:38:06.671183Z\u003c/lastmod\u003e\n  \u003c/sitemap\u003e\n  \u003csitemap\u003e\n    \u003cloc\u003ehttps:/www.example.com/sitemaps/sitemap2.xml\u003c/loc\u003e\n    \u003clastmod\u003e2022-02-12T18:38:06.671183Z\u003c/lastmod\u003e\n  \u003c/sitemap\u003e\n\u003c/sitemapindex\u003e\n```\n\n\n### Custom output buffer for Sitemap files\nIt is possible to write the `Sitemap` content into a custom output using this method:\n\n```go\n\n// Finalize must be called to make the content closed.\nsm.Finalize()\n\n// Needs an io.Writer interface\nbuf := bytes.Buffer{}\nn, err = sm.WriteTo(\u0026buf)\n```\n\n## TODO list\n- [x] Develop: add new functionalities:\n  - [x] Write the sitemap_index and sitemap files in xml format\n  - [x] Compress option\n  - [x] Break the sitemap xml file in case of exceeding \n    the sitemaps.org limits (50,000 urls OR 50MB uncompressed file)\n  - [x] Ability to set Sitemap uri on server to set on it's url in sitemap_index file\n  - [x] Ping search engines for sitemap_index\n  - [ ] Ping search engines for single sitemap\n  - [ ] Break the sitemap_index xml file in case of exceeding the sitemaps.org limits (50,000 urls OR 50MB uncompressed file)\n  - [x] Implement Sitemap.WriteTo for custom outputs.\n  - [ ] Implement SitemapIndex.WriteTo for custom outputs.\n  - [x] Ability to change maximum URLs number for each file.\n- [ ] Support: Additional content types:\n  - [ ] Video sitemaps\n  - [x] Image sitemaps\n  - [ ] News sitemaps\n  - [ ] Alternate Links\n- [ ] Module Stability:\n  - [x] Increase test coverage to more than %80. current coverage is: 86.3% of statements\n  - [x] Write tests for different usages.\n\n\n## LINKS\nGoDoc documentation:\nhttps://pkg.go.dev/github.com/sabloger/sitemap-generator\n\nGit repository:\nhttps://github.com/sabloger/sitemap-generator\n\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsabloger%2Fsitemap-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsabloger%2Fsitemap-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsabloger%2Fsitemap-generator/lists"}