PHP code example of swoft-components / sitemap-pusher

1. Go to this page and download the library: Download swoft-components/sitemap-pusher library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

swoft-components / sitemap-pusher example snippets


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

  return [
    ...
    Baidu::BEAN_NAME => [
        'token' => '百度主动推送token',
        'site' => '要被推送的网站域名',
    ],
    ...
  ];
+ 

/** @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);

/**
 * 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;
    }

}