Repository: getnikola/nikola

Issue:
Wrong img src url in rss
Hi,

I'm hosting a nikola instance at http://acaia.ca/~tiago/. The generated RSS is removing the "/~tiago/" part from image sources, so I get many broken links in a feed reader. 

Example: img alt="/images/umapper.png" src="http://acaia.ca/images/umapper.png"

It should be img alt="/images/umapper.png" src="http://acaia.ca/~tiago/images/umapper.png"

The config file is correct and the HTML is also generated correctly. I'm not sure if it's an issue with PyRSS2Gen or with nikola itself. Please let me know if you need further information.

Regards,

Wrong img src url in rss
Hi,

I'm hosting a nikola instance at http://acaia.ca/~tiago/. The generated RSS is removing the "/~tiago/" part from image sources, so I get many broken links in a feed reader. 

Example: img alt="/images/umapper.png" src="http://acaia.ca/images/umapper.png"

It should be img alt="/images/umapper.png" src="http://acaia.ca/~tiago/images/umapper.png"

The config file is correct and the HTML is also generated correctly. I'm not sure if it's an issue with PyRSS2Gen or with nikola itself. Please let me know if you need further information.

Regards,



Discussion:
What's your version of Nikola, and what's in your BASE_URL setting?

Nikola v6.4.0
BASE_URL is not set.
SITE_URL = "http://acaia.ca/~tiago/"

I'd have to check, to be honest. Can you put a dump of the site somewhere private and mail me the URL at ralsina (at) kde org?

I think I found the issue.

In the mentioned [post](http://acaia.ca/~tiago/posts/new-project-pymapper-a-cross-platform-gui-for-libmapper/index.rst):

``` rst
.. figure:: /images/umapper.png

    Umapper (from http://sourceforge.net/projects/umapper)
```

Nikola tries to be intelligent here, and makes those paths relative to `/~tiago/`.  However, the dates in RSS are not treated this way, and they are still relative to `/`, as the URL would suggest.

We should probably find this “intelligence” bit and (a) nuke it, or (b) extend it to RSS.

@tiagovaz I meant a dump of the sources and config of your site, not the output :-)

But I see, the images links are different in the RSS. 

I have reproduced this.

The problem seems to be in Post.text(), where document.make_links_absolute is removing the path, so the image ends up hanging from the root of the site instead of ~tiago

Why that doesn't happen with the actual post page is troubling.

What's your version of Nikola, and what's in your BASE_URL setting?

Nikola v6.4.0
BASE_URL is not set.
SITE_URL = "http://acaia.ca/~tiago/"

I'd have to check, to be honest. Can you put a dump of the site somewhere private and mail me the URL at ralsina (at) kde org?

I think I found the issue.

In the mentioned [post](http://acaia.ca/~tiago/posts/new-project-pymapper-a-cross-platform-gui-for-libmapper/index.rst):

``` rst
.. figure:: /images/umapper.png

    Umapper (from http://sourceforge.net/projects/umapper)
```

Nikola tries to be intelligent here, and makes those paths relative to `/~tiago/`.  However, the dates in RSS are not treated this way, and they are still relative to `/`, as the URL would suggest.

We should probably find this “intelligence” bit and (a) nuke it, or (b) extend it to RSS.

@tiagovaz I meant a dump of the sources and config of your site, not the output :-)

But I see, the images links are different in the RSS. 

I have reproduced this.

The problem seems to be in Post.text(), where document.make_links_absolute is removing the path, so the image ends up hanging from the root of the site instead of ~tiago

Why that doesn't happen with the actual post page is troubling.


Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -783,14 +783,16 @@ def generic_rss_renderer(self, lang, title, link, description, timeline, output_
         items = []
 
         for post in timeline[:feed_length]:
-            data = post.text(lang, teaser_only=rss_teasers, really_absolute=True, strip_html=rss_plain)
+            old_url_type = self.config['URL_TYPE']
+            self.config['URL_TYPE'] = 'absolute'
+            data = post.text(lang, teaser_only=rss_teasers, strip_html=rss_plain)
             if feed_url is not None and data:
                 # Massage the post's HTML (unless plain)
                 if not rss_plain:
                     # FIXME: this is duplicated with code in Post.text()
                     try:
                         doc = lxml.html.document_fromstring(data)
-                        doc.rewrite_links(lambda dst: self.url_replacer(feed_url, dst, lang))
+                        doc.rewrite_links(lambda dst: self.url_replacer(post.permalink(), dst, lang))
                         try:
                             body = doc.body
                             data = (body.text or '') + ''.join(
@@ -803,7 +805,7 @@ def generic_rss_renderer(self, lang, title, link, description, timeline, output_
                             data = ""
                         else:  # let other errors raise
                             raise(e)
-
+            self.config['URL_TYPE'] = old_url_type
             args = {
                 'title': post.title(lang),
                 'link': post.permalink(lang, absolute=True),
diff --git a/nikola/post.py b/nikola/post.py
--- a/nikola/post.py
+++ b/nikola/post.py
@@ -402,7 +402,7 @@ def _translated_file_path(self, lang):
         else:
             return get_translation_candidate(self.config, self.base_path, sorted(self.translated_to)[0])
 
-    def text(self, lang=None, teaser_only=False, strip_html=False, really_absolute=False):
+    def text(self, lang=None, teaser_only=False, strip_html=False):
         """Read the post file for that language and return its contents.
 
         teaser_only=True breaks at the teaser marker and returns only the teaser.
@@ -426,7 +426,7 @@ def text(self, lang=None, teaser_only=False, strip_html=False, really_absolute=F
                 return ""
             # let other errors raise
             raise(e)
-        base_url = self.permalink(lang=lang, absolute=really_absolute)
+        base_url = self.permalink(lang=lang)
         document.make_links_absolute(base_url)
 
         if self.hyphenate:
@@ -449,11 +449,11 @@ def text(self, lang=None, teaser_only=False, strip_html=False, really_absolute=F
                 if not strip_html:
                     if TEASER_REGEXP.search(data).groups()[-1]:
                         teaser += '<p class="more"><a href="{0}">{1}</a></p>'.format(
-                            self.permalink(lang, absolute=really_absolute),
+                            self.permalink(lang),
                             TEASER_REGEXP.search(data).groups()[-1])
                     else:
                         teaser += READ_MORE_LINK.format(
-                            link=self.permalink(lang, absolute=really_absolute),
+                            link=self.permalink(lang),
                             read_more=self.messages[lang]["Read more"])
                 # This closes all open tags and sanitizes the broken HTML
                 document = lxml.html.fromstring(teaser)


Test patch: