gatsby-plugin-sitemap-html

中文文档
1.3.0发布于 2026/11/04MITTypeScriptCommonJS构建来源已验证

Gatsby plugin that extends gatsby-plugin-sitemap to generate HTML-styled sitemaps using XSL

原始使用文档
文档目录17 节
  1. ✨ Features
  2. 📦 Installation
  3. 🚀 Quick Start
  4. ⚙️ Configuration
  5. Basic Configuration
  6. Custom Output Path
  7. Custom Sitemap Filename
  8. Options
  9. 📖 How It Works
  10. 🎨 Custom Styling
  11. 📚 Documentation
  12. 🔍 Example
  13. 🤝 Contributing
  14. 🔒 Security
  15. 📝 Changelog
  16. 📄 License
  17. 🙏 Acknowledgments

gatsby-plugin-sitemap-html

npm version License: MIT CI codecov

A Gatsby plugin that extends gatsby-plugin-sitemap to generate human-readable, HTML-styled sitemaps using XSL. Transform your XML sitemaps into beautiful, browser-friendly pages that both users and search engines can appreciate.

✨ Features

  • 🎨 Beautiful HTML styling - Makes sitemaps human-readable in browsers
  • 🔧 Zero configuration - Works out of the box with sensible defaults
  • 🎯 Customizable - Bring your own XSL template if needed
  • 📦 Lightweight - Minimal dependencies
  • 🚀 SEO-friendly - Maintains XML structure for search engines
  • 🔄 Automatic processing - Handles sitemap index and all sitemap files

📦 Installation

pnpm add gatsby-plugin-sitemap gatsby-plugin-sitemap-html

Or with npm:

npm install gatsby-plugin-sitemap gatsby-plugin-sitemap-html

Or with yarn:

yarn add gatsby-plugin-sitemap gatsby-plugin-sitemap-html

🚀 Quick Start

Add the plugin to your gatsby-config.js. Important: Add it after gatsby-plugin-sitemap:

module.exports = {
  siteMetadata: {
    siteUrl: 'https://www.example.com',
  },
  plugins: [
    'gatsby-plugin-sitemap',
    'gatsby-plugin-sitemap-html',
  ],
};

That's it! Build your site and visit /sitemap.xml in your browser to see the styled sitemap.

⚙️ Configuration

Basic Configuration

module.exports = {
  plugins: [
    'gatsby-plugin-sitemap',
    {
      resolve: 'gatsby-plugin-sitemap-html',
      options: {
        // Optional: path to custom XSL template
        xslTemplate: `${__dirname}/src/templates/custom-sitemap.xsl`,
      },
    },
  ],
};

Custom Output Path

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-plugin-sitemap',
      options: {
        output: '/sitemaps',
      },
    },
    {
      resolve: 'gatsby-plugin-sitemap-html',
      options: {
        output: '/sitemaps', // Must match gatsby-plugin-sitemap
      },
    },
  ],
};

Custom Sitemap Filename

module.exports = {
  plugins: [
    'gatsby-plugin-sitemap',
    {
      resolve: 'gatsby-plugin-sitemap-html',
      options: {
        sitemapFilename: 'custom-sitemap.xml',
      },
    },
  ],
};

Options

| Option | Type | Default | Description | | ---------------- | ------ | ----------------- | --------------------------------------------------------------------------- | | xslTemplate | string | built-in template | Path to a custom XSL template file (optional) | | output | string | / | Folder path where sitemaps are stored (must match gatsby-plugin-sitemap) | | sitemapFilename | string | sitemap.xml | Custom filename for the main sitemap file (renamed from sitemap-index.xml) |

📖 How It Works

  1. gatsby-plugin-sitemap generates your sitemap files (sitemap-index.xml, sitemap-0.xml, etc.)
  2. This plugin automatically:
    • Copies the XSL stylesheet to your public directory
    • Injects XSL references into all sitemap files
    • Renames sitemap-index.xml to sitemap.xml (or custom filename via sitemapFilename option) for standard naming
  3. When users visit your sitemap in a browser, they see a styled HTML page
  4. Search engines still see the standard XML structure

🎨 Custom Styling

To customize the appearance of your sitemap:

  1. Create a custom XSL file (you can copy from node_modules/gatsby-plugin-sitemap-html/templates/sitemap.xsl)
  2. Modify the styles and layout as needed
  3. Reference it in your config:
{
  resolve: 'gatsby-plugin-sitemap-html',
  options: {
    xslTemplate: './src/templates/my-sitemap.xsl',
  },
}

📚 Documentation

🔍 Example

Check the example directory for a complete working demo.

To run the example:

cd example
pnpm install
pnpm run build
pnpm run serve

Then visit http://localhost:9000/sitemap.xml

🤝 Contributing

Contributions are welcome! Please read our Contributing Guide for details.

Please note that this project is released with a Code of Conduct. By participating in this project you agree to abide by its terms.

🔒 Security

See our Security Policy for reporting vulnerabilities.

📝 Changelog

See CHANGELOG.md for release history.

📄 License

MIT © Ketan Patel

🙏 Acknowledgments


If you find this plugin helpful, please ⭐ star the repo!

版本与发布记录

gatsby-plugin-sitemap-html 共发布 13 个版本,首次发布于 2025/11/05;过去 12 个月发布了 13 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.3.0latest2026/11/04今天
1.2.32026/11/021 天前
1.2.22025/11/0711 个月前
1.2.12025/11/0711 个月前
1.2.02025/11/0711 个月前
1.1.32025/11/0511 个月前

关于 gatsby-plugin-sitemap-html 的常见问题

gatsby-plugin-sitemap-html 是什么?

Gatsby插件,扩展了gatsby-plugin-sitemap以使用XSL生成HTML风格的网站地图

如何安装 gatsby-plugin-sitemap-html?

在项目目录运行 npm install gatsby-plugin-sitemap-html,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:gatsby(^5.16.1)、gatsby-plugin-sitemap(^6.16.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

gatsby-plugin-sitemap-html 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

gatsby-plugin-sitemap-html 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

gatsby-plugin-sitemap-html 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

gatsby-plugin-sitemap-html 可以商用吗?

gatsby-plugin-sitemap-html 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

gatsby-plugin-sitemap-html 还在维护吗?

最新版本 1.3.0 发布于 2026/11/04(今天);至今共发布 13 个版本,其中过去 12 个月发布了 13 个;首次发布于 2025/11/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。