@@ -344,12 +344,16 @@ class ArticlesUrlBuilder implements UrlBuilder
344344 }
345345
346346 // link to section
347- yield Url::create(
348- 'https://example.com/article/',
349- $section_update_at ?: new \DateTimeImmutable('-1 day'),
350- ChangeFrequency::daily(),
351- 9
352- );
347+ if ($section_update_at !== null) {
348+ yield Url::createSmart('https://example.com/article/', $section_update_at);
349+ } else {
350+ yield Url::create(
351+ 'https://example.com/article/',
352+ new \DateTimeImmutable('-1 day'),
353+ ChangeFrequency::daily(),
354+ 9
355+ );
356+ }
353357 }
354358}
355359```
@@ -401,6 +405,26 @@ $stream->pushSitemap(new Sitemap('https://example.com/sitemap_articles.xml', new
401405$stream->close();
402406```
403407
408+ Result ` sitemap.xml ` :
409+
410+ ``` xml
411+ <?xml version =" 1.0" encoding =" UTF-8" ?>
412+ <sitemapindex xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : schemaLocation =" http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" xmlns =" http://www.sitemaps.org/schemas/sitemap/0.9" >
413+ <sitemap >
414+ <loc >https://example.com/sitemap_main.xml</loc >
415+ <lastmod >2020-06-15T13:39:46+03:00</lastmod >
416+ </sitemap >
417+ <sitemap >
418+ <loc >https://example.com/sitemap_news.xml</loc >
419+ <lastmod >2020-06-15T13:39:46+03:00</lastmod >
420+ </sitemap >
421+ <sitemap >
422+ <loc >https://example.com/sitemap_articles.xml</loc >
423+ <lastmod >2020-06-15T13:39:46+03:00</lastmod >
424+ </sitemap >
425+ </sitemapindex >
426+ ```
427+
404428## Split URLs and make Sitemap index
405429
406430You can simplify splitting the list of URLs to partitions and creating a Sitemap index.
@@ -452,14 +476,8 @@ $stream = new WritingSplitIndexStream(
452476$stream->open();
453477
454478// build sitemap.xml index file and sitemap1.xml, sitemap2.xml, sitemapN.xml with URLs
455- $i = 0;
456479foreach ($builders as $url) {
457480 $stream->push($url);
458-
459- // not forget free memory
460- if (++$i % 100 === 0) {
461- gc_collect_cycles();
462- }
463481}
464482
465483// you can add a link to a sitemap created earlier
@@ -475,6 +493,31 @@ sitemap.xml
475493sitemap1.xml
476494sitemap2.xml
477495sitemap3.xml
496+ sitemap_news.xml
497+ ```
498+
499+ Result ` sitemap.xml ` :
500+
501+ ``` xml
502+ <?xml version =" 1.0" encoding =" UTF-8" ?>
503+ <sitemapindex xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : schemaLocation =" http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" xmlns =" http://www.sitemaps.org/schemas/sitemap/0.9" >
504+ <sitemap >
505+ <loc >https://example.com/sitemap1.xml</loc >
506+ <lastmod >2020-06-15T13:39:46+03:00</lastmod >
507+ </sitemap >
508+ <sitemap >
509+ <loc >https://example.com/sitemap2.xml</loc >
510+ <lastmod >2020-06-15T13:39:46+03:00</lastmod >
511+ </sitemap >
512+ <sitemap >
513+ <loc >https://example.com/sitemap3.xml</loc >
514+ <lastmod >2020-06-15T13:39:46+03:00</lastmod >
515+ </sitemap >
516+ <sitemap >
517+ <loc >https://example.com/sitemap_news.xml</loc >
518+ <lastmod >2020-06-15T13:39:46+03:00</lastmod >
519+ </sitemap >
520+ </sitemapindex >
478521```
479522
480523## Split URLs in groups
0 commit comments