{"id":15699073,"url":"https://github.com/amannn/multi-sitemap","last_synced_at":"2025-05-09T02:21:20.052Z","repository":{"id":28012525,"uuid":"115204994","full_name":"amannn/multi-sitemap","owner":"amannn","description":"Painless creation of large dynamic sitemaps that consist of multiple files","archived":false,"fork":false,"pushed_at":"2022-01-30T10:42:13.000Z","size":236,"stargazers_count":6,"open_issues_count":13,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T21:43:18.892Z","etag":null,"topics":["express","nodejs","sitemap"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/amannn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-23T15:40:30.000Z","updated_at":"2024-07-10T08:50:53.000Z","dependencies_parsed_at":"2022-08-07T13:01:28.653Z","dependency_job_id":null,"html_url":"https://github.com/amannn/multi-sitemap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amannn%2Fmulti-sitemap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amannn%2Fmulti-sitemap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amannn%2Fmulti-sitemap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amannn%2Fmulti-sitemap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amannn","download_url":"https://codeload.github.com/amannn/multi-sitemap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253176668,"owners_count":21866185,"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":["express","nodejs","sitemap"],"created_at":"2024-10-03T19:38:04.649Z","updated_at":"2025-05-09T02:21:20.031Z","avatar_url":"https://github.com/amannn.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# multi-sitemap\n\nPainless creation of large dynamic sitemaps that consist of multiple files.\n\n## Features\n - Supports generating sitemaps from **dynamic data**: e.g. generating a sitemap for all entities in a paginated REST endpoint.\n - Automatically splits sitemaps into **chunks of 50k** entries to comply to the [Google guidelines](https://support.google.com/webmasters/answer/183668#sitemapformat).\n - Pluggable writers: Use `SitemapWriterXml`, `SitemapWriterTxt` or build your own (e.g. create a sitemap at a remote static file host).\n - Utilizes **streams**, so large amounts of data can be processed without memory issues.\n - Built with **TypeScript** so consumers can take advantage of types.\n\n## Usage\n\n```js\nimport {SitemapProcessor, SitemapWriterXml} from 'multi-sitemap';\n\n(async () =\u003e {\n  const processor = new SitemapProcessor({\n    // The domain where the sitemap is hosted. A sitemap is\n    // required to include a full URL including the host.\n    publicHost: 'https://domain.tld',\n\n    // The public path on the host where the sitemap can be\n    // found. This will be concatenated with `publicHost`.\n    publicDirectory: '/sitemap',\n\n    // One of the pluggable writers.\n    writer: new SitemapWriterXml({directory: './static/sitemap'});\n  });\n\n  await processor.addStatic({\n    name: 'pages',\n    entries: ['/', '/about']\n  });\n\n  await processor.addDynamic({\n    name: 'products',\n    reader: new SitemapProductsReader()\n  });\n\n  await processor.addIndex();\n})();\n```\n\nAll methods of `SitemapProcessor` return promises that should be waited for before calling other methods. The `addIndex` method should be called last, as this is the time the processor knows about all child sitemaps.\n\n## Adding dynamic data\n\nCreate a reader class that implements the following interface:\n\n```ts\ninterface ISitemapReader {\n  hasNext(): boolean;\n  getNext(): Promise\u003cSitemapEntryConfig[]\u003e;\n}\n\n// Given the following types:\n\ntype SitemapEntryConfig = /* url */ string | ISitemapEntry;\n\ninterface ISitemapEntry {\n  url: string;\n  lastModified?: Date;\n  changeFrequency?:\n    | 'always'\n    | 'hourly'\n    | 'daily'\n    | 'weekly'\n    | 'monthly'\n    | 'yearly'\n    | 'never';\n  priority?: number;\n}\n```\n\nAn instance of such a class can be passed to the sitemap processor. An example would be:\n\n```js\n/**\n * Fetches 7 pages of products, each consisting\n * of 20 entities that are written to a sitemap.\n */\nclass SitemapProductsReader {\n  i = 0;\n\n  hasNext() {\n    return this.i \u003c 7;\n  }\n\n  getNext() {\n    const size = 20;\n    const offset = this.i * size;\n\n    this.i++;\n\n    return fetch(`/api/products?offset=${offset}\u0026size=${size}`)\n      .then(products =\u003e products.map(product =\u003e `/products/${product.id}`))\n  }\n}\n\nprocessor.addDynamic({\n  name: 'products',\n  reader: new SitemapProductsReader()\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famannn%2Fmulti-sitemap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famannn%2Fmulti-sitemap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famannn%2Fmulti-sitemap/lists"}