Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sviiiter/yii-sitemap-generator
sitemap generator library
https://github.com/sviiiter/yii-sitemap-generator
yii
Last synced: 1 day ago
JSON representation
sitemap generator library
- Host: GitHub
- URL: https://github.com/sviiiter/yii-sitemap-generator
- Owner: sviiiter
- Created: 2021-10-05T09:47:30.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-05T09:51:34.000Z (about 3 years ago)
- Last Synced: 2024-11-06T05:43:35.106Z (about 2 months ago)
- Topics: yii
- Language: PHP
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sitemap generator
Simple library contains interfaces to extract the data from storage, converts into tree and expand this into linear structure.
In respect that structure of site is tree of pages.Usage:
### - Create pipeline of ordered dto
Projects, products, news e.t.c. It is possible to create extractor tree as subtree of another extractor.
```
SitemapExtractorTopMenu::class,
'catalog' => SitemapExtractorCatalogPages::class
];
return array_map(function (SitemapExtractor $i) { return (new $i)->extract(); }, $pipe);
}}
```### - create concrete generator with converting location method:
```
class ConcreteXmlSitemapGenerator extends XmlSitemapGenerator
{/**
* @inheritDoc
*
* @param $url
* @return string
*/
protected static function convertLocation($url):string {
return rtrim(Site::current()->url, '/') . '/' . ltrim($url, '/');
}}
```### - in your clients code (kinda console command):
```
...
$piecesToExportToFile = (new SitemapProcessor())->collect();$rootXml = new SimpleXMLElement('');
$generator = new ConcreteXmlSitemapGenerator();
foreach ($piecesToExportToFile as $baseFilename => $tree) {$linear = $generator->extractTree($tree);
$xml = $generator->getXmlString($linear);$baseFilenameWExt = 'sitemap_' . $baseFilename . '.xml';
$filename = $exportDir . '/' . $baseFilenameWExt;
file_put_contents($filename, $xml);$rootSitemapTag = $rootXml->addChild('sitemap');
$rootSitemapTag->addChild('loc', rtrim(Site::current()->url, '/') . '/' . $baseFilenameWExt);
}$rootXml->asXML($exportDir . '/sitemap.xml');
...
```
... or to create a single file:```
$tree = (new SitemapProcessor())->collect();$generator = new ConcreteXmlSitemapGenerator();
$linear = $generator->extractTree($tree);
$xml = $generator->getXmlString($linear);
```