{"id":15016530,"url":"https://github.com/quasibit/eleventy-plugin-sitemap","last_synced_at":"2025-04-06T02:08:47.756Z","repository":{"id":38174246,"uuid":"272913582","full_name":"quasibit/eleventy-plugin-sitemap","owner":"quasibit","description":"Eleventy plugin to generate a sitemap.","archived":false,"fork":false,"pushed_at":"2025-01-23T18:57:08.000Z","size":4900,"stargazers_count":39,"open_issues_count":14,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T00:07:02.220Z","etag":null,"topics":["11ty","11ty-plugin","eleventy","eleventy-plugin","sitemap"],"latest_commit_sha":null,"homepage":"","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/quasibit.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-17T07:59:58.000Z","updated_at":"2025-01-23T18:57:13.000Z","dependencies_parsed_at":"2024-06-18T20:05:55.162Z","dependency_job_id":"d38d7c75-d910-4390-9331-f224cd411e38","html_url":"https://github.com/quasibit/eleventy-plugin-sitemap","commit_stats":{"total_commits":131,"total_committers":7,"mean_commits":"18.714285714285715","dds":0.4122137404580153,"last_synced_commit":"43c165c972928e97c714982daf696bbc1631c790"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasibit%2Feleventy-plugin-sitemap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasibit%2Feleventy-plugin-sitemap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasibit%2Feleventy-plugin-sitemap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasibit%2Feleventy-plugin-sitemap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quasibit","download_url":"https://codeload.github.com/quasibit/eleventy-plugin-sitemap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423514,"owners_count":20936626,"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":["11ty","11ty-plugin","eleventy","eleventy-plugin","sitemap"],"created_at":"2024-09-24T19:49:02.202Z","updated_at":"2025-04-06T02:08:47.728Z","avatar_url":"https://github.com/quasibit.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eleventy-plugin-sitemap\n\n[![npm](https://img.shields.io/npm/v/@quasibit/eleventy-plugin-sitemap)](https://www.npmjs.com/package/@quasibit/eleventy-plugin-sitemap)\n[![Release workflow](https://github.com/quasibit/eleventy-plugin-sitemap/workflows/Release/badge.svg)](https://github.com/quasibit/eleventy-plugin-sitemap/actions?query=workflow%3ARelease)\n[![Test workflow](https://github.com/quasibit/eleventy-plugin-sitemap/workflows/Test/badge.svg)](https://github.com/quasibit/eleventy-plugin-sitemap/actions?query=workflow%3ATest)\n[![codecov](https://codecov.io/gh/quasibit/eleventy-plugin-sitemap/branch/master/graph/badge.svg?token=F4X4KPQQCC)](https://codecov.io/gh/quasibit/eleventy-plugin-sitemap)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n[Eleventy](https://www.11ty.dev/) plugin to generate a sitemap using\n[ekalinin/sitemap](https://github.com/ekalinin/sitemap.js) generator.\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Options](#options)\n- [Examples](#examples)\n- [Advanced usage](#advanced-usage)\n- [Related plugins](#related-plugins)\n- [Maintainers](#maintainers)\n- [License](#license)\n\n## Installation\n\nInstall the package:\n\n```sh\nnpm install --save @quasibit/eleventy-plugin-sitemap\n```\n\nAdd the plugin to your [Eleventy configuration](https://www.11ty.dev/docs/config/)\n(usually `.eleventy.js`):\n\n```js\nconst sitemap = require(\"@quasibit/eleventy-plugin-sitemap\");\n\nmodule.exports = function (eleventyConfig) {\n  eleventyConfig.addPlugin(sitemap, {\n    sitemap: {\n      hostname: \"https://example.com\",\n    },\n  });\n};\n```\n\n## Usage\n\nCreate a sitemap file and use the shortcode to generate the sitemap XML:\n\n```njk\n---\npermalink: /sitemap.xml\nlayout: null\neleventyExcludeFromCollections: true\n---\n{% sitemap collections.all %}\n```\n\nThe above snippet does the following:\n\n- Sets the permalink to `/sitemap.xml`.\n- Disables any [layout](https://www.11ty.dev/docs/layouts/).\n- Excludes the sitemap file from Eleventy collections.\n- Calls the `sitemap` shortcode.\n\nAs the first argument to the shortcode, you pass the collection of items that\nyou want to use in the sitemap.\n\nThis shortcode is available for Liquid, Nunjucks, and Javascript templates.\nIt will not work if placed in a Markdown file.\n\nYou can also copy this sample from the examples and adapt it to your needs:\n\n```sh\ncp node_modules/@quasibit/eleventy-plugin-sitemap/examples/default/sitemap.njk sitemap.njk\n```\n\nAfter creating the sitemap, you should add the sitemap to `robots.txt`:\n\n```txt\nSitemap: https://example.com/sitemap.xml\n```\n\n## Options\n\nThe following options are available:\n\n```js\neleventyConfig.addPlugin(sitemap, {\n  // Name of the property for the last modification date.\n  // By default it is undefined and the plugin will fallback to `date`.\n  // When set, the plugin will try to use this property and it will fallback\n  // to the `date` property when needed.\n  lastModifiedProperty: \"modified\",\n\n  sitemap: {\n    // Options for SitemapStream. See https://github.com/ekalinin/sitemap.js/blob/master/api.md#sitemapstream\n    // Hostname is needed when the URLs of the items don't include it.\n    hostname: \"https://example.com\",\n  },\n});\n```\n\n## Examples\n\nSee [./examples](./examples) folder.\n\n## Advanced usage\n\n### Customizing sitemap properties\n\nYou can customize the values used for the sitemap links by adding [front matter](https://www.11ty.dev/docs/data-frontmatter/)\nto your pages.\n\n```yaml\n---\nsitemap:\n  changefreq: weekly\n  priority: 0.8\n---\n\n```\n\nAlternatively, you can apply the properties to a folder of items by creating a\n[directory data file](https://www.11ty.dev/docs/data-template-dir/).\n\nAssuming you want to apply this to all the files in `posts/*`:\n\n```javascript\n// posts/posts.11tydata.js\nmodule.exports = () =\u003e {\n  return {\n    sitemap: {\n      changefreq: \"weekly\",\n      priority: 0.8,\n    },\n  };\n};\n```\n\nFor a full list of options, please refer to [Sitemap Item Options](https://github.com/ekalinin/sitemap.js/blob/master/api.md#sitemap-item-options).\n\n### Exclude pages from the sitemap\n\nYou have several options to exclude pages from the sitemap.\n\nYou can exclude them using the standard `eleventyExcludeFromCollections`\nproperty, which will exclude them from all collections.\n\n```yaml\n---\neleventyExcludeFromCollections: true\n---\n\n```\n\nYou can use the `ignore` property on the `sitemap` data, which will only\nexclude it from the sitemap.\n\n```yaml\n---\nsitemap:\n  ignore: true\n---\n\n```\n\nOr you can create a [custom collection](https://www.11ty.dev/docs/collections/#advanced-custom-filtering-and-sorting)\nthat excludes the items that you don't want in the sitemap and then pass that\ncollection to the shortcode.\n\n```js\neleventyConfig.addCollection(\"sitemap\", function (collectionApi) {\n  return collectionApi.getAll().filter((item) =\u003e {\n    // Place your condition here for excluding items from the sitemap.\n    return true;\n  });\n});\n```\n\nSpecify the collection in the shortcode:\n\n```njk\n{% sitemap collections.sitemap %}\n```\n\n### Create a multilingual sitemap\n\nFor creating a [multilingual sitemap](https://webmasters.googleblog.com/2012/05/multilingual-and-multinational-site.html)\nyou need to add alternate language child links for each link.\n\nYou could do this with [front matter](#customizing-sitemap-properties) and the\n[links property](https://github.com/ekalinin/sitemap.js/blob/master/api.md#sitemap-item-options)\n, but in most cases it's easier to do this with a custom collection.\n\n```js\neleventyConfig.addCollection(\"sitemap\", function (collectionApi) {\n  return collectionApi.getAll().map((item, index, all) =\u003e {\n    return {\n      url: item.url,\n      date: item.date,\n      data: {\n        ...item.data,\n        sitemap: {\n          ...item.data.sitemap,\n          links: all\n            // Find all the translations of the current item.\n            // This assumes that all translated items that belong together\n            // have the same `translationKey` value in the front matter.\n            .filter(\n              (other) =\u003e other.data.translationKey === item.data.translationKey\n            )\n\n            // Map each translation into an alternate link. See https://github.com/ekalinin/sitemap.js/blob/master/api.md#ILinkItem\n            // Here we assume each item has a `lang` value in the front\n            // matter. See https://support.google.com/webmasters/answer/189077#language-codes\n            .map((translation) =\u003e {\n              return {\n                url: translation.url,\n                lang: translation.data.lang,\n              };\n            }),\n        },\n      },\n    };\n  });\n});\n```\n\nAnd then pass that collection to the sitemap shortcode:\n\n```njk\n{% sitemap collections.sitemap %}\n```\n\nYou can see an example with dynamic hostnames in [./examples/multilingual/](./examples/multilingual/).\n\n## Related plugins\n\n- [@quasibit/eleventy-plugin-schema](https://github.com/quasibit/eleventy-plugin-schema):\n  generate JSON-LD structured data.\n\n## Maintainers\n\n- [@nunof07](https://github.com/nunof07)\n\n## License\n\nMIT. See [LICENSE](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquasibit%2Feleventy-plugin-sitemap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquasibit%2Feleventy-plugin-sitemap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquasibit%2Feleventy-plugin-sitemap/lists"}