| @@ -724,13 +724,76 @@ | ||
| 724 | 724 | } |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | /** |
| 728 | + * The robots directive for this page. | |
| 729 | + * | |
| 730 | + * Normally "index, follow" with the usual snippet hints, exactly as before. | |
| 731 | + * When the operator has both dropped this content type from the sitemap and | |
| 732 | + * opted in to noindexing excluded types, it becomes "noindex, follow" — | |
| 733 | + * because removing a URL from a sitemap does not stop Google indexing it, | |
| 734 | + * and this page was previously asserting the opposite. | |
| 735 | + * | |
| 736 | + * "follow" is kept deliberately: the page should stop being indexed, but | |
| 737 | + * links out of it (to trips that ARE published) should still be crawled. | |
| 738 | + */ | |
| 739 | + private function robotsDirective(): string | |
| 740 | + { | |
| 741 | + $indexable = 'index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1'; | |
| 742 | + | |
| 743 | + if (!SettingsService::isEnabled('sitemap_noindex_excluded')) { | |
| 744 | + return $indexable; | |
| 745 | + } | |
| 746 | + | |
| 747 | + $sitemapType = $this->sitemapTypeForPage(); | |
| 748 | + if ($sitemapType === '') { | |
| 749 | + return $indexable; | |
| 750 | + } | |
| 751 | + | |
| 752 | + if (!class_exists(\Yatra\Sitemap\SitemapService::class)) { | |
| 753 | + return $indexable; | |
| 754 | + } | |
| 755 | + | |
| 756 | + $sitemap = new \Yatra\Sitemap\SitemapService(); | |
| 757 | + | |
| 758 | + return $sitemap->isTypeEnabled($sitemapType) ? $indexable : 'noindex, follow'; | |
| 759 | + } | |
| 760 | + | |
| 761 | + /** | |
| 762 | + * Map this page onto the sitemap content type that governs it. | |
| 763 | + * | |
| 764 | + * The taxonomy listing pages are published by the sitemap's `archive` type | |
| 765 | + * (the trip listing plus each taxonomy index), so they follow it. | |
| 766 | + * | |
| 767 | + * @return string '' when no sitemap type owns this page. | |
| 768 | + */ | |
| 769 | + private function sitemapTypeForPage(): string | |
| 770 | + { | |
| 771 | + switch ($this->pageType) { | |
| 772 | + case self::PAGE_TYPE_TRIP: | |
| 773 | + return \Yatra\Sitemap\SitemapService::TYPE_TRIP; | |
| 774 | + case self::PAGE_TYPE_DESTINATION: | |
| 775 | + return \Yatra\Sitemap\SitemapService::TYPE_DESTINATION; | |
| 776 | + case self::PAGE_TYPE_ACTIVITY: | |
| 777 | + return \Yatra\Sitemap\SitemapService::TYPE_ACTIVITY; | |
| 778 | + case self::PAGE_TYPE_CATEGORY: | |
| 779 | + return \Yatra\Sitemap\SitemapService::TYPE_CATEGORY; | |
| 780 | + case self::PAGE_TYPE_TRIP_ARCHIVE: | |
| 781 | + case self::PAGE_TYPE_DESTINATION_LISTING: | |
| 782 | + case self::PAGE_TYPE_ACTIVITY_LISTING: | |
| 783 | + case self::PAGE_TYPE_CATEGORY_LISTING: | |
| 784 | + return \Yatra\Sitemap\SitemapService::TYPE_ARCHIVE; | |
| 785 | + default: | |
| 786 | + return ''; | |
| 787 | + } | |
| 788 | + } | |
| 789 | + | |
| 790 | + /** | |
| 728 | 791 | * Output advanced meta tags |
| 729 | 792 | */ |
| 730 | 793 | private function outputAdvancedMetaTags(): void |
| 731 | 794 | { |
| 732 | - echo '<meta name="robots" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1">' . "\n"; | |
| 795 | + echo '<meta name="robots" content="' . esc_attr($this->robotsDirective()) . '">' . "\n"; | |
| 733 | 796 | echo '<link rel="canonical" href="' . esc_url($this->seoData['url']) . '">' . "\n"; |
| 734 | 797 | echo '<meta name="author" content="' . esc_attr($this->seoData['author']) . '">' . "\n"; |
| 735 | 798 | echo '<meta name="publisher" content="' . esc_attr($this->seoData['publisher']) . '">' . "\n"; |
| 736 | 799 | echo '<meta name="lastmod" content="' . esc_attr($this->seoData['modified_time']) . '">' . "\n"; |