Browse Source

feat: wrapping xml text in ctag to avoid error on special chars

danilo silva 4 years ago
parent
commit
af312b946a
1 changed files with 15 additions and 15 deletions
  1. 15 15
      lib/podcast_feed_web/templates/feed/feed.xml.eex

+ 15 - 15
lib/podcast_feed_web/templates/feed/feed.xml.eex

@@ -2,44 +2,44 @@
 <rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:itunesu="http://www.itunesu.com/feed" version="2.0">
   <channel>
     <link><%= @podcast.link %></link>
-    <language><%= @podcast.language %></language>
+    <language><![CDATA[<%= @podcast.language %>]]></language>
     <copyright>&#xA9;2022</copyright>
-    <webMaster><%= @podcast.webmaster %></webMaster>
-    <managingEditor><%= @podcast.webmaster %></managingEditor>
+    <webMaster><![CDATA[<%= @podcast.webmaster %>]]></webMaster>
+    <managingEditor><![CDATA[<%= @podcast.webmaster %>]]></managingEditor>
     <image>
       <url><%= @podcast.image.url %></url>
-      <title><%= @podcast.image.title %></title>
+      <title><![CDATA[<%= @podcast.image.title %>]]></title>
       <link><%= @podcast.image.link %></link>
     </image>
     <itunes:owner>
-      <itunes:name><%= @podcast.owner.name %></itunes:name>
-      <itunes:email><%= @podcast.owner.email %></itunes:email>
+      <itunes:name><![CDATA[<%= @podcast.owner.name %>]]></itunes:name>
+      <itunes:email><![CDATA[<%= @podcast.owner.email %>]]></itunes:email>
     </itunes:owner>
     <itunes:category text="<%= @podcast.category %>">
       <itunes:category text="<%= @podcast.category %>" />
     </itunes:category>
     <itunes:keywords><%= @podcast.keywords |> Enum.join(", ") %></itunes:keywords>
-    <itunes:explicit><%= @podcast.explicit %></itunes:explicit>
+    <itunes:explicit><![CDATA[<%= @podcast.explicit %>]]></itunes:explicit>
     <itunes:image href="<%= @podcast.image.url %>" />
     <atom:link href="http://www.ape-alveare.it/podcast.xml" rel="self" type="application/rss+xml" />
     <pubDate><%= @podcast.pubDate |> Calendar.DateTime.Format.rfc2822 %></pubDate>
-    <title><%= @podcast.title %></title>
-    <itunes:author>College, school, or department owning the podcast</itunes:author>
-    <description><%= @podcast.description %></description>
-    <itunes:summary><%= @podcast.description %></itunes:summary>
-    <itunes:subtitle><%= @podcast.description %></itunes:subtitle>
+    <title><![CDATA[<%= @podcast.title %>]]></title>
+    <itunes:author><![CDATA[<%= @podcast.owner.name %>]]></itunes:author>
+    <description><![CDATA[<%= @podcast.description %>]]></description>
+    <itunes:summary><![CDATA[<%= @podcast.description %>]]></itunes:summary>
+    <itunes:subtitle><![CDATA[<%= Regex.run(~r/\A(.{0,255})(?: |\.|\Z)/,  @podcast.description) |> List.last() %>]]></itunes:subtitle>
     <lastBuildDate><%= @podcast.pubDate |> Calendar.DateTime.Format.rfc2822 %></lastBuildDate>
     <%= for item <- @items do %>
     <item>
-      <title><%= item.title %></title>
+      <title><![CDATA[<%= item.title %>]]></title>
       <link><%= item.link %></link>
       <pubDate><%= item.pubDate |> Calendar.DateTime.Format.rfc2822 %></pubDate>
-      <description><%= item.description %></description>
+      <description><![CDATA[<%= item.description %>]]></description>
       <enclosure url="<%= item.link %>" length="<%= item.length %>" type="audio/mpeg"/>
       <guid><%= item.link %></guid>
       <itunes:duration><%= item.length |> format_length %></itunes:duration>
       <itunes:summary><%= item.summary %></itunes:summary>
-      <itunes:keywords><%= item.keywords |> Enum.join(", ") %></itunes:keywords>
+      <itunes:keywords><![CDATA[<%= item.keywords |> Enum.join(", ") %>]]></itunes:keywords>
       <itunes:explicit><%= item.explicit %></itunes:explicit>
     </item>
     <% end %>