georgringer / news

TYPO3 Extension news
GNU General Public License v2.0
260 stars 352 forks source link

[Bug] Google News Sitemap not working #1839

Open bh-teufels opened 1 year ago

bh-teufels commented 1 year ago

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

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
}
georgringer commented 1 year ago

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?

bh-teufels commented 1 year ago

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?

georgringer commented 1 year ago

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!

chriskrj commented 1 year ago

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

Zillion01 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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