{"id":15621761,"url":"https://github.com/pirtleshell/xml-sitemap","last_synced_at":"2025-03-29T15:47:16.386Z","repository":{"id":57401848,"uuid":"76064138","full_name":"pirtleshell/xml-sitemap","owner":"pirtleshell","description":"Utilities for quickly writing and updating XML sitemaps","archived":false,"fork":false,"pushed_at":"2016-12-17T04:10:01.000Z","size":92,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T22:17:12.682Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/xml-sitemap","language":"JavaScript","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/pirtleshell.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}},"created_at":"2016-12-09T19:28:08.000Z","updated_at":"2021-12-13T18:24:29.000Z","dependencies_parsed_at":"2022-09-15T18:41:24.406Z","dependency_job_id":null,"html_url":"https://github.com/pirtleshell/xml-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/pirtleshell%2Fxml-sitemap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirtleshell%2Fxml-sitemap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirtleshell%2Fxml-sitemap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirtleshell%2Fxml-sitemap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pirtleshell","download_url":"https://codeload.github.com/pirtleshell/xml-sitemap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246207491,"owners_count":20740723,"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":[],"created_at":"2024-10-03T09:51:44.779Z","updated_at":"2025-03-29T15:47:16.362Z","avatar_url":"https://github.com/pirtleshell.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xml-sitemap\n\n\u003e Utilities for quickly making custom XML sitemaps\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n\t- [Build a sitemap from scratch](#build-a-sitemap-from-scratch)\n\t- [Setting a host](#setting-a-host)\n\t- [Updating and reading sitemap info](#updating-and-reading-sitemap-info)\n\t- [Editing an existing sitemap](#editing-an-existing-sitemap)\n\t- [Set lastmod values from files](#set-lastmod-values-from-files)\n- [API](#api)\n- [Licence](#licence)\n\n## Install\n\nAdd it to a project with `npm`:\n```sh\n$ npm install xml-sitemap --save\n```\n\nThen just `require` it in your project:\n```js\nvar XmlSitemap = require('xml-sitemap');\nvar sitemap = new XmlSitemap();\n```\n\n## Usage\n\nFor more info on anything check out the [docs](https://github.com/PirtleShell/xml-sitemap/blob/master/docs/api.md).\n\n### Build a sitemap from scratch\n\nAll methods that don't return values return the sitemap, so you can chain them all together.\n\n```js\nvar sitemap = new XmlSitemap();\n\n// add some urls\nsitemap.add('http://domain.com/')\n\n  .add('http://domain.com/another-page', {\n    lastmod: 'now',\n    priority: 0.8\n  })\n\n  .add({\n    url: 'http://domain.com/sitemapz-rule',\n    changefreq: 'never',\n    lastmod: '1999-12-31'\n  });\n```\n\nWe could have made the same sitemap with a single array:\n\n```js\nvar sitemap = new XmlSitemap()\n  .add([\n    'http://domain.com/',\n    {\n      url: 'http://domain.com/another-page',\n      lastmod: 'now',\n      priority: 0.8\n    },\n    {\n      loc: 'http://domain.com/sitemapz-rule',\n      changefreq: 'never',\n      lastmod: '1999-12-31'\n    }\n  ]);\n```\n\n### Setting a host\n\nSetting a host with `.setHost(url)` allows for all methods to accept relative links. `.setHost` accepts a string or an object with options. Building the above with a host set:\n\n```js\nvar sitemap = new XmlSitemap()\n  .setHost('http://domain.com/')    // allows relative links, automatically adds host url\n  .add([\n    {\n      url: '/another-page',\n      lastmod: 'now',\n      priority: 0.8\n    },\n    {\n      loc: '/sitemapz-rule',\n      changefreq: 'never',\n      lastmod: '1999-12-31'\n    }\n  ]);\n```\n\n### Updating and reading sitemap info\n\nUpdate and read some info from the sitemap we built above:\n\n```js\n// update some values\nsitemap.update('http://domain.com/', new Date())\n  .setOptionValue('http://domain.com/sitemapz-rule', 'priority', 1);\n\n// an array of the urls is in sitemap.urls\nsitemap.urls\n//=\u003e [ 'http://domain.com/', 'http://domain.com/magic', 'http://domain.com/another-page', 'http://domain.com/sitemapz-rule' ]\n\n// and the xml is in sitemap.xml\nrequire('fs').writeFileSync('sitemap.xml', sitemap.xml);\n\n// we can also read info from the sitemap\nsitemap.hasUrl('http://domain.com/another-page');\n//=\u003e true\n\nsitemap.getOptionValue('http://domain.com/', 'lastmod');\n//=\u003e {today's date!}\n\nsitemap.getOptionValue('http://domain.com/magic', 'lastmod');\n//=\u003e {today's date!}\n\nsitemap.getOptionValue('http://domain.com/another-page', 'lastmod');\n//=\u003e null\n```\n\n### Editing an existing sitemap\n\nWe can read in an existing sitemap (like the one we made above!) and modify it on the fly.\n\n```js\n// get the XML as a string\nvar xmlString = require('fs').readFileSync('sitemap.xml');\n// and pass it to the constructor\nvar sitemap = new XmlSitemap(xmlString)\n  .setHost('http://domain.com/');\n\nsitemap.hasUrl('/magic');\n//=\u003e true\n\n// modify it\nsitemap.remove('/another-page')\n  .setOptionValues('/magic', {\n    lastmod: '2012-12-21',\n    priority: 0.9\n  });\n\nsitemap.hasUrl('/another-page');\n//=\u003e false\nsitemap.getOptionValue('/magic', 'priority');\n//=\u003e '0.9'\n\n// quickly update lastmod vlaues\nsitemap.getOptionValue('/magic', 'lastmod');\n//=\u003e '2012-12-21'\n\nsitemap.update('/magic');\nsitemap.getOptionValue('/magic', 'lastmod');\n//=\u003e {today's date}\n```\n\n### Set lastmod values from files\n\nFor easily updating a url's lastmod, we can link a file to it. Here are a few ways to link the file:\n\n```js\nvar filename = 'path/to/file.html'; // last modified on '2012-12-21'\n\n// link by adding a filename to the 'file' key to its options when adding it\nsitemap.add({\n  url: 'http://domain.com/',\n  file: filename\n});\n\n// or after it is already in the sitemap\nsitemap.linkFile('http://domain.com/', filename);\n\n// the lastmod has been updated accordingly in both cases\nsitemap.getOptionValue('http://domain.com/', 'lastmod');\n//=\u003e '2012-12-21'\n\n// linked files are listed in sitemap.files\nsitemap.files\n//=\u003e {'http://domain.com/': 'path/to/file.html'}\n```\n\nLinked files automatically update the lastmod of their respective urls when `updateAll()` is called. So you can link many files to urls already in the sitemap by assigning the files object and then updating all.\n\n```js\nsitemap.files = {\n  url1: filename1,\n  url2: filename2,\n  ...\n};\nsitemap.updateAll();\n```\n\nTo update a lastmod from a file without linking it, use `sitemap.updateFromFile(url, filepath)`. Unlink a file with `sitemap.unlinkFile(url)`.\n\n## API\nRead the full documentation on the API [here](https://github.com/PirtleShell/xml-sitemap/blob/master/docs/api.md).\n\n## Licence\nMIT \u0026copy; 2016 [Robert Pirtle](https://pirtle.xyz)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirtleshell%2Fxml-sitemap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpirtleshell%2Fxml-sitemap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirtleshell%2Fxml-sitemap/lists"}