From e44edb732764dd71418788a528932b8f5a3c5ef6 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 28 Dec 2024 13:52:50 -0500 Subject: [PATCH] fix: Add missing `` sitemap entry implementation that didn't make it over to the Craft 5 version of the plugin ([#1551](https://github.com/nystudio107/craft-seomatic/issues/1551)) --- src/helpers/Sitemap.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/helpers/Sitemap.php b/src/helpers/Sitemap.php index 440049219..5217c1fe7 100644 --- a/src/helpers/Sitemap.php +++ b/src/helpers/Sitemap.php @@ -309,6 +309,25 @@ public static function generateSitemap(array $params): ?string } } } + // Handle news sitemaps https://developers.google.com/search/docs/crawling-indexing/sitemaps/news-sitemap + if ((bool)$metaBundle->metaSitemapVars->newsSitemap) { + $now = new DateTime(); + $interval = $now->diff($dateUpdated); + if ($interval->days <= 2) { + $language = strtolower($element->getLanguage()); + if (!str_starts_with($language, 'zh')) { + $language = substr($language, 0, 2); + } + $lines[] = ''; + $lines[] = ''; + $lines[] = '' . $metaBundle->metaSitemapVars->newsPublicationName . ''; + $lines[] = '' . $language . ''; + $lines[] = ''; + $lines[] = '' . $dateUpdated->format(DateTime::W3C) . ''; + $lines[] = '' . $element->title . ''; + $lines[] = ''; + } + } // Handle any Assets if ($metaBundle->metaSitemapVars->sitemapAssets) { // Regular Assets fields