{"id":13717000,"url":"https://github.com/syntax-tree/xast-util-sitemap","last_synced_at":"2025-06-29T22:03:54.872Z","repository":{"id":43396603,"uuid":"329912400","full_name":"syntax-tree/xast-util-sitemap","owner":"syntax-tree","description":"xast utility to build a sitemap","archived":false,"fork":false,"pushed_at":"2023-07-18T14:44:07.000Z","size":103,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-31T14:58:00.765Z","etag":null,"topics":["sitemap","xast","xast-util","xml"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","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/syntax-tree.png","metadata":{"funding":{"github":"unifiedjs","open_collective":"unified"},"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}},"created_at":"2021-01-15T12:57:23.000Z","updated_at":"2024-11-06T13:15:59.000Z","dependencies_parsed_at":"2024-01-14T22:13:43.419Z","dependency_job_id":null,"html_url":"https://github.com/syntax-tree/xast-util-sitemap","commit_stats":{"total_commits":36,"total_committers":3,"mean_commits":12.0,"dds":0.05555555555555558,"last_synced_commit":"a9f2418882b88e7920a44523f1a30c7a5d5e3b7d"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-sitemap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-sitemap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-sitemap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-sitemap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/xast-util-sitemap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fxast-util-sitemap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259198001,"owners_count":22820153,"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":["sitemap","xast","xast-util","xml"],"created_at":"2024-08-03T00:01:16.552Z","updated_at":"2025-06-29T22:03:54.845Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["xast utilities"],"sub_categories":[],"readme":"# xast-util-sitemap\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[xast][] utility to build a [`sitemap.xml`][sitemap-site].\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`sitemap(data)`](#sitemapdata)\n    *   [`Entry`](#entry)\n    *   [`Alternate`](#alternate-1)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package helps you build a [`sitemap.xml`][sitemap-site].\nIt supports localization as suggested by [Google][].\n\n## When should I use this?\n\nThis package focusses on a small set of widely used parts of sitemaps.\nIt has a few good options instead of overwhelming with everything that *could*\nbe done.\nIf you do need more things, well: this utility gives you a syntax tree, which\nyou can change.\n\nThis proejct is intended for sites with up to 50k URLs and a resulting\nserialized contents of up to 50MB.\nWrapping this project into something that generates sitemap index files is left\nas an exercise to the reader.\n\nYou don’t always need a sitemap.\n[See Google’s recommendations for whether you need a\nsitemap](https://developers.google.com/search/docs/advanced/sitemaps/overview)\n\nYou should place sitemaps in the root of your site and reference them in\n`robots.txt`.\nYou might also [report](https://support.google.com/webmasters/answer/7451001)\nsitemap changes to Google.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install xast-util-sitemap\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {sitemap} from 'https://esm.sh/xast-util-sitemap@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {sitemap} from 'https://esm.sh/xast-util-sitemap@2?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {sitemap} from 'xast-util-sitemap'\nimport {toXml} from 'xast-util-to-xml'\n\nconst tree = sitemap([\n  'https://example.com/alpha/',\n  {url: 'https://example.com/bravo/'},\n  {url: 'https://example.com/charlie/', modified: new Date(2018, 1, 2, 3)},\n  {\n    url: 'https://example.com/delta/',\n    lang: 'en',\n    alternate: {\n      nl: 'https://example.com/dirk/',\n      'fr-BE': 'https://example.com/désiré/'\n    }\n  }\n])\n\nconsole.log(toXml(tree))\n```\n\nYields (pretty printed):\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003curlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://example.com/alpha/\u003c/loc\u003e\n  \u003c/url\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://example.com/bravo/\u003c/loc\u003e\n  \u003c/url\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://example.com/charlie/\u003c/loc\u003e\n    \u003clastmod\u003e2018-02-02T02:00:00.000Z\u003c/lastmod\u003e\n  \u003c/url\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://example.com/delta/\u003c/loc\u003e\n    \u003cxhtml:link rel=\"alternate\" hreflang=\"en\" href=\"https://example.com/delta/\" /\u003e\n    \u003cxhtml:link rel=\"alternate\" hreflang=\"nl\" href=\"https://example.com/dirk/\" /\u003e\n    \u003cxhtml:link rel=\"alternate\" hreflang=\"fr-BE\" href=\"https://example.com/d%C3%A9sir%C3%A9/\" /\u003e\n  \u003c/url\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://example.com/dirk/\u003c/loc\u003e\n    \u003cxhtml:link rel=\"alternate\" hreflang=\"en\" href=\"https://example.com/delta/\" /\u003e\n    \u003cxhtml:link rel=\"alternate\" hreflang=\"nl\" href=\"https://example.com/dirk/\" /\u003e\n    \u003cxhtml:link rel=\"alternate\" hreflang=\"fr-BE\" href=\"https://example.com/d%C3%A9sir%C3%A9/\" /\u003e\n  \u003c/url\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://example.com/d%C3%A9sir%C3%A9/\u003c/loc\u003e\n    \u003cxhtml:link rel=\"alternate\" hreflang=\"en\" href=\"https://example.com/delta/\" /\u003e\n    \u003cxhtml:link rel=\"alternate\" hreflang=\"nl\" href=\"https://example.com/dirk/\" /\u003e\n    \u003cxhtml:link rel=\"alternate\" hreflang=\"fr-BE\" href=\"https://example.com/d%C3%A9sir%C3%A9/\" /\u003e\n  \u003c/url\u003e\n\u003c/urlset\u003e\n```\n\n## API\n\nThis package exports the identifier [`sitemap`][api-sitemap].\nThere is no default export.\n\n### `sitemap(data)`\n\nBuild a sitemap.\n\n###### Parameters\n\n*   `data` (`Array\u003cEntry | string\u003e`)\n    — entries to build a sitemap for\n    (see [`Entry`][api-entry], strings are equivalent to `{url: string}`)\n\n###### Returns\n\nSitemap ([`Root`][root]).\n\n### `Entry`\n\nEntries represent a single URL and describe them with metadata (TypeScript\ntype).\n\n##### Fields\n\n###### `url`\n\nFull URL ([`\u003cloc\u003e`][loc]; `string`, required, example: `https://example.org/`).\n\n###### `modified`\n\nValue indicating when the page last changed ([`\u003clastmod\u003e`][lastmod]; `Date` or\nvalue for `new Date(x)`, optional).\n\n###### `lang`\n\n[BCP 47][bcp47] tag indicating the language of the page (`string`, required w/\n`alternate`, example: `'en-GB'`).\n\n###### `alternate`\n\nTranslations of the page, where each key is a [BCP 47][bcp47] tag and each\nvalue an [`Alternate`][api-alternate] (`Record\u003cstring, Alternate\u003e`, optional,\nexample: `{nl: 'https://example.nl/'}`).\n\nAlternate resources “inherit” fields (`modified`) from the entry they are\ndescribed in.\n\n### `Alternate`\n\nAlternative content, typically a translation (TypeScript type).\n\nTo define different fields, either use a full entry object:\n\n```js\n[\n  {\n    url: 'https://example.com/delta/',\n    modified: '05 October 2011 14:48 UTC',\n    lang: 'en',\n    alternate: {nl: {url: 'https://example.com/dirk/', modified: '20 January 2020 00:00 UTC'}}\n  }\n]\n```\n\n…or define them separately:\n\n```js\n[\n  {\n    url: 'https://example.com/delta/',\n    modified: '05 October 2011 14:48 UTC',\n    lang: 'en',\n    alternate: {nl: 'https://example.com/dirk/'}\n  },\n  {\n    url: 'https://example.com/dirk/',\n    modified: '20 January 2020 00:00 UTC',\n    // `xast-util-sitemap` is smart enough to know about the next two already,\n    // but they’re shown here for clarity.\n    lang: 'nl',\n    alternate: {en: 'https://example.com/delta/'}\n  }\n]\n```\n\n###### Type\n\n```ts\ntype Alternate = Omit\u003cEntry, 'alternate' | 'lang'\u003e | string\n```\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Alternate`][api-alternate] and\n[`Entry`][api-entry].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `xast-util-sitemap@^2`,\ncompatible with Node.js 16.\n\n## Security\n\nXML can be a dangerous language: don’t trust user-provided data.\nSitemaps also indicate “ownership” of URLs: crawlers assume that the origin\nof the `sitemap.xml` file is also an owner\n\n## Related\n\n*   [`xast-util-to-xml`](https://github.com/syntax-tree/xast-util-to-xml)\n    — serialize xast to XML\n*   [`xast-util-feed`](https://github.com/syntax-tree/xast-util-feed)\n    — build feeds (RSS, Atom)\n*   [`xastscript`](https://github.com/syntax-tree/xastscript)\n    — create xast trees\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/syntax-tree/xast-util-sitemap/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/xast-util-sitemap/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/xast-util-sitemap.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/xast-util-sitemap\n\n[downloads-badge]: https://img.shields.io/npm/dm/xast-util-sitemap.svg\n\n[downloads]: https://www.npmjs.com/package/xast-util-sitemap\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=xast-util-sitemap\n\n[size]: https://bundlejs.com/?q=xast-util-sitemap\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[xast]: https://github.com/syntax-tree/xast\n\n[root]: https://github.com/syntax-tree/xast#root\n\n[sitemap-site]: https://www.sitemaps.org\n\n[loc]: https://www.sitemaps.org/protocol.html#locdef\n\n[lastmod]: https://www.sitemaps.org/protocol.html#lastmoddef\n\n[bcp47]: https://github.com/wooorm/bcp-47\n\n[google]: https://developers.google.com/search/docs/advanced/crawling/localized-versions#expandable-3\n\n[api-sitemap]: #sitemapdata\n\n[api-entry]: #entry\n\n[api-alternate]: #alternate-1\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fxast-util-sitemap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fxast-util-sitemap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fxast-util-sitemap/lists"}