PHPackages                             charcoal/contrib-sitemap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. charcoal/contrib-sitemap

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

charcoal/contrib-sitemap
========================

Charcoal service for generating a sitemap.

v2.0.1(2y ago)032MITPHPPHP ^7.4 || ^8.0

Since Mar 23Pushed 2y ago2 watchersCompare

[ Source](https://github.com/charcoalphp/contrib-sitemap)[ Packagist](https://packagist.org/packages/charcoal/contrib-sitemap)[ Docs](https://charcoalphp.github.io/contrib-sitemap/)[ RSS](/packages/charcoal-contrib-sitemap/feed)WikiDiscussions main Synced yesterday

READMEChangelog (2)Dependencies (10)Versions (4)Used By (0)

Charcoal Sitemap
================

[](#charcoal-sitemap)

[![License](https://camo.githubusercontent.com/58520713949a27fc9b6a2410091cc7b61c626ca73de9a84ea78d2c5388ee7887/68747470733a2f2f706f7365722e707567782e6f72672f63686172636f616c2f636f6e747269622d736974656d61702f6c6963656e7365)](LICENSE)[![Build Status](https://camo.githubusercontent.com/69fdf8d17fbde2860177da1c677a16d98d917e194c305f04afef45a5302a52ad/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f63686172636f616c7068702f636f6e747269622d736974656d61702f63692e796d6c3f6272616e63683d6d61696e)](https://github.com/charcoalphp/contrib-sitemap/actions)[![Latest Release](https://camo.githubusercontent.com/0955b81c570f6ad46cdc1b94821262aaa46ceae86ace0b3252ca3ece43a62d68/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f63686172636f616c7068702f636f6e747269622d736974656d61702e737667)](https://github.com/charcoalphp/contrib-sitemap/releases/latest)[![Supported PHP Version](https://camo.githubusercontent.com/03998d43a5ee66f0266594dbc1d221896d389b7ab45ffe9130aa726e778f0835/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f63686172636f616c2f63686172636f616c3f7374796c653d666c61742d737175617265266c6f676f3d706870)](composer.json)

A [Charcoal](https://github.com/charcoalphp/charcoal) package for generating a sitemap.

Installation
------------

[](#installation)

```
composer require charcoal/contrib-sitemap
```

### Setup

[](#setup)

For Charcoal projects, the package can be registered in two ways.

#### Charcoal Module

[](#charcoal-module)

The Sitemap's module will register the service provider (see below) and the route (`/sitemap.xml`).

The module can be registered from your configuration file:

```
"modules": {
    "charcoal/sitemap/sitemap": {}
}
```

#### Charcoal Service Provider

[](#charcoal-service-provider)

The Sitemap's service provider will register the necessary services (see below) for building a sitemap.

The service provider can be registered from your configuration file:

```
{
    "service_providers": {
        "charcoal/view/service-provider/view": {}
    }
}
```

To register a route from your configuration file:

```
{
    "routes": {
        "actions": {
            "sitemap.xml": {
                "route": "/sitemap.xml",
                "methods": [ "GET" ],
                "controller": "charcoal/sitemap/action/sitemap",
                "action_data": {
                    "sitemap_ident": "xml"
                }
            }
        }
    }
}
```

By default, the action controller will look for a sitemap hierarchy named `xml`which can be changed via the `sitemap_ident` controller setting.

Overview
--------

[](#overview)

### Routes

[](#routes)

- **`GET /sitemap.xml`** — A route assigned to `Charcoal\Sitemap\Action\SitemapAction`.
    Used to serve the XML document.

### Services

[](#services)

- **`charcoal/sitemap/builder`** — Instance of `Charcoal\Sitemap\Service\Builder`.
    Used to generate the collections of links from the configured models.
- **`sitemap/formatter/xml`** — Instance of `Charcoal\Sitemap\Service\XmlFormatter`.
    Used to generate the XML from one or more collections of links from the `Builder`.
- **`sitemap/presenter`** — Instance of `Charcoal\Sitemap\Service\SitemapPresenter`.
    Used to resolve model transformations.
- **`sitemap/transformer/factory`** — Instance of `Charcoal\Factory\GenericFactory`([charcoal/factory](https://github.com/charcoalphp/factory)).
    Used to resolve object transformers from object types.

Configuration
-------------

[](#configuration)

The Sitemap can be configured from the application configset under the `sitemap` key. You can setup which objects to be included and available translations (l10n).

Most options are renderable by objects using your application's chosen template syntax (Mustache used in examples below).

### Default Options

[](#default-options)

```
{
    /**
     * The service's configuration point.
     */
    "sitemap": {
        /**
         * One or more groups to customize how objects should be processed.
         *
         * The array key is an arbitrary identifier for the grouping of models.
         */
        "": {
            /**
             * Whether or not to include links to translations.
             *
             * - `true` — Multilingual. Include all translations
             *   (see `locales.languages`).
             * - `false` — Unilingual. Include only the default language
             *   (see `locales.default_language`).
             */
            "l10n": false,
            /**
             * The language to include a link to if group is unilingual.
             *
             * If `l10n` is `true`, this option is ignored.
             *
             * Defaults to the application's current language.
             */
            "locale": "",
            /**
             * Whether or not to check if the routable object
             * has an active route (`RoutableInterface#isActiveRoute()`)
             *
             * - `true` — Include only routable objects with active routes.
             * - `false` — Ignore if a routable object's route is active.
             */
            "check_active_routes": false,
            /**
             * Whether or not to prepend relative URIs with
             * the application's base URI (see `base_url`).
             *
             * - `true` — Use only the object's URI (see `sitemap.*.objects.*.url`).
             * - `false` — Prepend the base URI if object's URI is relative.
             */
            "relative_urls": false,
            /**
             * The transformer to parse each model included in `objects`.
             *
             * Either a PHP FQCN or snake-case equivalent.
             */
            "transformer": "",
            /**
             * Map of models to include in the sitemap.
             */
            "objects": {
                /**
                 * One or more models to customize and include in the sitemap.
                 *
                 * The array key must be the model's object type,
                 * like `app/model/foo-bar`, or fully-qualified name (FQN),
                 * like `App\Model\FooBar`.
                 */
                "": {
                    /**
                     * The transformer to parse the object.
                     *
                     * Either a PHP FQCN or snake-case equivalent.
                     */
                    "transformer": "",
                    /**
                     * The URI of the object for the `` element.
                     */
                    "url": "{{ url }}",
                    /**
                     * The name of the object. Can be used in a
                     * custom sitemap builder or XML generator.
                     */
                    "label": "{{ title }}",
                    /**
                     * Map of arbitrary object data that can be used
                     * in a custom sitemap builder or XML generator.
                     */
                    "data": {},
                    /**
                     * List or map of collection filters of which objects
                     * to include in the sitemap.
                     *
                     * ```json
                     * "": {
                     *     "property": "active",
                     *     "value": true
                     * }
                     * ```
                     */
                    "filters": [],
                    /**
                     * List or map of collection orders to sort the objects
                     * in the sitemap.
                     *
                     * ```json
                     * "": {
                     *     "property": "position",
                     *     "direction": "ASC"
                     * }
                     * ```
                     */
                    "orders": [],
                    /**
                     * Map of models to include in the sitemap
                     * below this model.
                     *
                     * Practical to group related models.
                     */
                    "children": {
                        /**
                         * One or more models to customize and include in the sitemap.
                         */
                        "": {
                            /**
                             * A constraint on the parent object to determine
                             * if the child model's objects should be included
                             * in the sitemap.
                             */
                            "condition": null
                        }
                    }
                }
            }
        }
    }
}
```

Each model can override the following options of their group: `l10n`, `locale`, `check_active_routes`, `relative_urls`.

### Example

[](#example)

The example below, identified as `footer_sitemap`, is marked as multilingual using the `l10n` option which will include all translations.

```
{
    "sitemap": {
        "footer_sitemap": {
            "l10n": true,
            "check_active_routes": true,
            "relative_urls": false,
            "transformer": "charcoal/sitemap/transformer/routable",
            "objects": {
                "app/object/section": {
                    "transformer": "\\App\\Transformer\\Sitemap\\Section",
                    "label": "{{ title }}",
                    "url": "{{ url }}",
                    "filters": {
                        "active": {
                            "property": "active",
                            "value": true
                        }
                    },
                    "data": {
                        "id": "{{ id }}",
                        "metaTitle": "{{ metaTitle }}"
                    },
                    "children": {
                        "app/object/section-children": {
                            "condition": "{{ isAnObjectParent }}"
                        }
                    }
                }
            }
        }
    }
}
```

Usage
-----

[](#usage)

### Using the builder

[](#using-the-builder)

The builder returns only an array. You need to make your own converter if you need another format.

Given the settings above:

```
$builder = $container['charcoal/sitemap/builder'];
// 'footer_sitemap' is the ident of the settings you want.
$links = $builder->build('footer_sitemap');
```

You can also use the `SitemapBuilderAwareTrait`, which includes the setter and getter for the sitemap builder, in order to use it with minimal code in every necessary class.

### XML Formatter

[](#xml-formatter)

The XML formatter generates a valid XML sitemap from the array returned by the builder.

```
$builder = $container['charcoal/sitemap/builder'];
$links   = $builder->build('footer_sitemap');

$formatter = $container['sitemap/formatter/xml'];
$sitemap   = $formatter->createXmlFromCollections($links);
```

Development
-----------

[](#development)

To install the development environment:

```
composer install
```

To run the scripts (PHP lint, PHPCS, PHPStan, and PHPUnit):

```
composer lint
composer test
```

License
-------

[](#license)

Charcoal is licensed under the MIT license. See [LICENSE](LICENSE) for details.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~220 days

Total

3

Last Release

757d ago

Major Versions

v1.0.0 → v2.0.02023-11-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/0a4f39523b4b2837562ba0848a0327b8d340118d1ba87cb0f5d59b1d5cb6beba?d=identicon)[mcaskill](/maintainers/mcaskill)

---

Top Contributors

[![mcaskill](https://avatars.githubusercontent.com/u/29353?v=4)](https://github.com/mcaskill "mcaskill (31 commits)")[![BeneRoch](https://avatars.githubusercontent.com/u/3017380?v=4)](https://github.com/BeneRoch "BeneRoch (10 commits)")[![pascalrioux](https://avatars.githubusercontent.com/u/36555872?v=4)](https://github.com/pascalrioux "pascalrioux (4 commits)")[![veve40](https://avatars.githubusercontent.com/u/7537381?v=4)](https://github.com/veve40 "veve40 (2 commits)")[![JoelAlphonso](https://avatars.githubusercontent.com/u/10762266?v=4)](https://github.com/JoelAlphonso "JoelAlphonso (1 commits)")

---

Tags

contributionphpsitemap-generatorcharcoalSitemap

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/charcoal-contrib-sitemap/health.svg)

```
[![Health](https://phpackages.com/badges/charcoal-contrib-sitemap/health.svg)](https://phpackages.com/packages/charcoal-contrib-sitemap)
```

###  Alternatives

[samdark/sitemap

Sitemap and sitemap index builder

5401.4M45](/packages/samdark-sitemap)[tackk/cartographer

A PHP sitemap generation tool.

325493.4k3](/packages/tackk-cartographer)[nystudio107/craft-seomatic

SEOmatic facilitates modern SEO best practices &amp; implementation for Craft CMS 5. It is a turnkey SEO system that is comprehensive, powerful, and flexible.

1741.5M62](/packages/nystudio107-craft-seomatic)[novactive/ezseobundle

Novactive eZ SEO Bundle is an Ibexa Platform bundle for SEO simplications. metas, sitemaps, robots.txt, etc.

29259.4k3](/packages/novactive-ezseobundle)[rainlab/sitemap-plugin

Sitemap plugin for October CMS

2282.5k1](/packages/rainlab-sitemap-plugin)[fof/sitemap

Generate a sitemap

1899.7k2](/packages/fof-sitemap)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
