news icon indicating copy to clipboard operation
news copied to clipboard

[Bug] Google News Sitemap not working

Open bh-teufels opened this issue 1 year ago • 7 comments

Bug Report

Current Behavior Getting following error on google news sitemap:

This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.

Expected behavior/output Getting sitemap of the news with the Google News Template

Environment

  • TYPO3 version(s): 11.5.14
  • PHP 8.1.2
  • news version: 9.4.0
  • Is your TYPO3 installation set up with Composer (Composer Mode): yes

Configuration

plugin.tx_seo {
    config {
        xmlSitemap {
            sitemaps {
                news {
                    provider = GeorgRinger\News\Seo\NewsXmlSitemapDataProvider
                    config {
                        # exclude internal & external news
                        excludedTypes = 1,2
                        additionalWhere =

                        sortField = datetime
                        lastModifiedField = tstamp
                        #Speicherort der Beiträge
                        pid = 123
                        recursive = 2
                        url {
                            #PageID der Detailseite
                            pageId = 124

                            #To enable the category detail page handling, set useCategorySinglePid = 1
                            useCategorySinglePid = 0

                            #add date to URL
                            #hrDate = 0
                            #hrDate {
                            #    day = j
                            #    month = n
                            #    year = Y
                            #}

                            fieldToParameterMap {
                                uid = tx_news_pi1[news]
                            }

                            additionalGetParameters {
                                tx_news_pi1.controller = News
                                tx_news_pi1.action = detail
                            }
                            useCacheHash = 1
                        }
                    }
                }
            }
        }
        googleNewsSitemap {
            sitemaps {
                news < plugin.tx_seo.config.xmlSitemap.sitemaps.news
                news {
                    config {
                        template = EXT:news/Resources/Private/Templates/News/GoogleNews.xml
                        googleNews = 1
                    }
                }
            }
        }
    }
}

seo_sitemap_news < seo_sitemap
seo_sitemap_news {
    typeNum = 1533906436
    10.sitemapType = googleNewsSitemap
}

bh-teufels avatar Aug 11 '22 13:08 bh-teufels

take a look at https://github.com/peterkraume/news/commit/4561cbd58ed4a04e5684caf89461bf5de5d2674a IMO it should be template=GoogleNews. can you test that with latest news main version?

georgringer avatar Aug 22 '22 18:08 georgringer

i tried with both template = EXT:news/Resources/Private/Templates/News/GoogleNews.xml template = GoogleNews

but has made no difference

with news 9.4.0 i am already on the latest version or should i use directly the main branch?

bh-teufels avatar Aug 23 '22 06:08 bh-teufels

please test main branch for that feature. btw the google news does have a restriction of 2 days. so the news must be max 2 days old!

georgringer avatar Aug 23 '22 06:08 georgringer

I could get this to work either with news 10.0.1 and TYPO3 11.

chriskrj avatar Oct 11 '22 07:10 chriskrj

Hi, there is 3 things going on here. The sortfield should be specified as tstamp, the template path for the SEO extension should be added and the template file should be edited since settings are not read. Then it works.

It concerns version 9.4.0

Georg maybe you can add this to the documentation.

Example typoscript :

plugin.tx_seo.config {
    xmlSitemap {
        sitemaps {
            news {
                provider = GeorgRinger\News\Seo\NewsXmlSitemapDataProvider
                config {
                    table = tx_news_domain_model_news
                    additionalWhere =
                    sortField = sorting
                    lastModifiedField = tstamp
                    changeFreqField = sitemap_changefreq
                    priorityField = sitemap_priority
                    pid = 107
                    recursive = 2
                    url {
                        pageId = 46
                        fieldToParameterMap {
                            uid = tx_news_pi1[news]
                        }

                        additionalGetParameters {
                            tx_news_pi1.controller = News
                            tx_news_pi1.action = detail
                        }

                        useCacheHash = 1
                    }
                }
            }

            events < plugin.tx_seo.config.xmlSitemap.sitemaps.news
            events {
                config {
                    pid = 108
                    url {
                        pageId = 47
                    }
                }
            }
        }
    }

    googleNewsSitemap.sitemaps.news < plugin.tx_seo.config.xmlSitemap.sitemaps.news
    googleNewsSitemap.sitemaps.news {
        config {
            sortField = tstamp
            template = GoogleNews
            googleNews = 1
        }
    }
}

google_news_sitemap < seo_sitemap
google_news_sitemap {
    typeNum = 1533906436
    10.sitemapType = googleNewsSitemap
}

In constants:

Note that when using the EXT:news/Resources/Private/Templates/News/GoogleNews.xml, Google will produce an error since the news:name and news:language are not filled in. The settings are not read. So you might put this template local and fill it in.

plugin.tx_seo {
    view {
        templateRootPath = EXT:Yourextension/Resources/Private/Templates/News/
    }
}

In config.yaml :

routeEnhancers:
  PageTypeSuffix:
    type: PageType
    default: /
    index: ''
    map:
      sitemap.xml: 1533906435
      google_news_sitemap.xml: 1533906436

Now after clearing cache xxx.com/google_news_sitemap.xml should work

Zillion01 avatar Oct 13 '22 11:10 Zillion01

Instead of mentioning the tstamp as sortfield, another solution (maybe better) is to change news/Classes/Seo/NewsXmlSitemapDataProvider.php line 87

        if ($forGoogleNews) {
            $constraints[] = $queryBuilder->expr()->gt($sortField, (new \DateTime('-2 days'))->getTimestamp());
        }

in

        if ($forGoogleNews) {
            $constraints[] = $queryBuilder->expr()->gt('tstamp', (new \DateTime('-2 days'))->getTimestamp());
        }

Zillion01 avatar Oct 13 '22 11:10 Zillion01

The Google Sitemap stoppped completely working, just 0 found. TYPO3 11.5.27 and News 9 and 10.

Zillion01 avatar May 12 '23 12:05 Zillion01