Harmonize RSS feed with W3C recommendations

1. Declare Atom schema support
2. Escape international characters in URL
3. Ignore locale in date
This commit is contained in:
Max Kostikov 2019-09-15 14:51:04 +02:00 committed by GitHub
parent 8df8d5f7dd
commit b272020b37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -32,6 +32,11 @@ class pluginRSS extends Plugin {
return $html;
}
private function urlRSS($url)
{
return preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url);
}
private function createXML()
{
@ -54,10 +59,11 @@ class pluginRSS extends Plugin {
);
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
$xml .= '<rss version="2.0">';
$xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
$xml .= '<channel>';
$xml .= '<atom:link href="'.DOMAIN_BASE.'rss.xml" rel="self" type="application/rss+xml" />';
$xml .= '<title>'.$site->title().'</title>';
$xml .= '<link>'.$site->url().'</link>';
$xml .= '<link>'.$this->urlRSS($site->url()).'</link>';
$xml .= '<description>'.$site->description().'</description>';
$xml .= '<lastBuildDate>'.date(DATE_RSS).'</lastBuildDate>';
@ -68,7 +74,7 @@ class pluginRSS extends Plugin {
$page = new Page($pageKey);
$xml .= '<item>';
$xml .= '<title>'.$page->title().'</title>';
$xml .= '<link>'.$page->permalink().'</link>';
$xml .= '<link>'.$this->urlRSS($page->permalink()).'</link>';
$xml .= '<description>'.Sanitize::html($page->contentBreak()).'</description>';
$xml .= '<pubDate>'.$page->date(DATE_RSS).'</pubDate>';
$xml .= '<guid isPermaLink="false">'.$page->uuid().'</guid>';