PHPackages                             swoft-components/sitemap-pusher - 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. swoft-components/sitemap-pusher

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

swoft-components/sitemap-pusher
===============================

SitemapPusher 是一个专门为 Swoft2 开发者设计的网站地图组件，旨在简化向各大站长平台提交网站链接的过程。通过自定义数据源生成sitemap，自动化的链接提交，帮助站长加速搜索引擎对新发布或更新内容的收录速度。

v1.0.2(10mo ago)0131Apache-2.0PHPPHP &gt;=7.4

Since Jun 22Pushed 9mo agoCompare

[ Source](https://github.com/swoft-components/sitemap-pusher)[ Packagist](https://packagist.org/packages/swoft-components/sitemap-pusher)[ RSS](/packages/swoft-components-sitemap-pusher/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (9)Used By (0)

SitemapPusher
=============

[](#sitemappusher)

概述
--

[](#概述)

SitemapPusher 是一个专门为 Swoft2 开发者设计的网站地图组件，旨在简化向各大站长平台提交网站链接的过程。通过自定义数据源生成sitemap，自动化的链接提交，帮助站长加速搜索引擎对新发布或更新内容的收录速度。

### 版本说明

[](#版本说明)

当前最新版本：**v1.0.6-beta**

稳定版：v1.0.2（此版本不支持命令行工具）

### 功能特色

[](#功能特色)

- 自定义数组数据源（`CustomDataSource::class`）

    用户可以直接通过配置数组内容，写入sitemap。

    ```
    // 自定义数据源至少有一个字段，后续三个字段为可选字段，分别对应: lastmod, changefreq, priority
    return [
      'app' => [
          'data' => [
              ['https://www.liujie.xin/'],
              ['https://www.liujie.xin/index.html'],
              ['https://www.liujie.xin/about.html'],
          ],
      ]
    ];
    ```
- 用户自定义数据源（`@DataSource`）

    使用 @DataSource 注解绑定到相应的自定义数据源类，数据源类必须实现 `DataSourceInterface::class`默认数据源，不在通过属性注入的方式加载自定义的数据，通过设置 filepath 指定文件数据源路径. 数据源文件示例如下：

    ```
    https://www.liujie.xin/,,,
    https://www.liujie.xin/about.html,,,0.8

    ```
- 分页执行，降低执行过程中的内存占用率

    通过配置参数`$pageSize`，数据源均支持分页执行，以便分批次写入sitemap 文件，降低内存的占用率。
- 大数据量网站地图生成，进度提示，预计完成时间提示

    生成网站地图参数可以配置参数 `logPerNum`，每写入`$logPerNum`条数据，会触发一个事件，默认事件会打印当前网站地图执行的进度，和预计完成时间。同时支持用户自定义事件处理。
- 自定义事件处理函数

    - sitemap 生成前事件
    - 进度报告事件
    - 异常处理事件
    - sitemap 生成后事件

        用户可以根据需求自定义相应的事件处理函数。
- 百度地图主动推送

    当前版本支持百度地图的主动推送功能，可以通过 swoft 事件触发机制，快速集成到系统中。
- 百度地图主动推送命令支持（新功能） 首先需要再 bean 定义中配置好 site 和 token

    ```
    return [
      ...
      Baidu::BEAN_NAME => [
          'token' => '百度主动推送token',
          'site' => '要被推送的网站域名',
      ],
      ...
    ];
    ```
- ```
    ```bash
    # 主动推送 url 到百度搜索引擎（目前只集成了baidu搜索引擎的主动推送）
    php bin/swoft sitemap:push [url] --engine=baidu

    ```
- 命令行工具

    提供 `php swoft sitemap:generate -d=/tmp -name=sitemap.txt -n 50 -p 100` 命令行工具，手动生成网站地图。

    - --dir, -d 指定网站地图的生成路径，默认值为当前目录 `./`
    - --name, -name 指定网站地图的名称，默认值为`sitemap.xml`
    - --num, -n 指定分页大小，对大量数据生成地图的网站，数据要分批进行写入，默认值为`50`
    - --progress, -p 指定每隔多少条记录写入，日志显示当前的执行进度，和预计完成时间，默认值为 `200`
    - --type, -t 指定生成的网站地图类型，默认值为 `xml`，可选值为 `txt` 和 `xml`

### 快速开始

[](#快速开始)

#### 网站地图生成

[](#网站地图生成)

网站地图生成示例代码：

```
/** @var Sitemap $sitemap */
$sitemap = bean(Sitemap::BEAN_NAME);
// 不同类型的 Writer 对应最后生成的不同的 sitemap 类型
$writer = TxtWriter::new(\Swoft::getAlias('@base/public/sitemap.txt'), 'w');
$sitemap->generate($writer, 50, 50);
```

设置自定义数据源，支持设置数据获取的优先级（决定获取数据源的顺序，priority 值越大优先级越高）。

```
/**
 * Class TagSource
 * @since 2.0.0
 * @DataSource(priority=100)
 */
class TagSource implements DataSourceInterface
{

    /**
     * 获取当前数据源的数据，每次获取指定分页的记录数，返回数据不足分页表示数据获取完毕.
     *
     * @param Sitemap $sitemap
     * @param int $size
     * @return DataSourceItem[]
     */
    public function getData(Sitemap $sitemap, int $size): array
    {
        return [];
    }

    /**
     * 获取当前数据源的总记录数
     *
     * @return int
     */
    public function count(): int
    {
        return 0;
    }

}
```

#### 手动生成

[](#手动生成)

```
# 通过命令在当前目录生成网站地图
php bin/sowft sitemap:gen
# 设置目录 -d=/tmp
# 设置名称 -name=sitemap
# 设置类型 -t=xml (目前支持 txt 和 xml 两种格式)
# 设置分页大小 -n=200 数据量比较大，可以设置 500，看情况定
# 设置进度汇报参数，-p=500 表示，每写入500条记录，就会提示用户当前执行进度，和预计完成时间。
php bin/swoft sitemap:gen -d=/tmp -name=sitemap.txt -n 50 -p 100
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance57

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~3 days

Total

8

Last Release

297d ago

PHP version history (2 changes)v1.0.0-betaPHP &gt;=7.4

v1.0.3-betaPHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/498a610f6038258ab3ad1399afa3cf2a65ee6b3372471898c9106af5bd3a2778?d=identicon)[liujiekkk](/maintainers/liujiekkk)

---

Top Contributors

[![liujiekkk](https://avatars.githubusercontent.com/u/14047843?v=4)](https://github.com/liujiekkk "liujiekkk (25 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/swoft-components-sitemap-pusher/health.svg)

```
[![Health](https://phpackages.com/badges/swoft-components-sitemap-pusher/health.svg)](https://phpackages.com/packages/swoft-components-sitemap-pusher)
```

###  Alternatives

[stuttter/wp-user-profiles

A sophisticated way to edit users in WordPress

11219.3k1](/packages/stuttter-wp-user-profiles)[fof/analytics

Tracks analytics using Google Analytics, Google Optimize/GTM and Matomo

3543.1k](/packages/fof-analytics)[chrico/wp-fields

Package which provides some re-usable fields for WordPress.

1981.2k](/packages/chrico-wp-fields)[aertmann/history

An improved history backend module for Neos

1070.2k](/packages/aertmann-history)[jlzan1314/swoft-entity

swoft 2.0 entity creater

121.5k](/packages/jlzan1314-swoft-entity)

PHPackages © 2026

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