renard / o-blog

Standalone orgmode blog exporter. DEPECATED, NOT MAINTAINED
http://renard.github.com/o-blog-v2
260 stars 58 forks source link

Feature Request: Truncate HTML in Atom Feed #31

Closed ghost closed 12 years ago

ghost commented 12 years ago

Can Lisp strip HTML tags and send only a selected number of words to a template, specifically the feed template?

renard commented 12 years ago

You can do something like:

(with-temp-buffer
     (insert (ob:post-content-html POST))
     (let ((html2text-remove-tag-list (loop for tag in html-tag-alist
                          c-collect-line-comments (car tag))))
       (html2text)
       (goto-char (point-min))
       (loop for x from 0 below 100 do (forward-word))
       (buffer-substring-no-properties (point-min) (point))))

Just be sure to (require 'html2text) and (require 'sgml-mode).

OTOH the returned text is just plain text (no HTML formating)

renard commented 12 years ago

In the last master commits I add ob:get-post-excerpt function which might do what you want.

ghost commented 12 years ago

It looks great and should do exactly what I want, but it keeps giving me this output: "Lisp error in nil: (void-function ellipsis)".

I did require html2text and sgml-mode, so I am not sure what the problem is.

In the blog_rss template, I replaced the current line to get the post content with " (format "%s" (ob:get-post-excerpt p))".

ghost commented 12 years ago

Not quite there yet. I am getting the following error now: "Lisp error in nil: (error Expected a loop keyword, found c-collect-line-comments)"

renard commented 12 years ago

Stupid completion :-(

Done now.

Anyway I found that some HTML are not stripped correctly.

ghost commented 12 years ago

Awesome! It is working now.

That is why I don't use automatic auto-completion, preferring triggered hippie + dabbrev.

Note: You are right about the HTML not being fully stripped. This can cause invalid XML. I believe this is a HTML2TEXT problem and not an issue with your code, which is working perfectly, so I will look into it and see what I can come up with.

renard commented 12 years ago

Yep. Maybe it's time to find a more clever solution.