Repository: tlienart/Franklin.jl
Pull request #748 (2020-12-28 09:46:02)

Apply CDATASection to title of rss
In `feed.xml`, the description has a CDATA section, but the title does not. I propose to apply the CDATA section to the title as well.
This change will allow us to use `&`, `<` for article titles.

Thank you for developing such a great package!

tlienart: Cool thank you, this seems useful! could you fix the RSS tests? otherwise I'll do this a bit later. Thanks!
5ebec: I'm sorry, I'll fix it right now.
5ebec: The current tests passed, but do we need to change `test/manager/rss.jl`?

For example, add the following after line 64 of it.
```julia
    @test occursin("<title><![CDATA[title 2]]></title>", fc)
    @test occursin("<title><![CDATA[title 1]]></title>", fc)
````

tlienart: Don't hesitate to add tests, possibly adding comments explaining what they are, thanks! I'll check all this soon and merge, thanks again for contributing 😊
5ebec: Thank you very much for your kind reply.
I have added tests for the RSS title.
tlienart: Fantastic,  thank  you!

Patch:
diff --git a/src/manager/rss_generator.jl b/src/manager/rss_generator.jl
index 46b588e9..18868d92 100644
--- a/src/manager/rss_generator.jl
+++ b/src/manager/rss_generator.jl
@@ -165,7 +165,7 @@ function write_rss_xml(rss_path, rss_title, rss_descr, rss_link, rss_items, rss_
         """
         <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
         <channel>
-          <title>$rss_title</title>
+          <title><![CDATA[$rss_title]]></title>
           <description><![CDATA[$(fix_relative_links(rss_descr, rss_link))]]></description>
           <link>$rss_link</link>
           <atom:link href="$(rss_link)$(rss_rel)feed.xml" rel="self" type="application/rss+xml" />
@@ -179,7 +179,7 @@ function write_rss_xml(rss_path, rss_title, rss_descr, rss_link, rss_items, rss_
         write(rss_buff,
           """
             <item>
-              <title>$(v.title)</title>
+              <title><![CDATA[$(v.title)]]></title>
               <link>$(full_link)</link>
               <description><![CDATA[$(fix_relative_links(v.description, rss_link))<br><a href=\"$(full_link)\">Read more</a>]]></description>
           """)


Test patch:
diff --git a/test/global/rss_sitemap.jl b/test/global/rss_sitemap.jl
index eef1efca..8edc4e42 100644
--- a/test/global/rss_sitemap.jl
+++ b/test/global/rss_sitemap.jl
@@ -5,7 +5,7 @@
     fc = prod(readlines(f, keep=true))
 
     @test occursin(raw"""<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">""", fc)
-    @test occursin(raw"""<title>Franklin Template</title>""", fc)
+    @test occursin(raw"""<title><![CDATA[Franklin Template]]></title>""", fc)
     @test occursin(raw"""<description><![CDATA[Example website using Franklin
   ]]></description>""", fc)
     @test !occursin(raw"""<author>""", fc)
diff --git a/test/manager/rss.jl b/test/manager/rss.jl
index fce339a1..b9118edd 100644
--- a/test/manager/rss.jl
+++ b/test/manager/rss.jl
@@ -62,6 +62,8 @@ end
     feed = joinpath(F.PATHS[:site], "feed.xml")
     @test isfile(feed)
     fc = read(feed, String)
+    @test occursin("<title><![CDATA[title 2]]></title>", fc)
+    @test occursin("<title><![CDATA[title 1]]></title>", fc)
     @test occursin("<description><![CDATA[A <strong>description</strong> done. Page with tags foo and bar.", fc)
     @test occursin("<description><![CDATA[Page with tag foo.", fc)
     @test occursin("<link>https://github.com/tlienart/Franklin.jl/hey/ho/</link>", fc)
@@ -80,6 +82,8 @@ end
     feed = joinpath(F.PATHS[:tag], "foo", "feed.xml")
     @test isfile(feed)
     foo_feed = read(feed, String)
+    @test occursin("<title><![CDATA[title 2]]></title>", foo_feed)
+    @test occursin("<title><![CDATA[title 1]]></title>", foo_feed)
     @test occursin("<description><![CDATA[A <strong>description</strong> done. Page with tags foo and bar.", foo_feed)
     @test occursin("<description><![CDATA[Page with tag foo.", foo_feed)
     @test occursin("<pubDate>Fri, 30 Oct 2020 00:00:00 UT</pubDate>", foo_feed)
@@ -90,6 +94,8 @@ end
     feed = joinpath(F.PATHS[:tag], "bar", "feed.xml")
     @test isfile(feed)
     bar_feed = read(feed, String)
+    @test occursin("<title><![CDATA[title 2]]></title>", bar_feed)
+    @test !occursin("<title><![CDATA[title 1]]></title>", bar_feed)
     @test occursin("<description><![CDATA[A <strong>description</strong> done. Page with tags foo and bar.", bar_feed)
     @test !occursin("<description><![CDATA[Page with tag foo.", bar_feed)
     @test occursin("<pubDate>Fri, 30 Oct 2020 00:00:00 UT</pubDate>", bar_feed)