bastibe / org-static-blog

A static site generator using org-mode
BSD 3-Clause "New" or "Revised" License
341 stars 74 forks source link

Relative links for images in RSS output #57

Open MassimoLauria opened 4 years ago

MassimoLauria commented 4 years ago

Hi,

I have an issue generating a proper RSS.

I am using org-mode version 9.2.6 and org-static-blog 1.3.0 and my configuration includes

(setq org-static-blog-publish-url "https://example.com/subfolder/")
(setq org-static-blog-publish-directory "~/blog/"))

If the blog post contains an image which for example is originally included as [[file:assets/image.jpg]] in the org file, I obtain

<img src="assets/image.jpg"> 

in both the HTML and the RSS output. But in the latter case this seems to be an issue, because I cannot see the images of the post in any RSS reader. Furthermore similar issues apply to the footnote links.

Reading the pages from the browser is fine since relative links are fine there. I am afraid that producing the RSS export just by cutting and pasting the HTML export is not the correct way.

Best,

MassimoLauria commented 4 years ago

My horrible solution so far had been to add "fix" the rss file using this ugly workaround, which I run on the rss.xml file before deploying it.

(defun fixrss ()
  "Fix broken <img src=\"..\"> links in rss.
org-static-blog naturally produces the RSS feed joining together
the html code from the blog webpages. This causes image links to
be realtive instead of aboslute, which makes the blog impossible
to read via RSS readers.

This is a hackish workaround..."
  (interactive)
  (goto-char (point-min))
  (let ((imgsrc-pattern "src=\\\"\\([^\"]*\\)\\\"")
        (replace-pattern (concat "src=\"" org-static-blog-publish-url "\\1" "\""))
        (oldstr))
    (while (search-forward-regexp imgsrc-pattern nil t)
      (setq oldstr (match-string 1))
      (cond
       ((string-match "^http" oldstr) (message (concat "Nothig to do for " oldstr)))
       ((string-match "^/"    oldstr) (message (concat "Nothig to do for " oldstr)))
       (t (message (concat "Convert " oldstr))
          (replace-match replace-pattern))))
    (save-buffer)))
bastibe commented 4 years ago

I believe links are simply copied verbatim.

The simplest solution is to use absolute links instead of relative links, i.e. [[http://yourdomain.com/assets/image.jpg]]. That's what I am doing currently (and it is not a pretty solution).

A much better solution would modify org-static-blog-post-bare so relative links and image links are automatically translated, much like org-static-blog-get-absolute-url does for page links. And if that's not possible, modify org-static-blog-render-post-content much like you did in your "ugly workaround".

Would you like to try your hand at a pull request to this effect?

MassimoLauria commented 4 years ago

I honestly would not like to but absolute links in the HTML output, because it would be a pain to work on draft/posts offline. I believe that the "right solution" is to use two different exporter for HTML and RSS. Indeed Ogbe.net uses the `org-publish' mechanism and does that. In this way he has a completely relocatable HTML output (all links are relative) and a well formatted RSS (all links are absolute).

I don't think I want to change the current status of org-static-blog. I'd rather use this hack for the time being... and well feel free to integrate it with org-static-blog-assemble-rss. For now I've messed with your tool more than enough.

bastibe commented 4 years ago

OK, no problem.