From efc1d38efd54dc6ed3c6d0d02648c2c966880e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Poo-Caama=C3=B1o?= Date: Thu, 31 Oct 2013 13:21:56 -0700 Subject: [PATCH] Fix invalid atom feed id:tag Fixes #1039: The atom feed generated produces an invalid attribute id:tag when SITEURL has something different that http or it contain a subdirectory, such as: * https://myblog.com/ * https://mysite.com/blog * http://mysite.com/blog --- pelican/writers.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pelican/writers.py b/pelican/writers.py index 6cf5232d..fec0348b 100644 --- a/pelican/writers.py +++ b/pelican/writers.py @@ -8,6 +8,9 @@ import logging if not six.PY3: from codecs import open + from urlparse import urlparse +else: + from urllib.parse import urlparse from feedgenerator import Atom1Feed, Rss201rev2Feed from jinja2 import Markup @@ -41,11 +44,13 @@ class Writer(object): def _add_item_to_the_feed(self, feed, item): title = Markup(item.title).striptags() + link = '%s/%s' % (self.site_url, item.url) feed.add_item( title=title, - link='%s/%s' % (self.site_url, item.url), - unique_id='tag:%s,%s:%s' % (self.site_url.replace('http://', ''), - item.date.date(), item.url), + link=link, + unique_id='tag:%s,%s:%s' % (urlparse(link).netloc, + item.date.date(), + urlparse(link).path.lstrip('/')), description=item.get_content(self.site_url), categories=item.tags if hasattr(item, 'tags') else None, author_name=getattr(item, 'author', ''),