Skip to content

Commit

Permalink
Adds CDATA sections to atom.xml, fixes imathis#198
Browse files Browse the repository at this point in the history
  • Loading branch information
fhemberger committed Oct 4, 2011
1 parent e219f9f commit 6241d28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 5 additions & 7 deletions .themes/classic/source/atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@ layout: nil
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

<title>{{ site.title | xml_escape }}</title>
<title><![CDATA[{{ site.title }}]]></title>
<link href="{{ site.url }}/atom.xml" rel="self"/>
<link href="{{ site.url }}/"/>
<updated>{{ site.time | date_to_xmlschema }}</updated>
<id>{{ site.url }}/</id>
<author>
<name>{{ site.author | xml_escape }}</name>
{% if site.email %}
<email>{{ site.email | xml_escape }}</email>
{% endif %}
<name><![CDATA[{{ site.author | strip_html }}]]></name>
{% if site.email %}<email><![CDATA[{{ site.email }}]]></email>{% endif %}
</author>
<generator uri="http://octopress.org/">Octopress</generator>

{% for post in site.posts limit: 20 %}
<entry>
<title>{{ post.title | xml_escape }}</title>
<title type="html"><![CDATA[{{ post.title | cdata_escape }}]]></title>
<link href="{{ site.url }}{{ post.url }}"/>
<updated>{{ post.date | date_to_xmlschema }}</updated>
<id>{{ site.url }}{{ post.id }}</id>
<content type="html">{{ post.content | expand_urls: site.url | xml_escape }}</content>
<content type="html"><![CDATA[{{ post.content | expand_urls: site.url | cdata_escape }}]]></content>
</entry>
{% endfor %}
</feed>
5 changes: 5 additions & 0 deletions plugins/octopress_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def raw_content(input)
return (content.nil?) ? input : content
end

# Escapes CDATA sections in post content
def cdata_escape(input)
input.gsub(/<!\[CDATA\[/, '&lt;![CDATA[').gsub(/\]\]>/, ']]&gt;')
end

# Replaces relative urls with full urls
def expand_urls(input, url='')
url ||= '/'
Expand Down

0 comments on commit 6241d28

Please sign in to comment.