Skip to content

Commit

Permalink
fix: Add missing <news> sitemap entry implementation that didn't ma…
Browse files Browse the repository at this point in the history
…ke it over to the Craft 5 version of the plugin ([#1551](#1551))
  • Loading branch information
khalwat committed Dec 28, 2024
1 parent 0ece657 commit e44edb7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/helpers/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = '<news:news>';
$lines[] = '<news:publication>';
$lines[] = '<news:name>' . $metaBundle->metaSitemapVars->newsPublicationName . '</news:name>';
$lines[] = '<news:language>' . $language . '</news:language>';
$lines[] = '</news:publication>';
$lines[] = '<news:publication_date>' . $dateUpdated->format(DateTime::W3C) . '</news:publication_date>';
$lines[] = '<news:title>' . $element->title . '</news:title>';
$lines[] = '</news:news>';
}
}
// Handle any Assets
if ($metaBundle->metaSitemapVars->sitemapAssets) {
// Regular Assets fields
Expand Down

0 comments on commit e44edb7

Please sign in to comment.