Repository: tlienart/Franklin.jl
Pull request #686 (2020-11-01 16:36:22)

Omit index.html from URLs in feed.xml.
Is this OK or does it have to include `index.html`? I could not find anything online.

fredrikekre: I guess the same could be done for `sitemap.xml`?

Patch:
diff --git a/src/manager/rss_generator.jl b/src/manager/rss_generator.jl
index f5093850..be87a0cb 100644
--- a/src/manager/rss_generator.jl
+++ b/src/manager/rss_generator.jl
@@ -61,7 +61,7 @@ $SIGNATURES
 Create an `RSSItem` out of the provided fields defined in the page vars.
 """
 function add_rss_item()
-    link  = url_curpage()
+    link  = get_url(url_curpage())
     title = jor("rss_title", "title")
     descr = jor("rss", "rss_description")
 
@@ -144,14 +144,16 @@ function rss_generator()::Nothing
         rss_path = joinpath(path(:tag), tag, "feed.xml")
         ## Filter items containing this tag only
         rss_items = OrderedDict{String,RSSItem}(k => v[1] for (k, v) in RSS_DICT_SORTED if tag ∈ v[2])
+        ## Find the relative path for the tag-feeds
+        rss_rel = strip(globvar("tag_page_path"), '/') * "/" * tag * "/"
         ## Write the file
-        write_rss_xml(rss_path, rss_title, rss_descr, rss_link, rss_items)
+        write_rss_xml(rss_path, rss_title, rss_descr, rss_link, rss_items, rss_rel)
     end
 
     return nothing
 end
 
-function write_rss_xml(rss_path, rss_title, rss_descr, rss_link, rss_items)
+function write_rss_xml(rss_path, rss_title, rss_descr, rss_link, rss_items, rss_rel="")
     # is there an RSS file already? if so remove it
     isfile(rss_path) && rm(rss_path)
     # make sure the directory exists
@@ -166,7 +168,7 @@ function write_rss_xml(rss_path, rss_title, rss_descr, rss_link, rss_items)
           <title>$rss_title</title>
           <description><![CDATA[$(fix_relative_links(rss_descr, rss_link))]]></description>
           <link>$rss_link</link>
-          <atom:link href="$(rss_link)feed.xml" rel="self" type="application/rss+xml" />
+          <atom:link href="$(rss_link)$(rss_rel)feed.xml" rel="self" type="application/rss+xml" />
         """)
 
 


Test patch:
diff --git a/test/global/rss_sitemap.jl b/test/global/rss_sitemap.jl
index 7c9af194..eef1efca 100644
--- a/test/global/rss_sitemap.jl
+++ b/test/global/rss_sitemap.jl
@@ -9,7 +9,7 @@
     @test occursin(raw"""<description><![CDATA[Example website using Franklin
   ]]></description>""", fc)
     @test !occursin(raw"""<author>""", fc)
-    @test occursin(raw"""<link>https://tlienart.github.io/FranklinTemplates.jl/menu1/index.html</link>""", fc)
+    @test occursin(raw"""<link>https://tlienart.github.io/FranklinTemplates.jl/menu1/</link>""", fc)
     @test occursin(raw"""<description><![CDATA[A short description of the page which would serve as <strong>blurb</strong> in a <code>RSS</code> feed;""", fc)
 end
 
diff --git a/test/manager/rss.jl b/test/manager/rss.jl
index f5cdb032..23941c57 100644
--- a/test/manager/rss.jl
+++ b/test/manager/rss.jl
@@ -34,8 +34,8 @@ end
     @test item.author == ""
     @test item.pubDate == Date(2020, 10, 27)
     @test tags == ["foo"]
-    @test F.RSS_DICT["/hey/hello/index.html"][1].description == item.description
-    @test F.RSS_DICT["/hey/hello/index.html"][2] == ["foo"]
+    @test F.RSS_DICT["/hey/hello/"][1].description == item.description
+    @test F.RSS_DICT["/hey/hello/"][2] == ["foo"]
 
     # Page 2 with tags = ["foo", "bar"]
     F.def_LOCAL_VARS!()
@@ -52,8 +52,8 @@ end
     @test item.author == "chuck@norris.com"
     @test item.pubDate == Date(2020, 10, 30)
     @test tags == ["foo", "bar"]
-    @test F.RSS_DICT["/hey/ho/index.html"][1].description == item.description
-    @test F.RSS_DICT["/hey/ho/index.html"][2] == ["foo", "bar"]
+    @test F.RSS_DICT["/hey/ho/"][1].description == item.description
+    @test F.RSS_DICT["/hey/ho/"][2] == ["foo", "bar"]
 
     # Generation
     F.PATHS[:folder] = td
@@ -64,8 +64,11 @@ end
     fc = read(feed, String)
     @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)
+    @test occursin("<link>https://github.com/tlienart/Franklin.jl/hey/hello/</link>", fc)
     @test occursin("<pubDate>Fri, 30 Oct 2020 00:00:00 UT</pubDate>", fc)
     @test occursin("<pubDate>Tue, 27 Oct 2020 00:00:00 UT</pubDate>", fc)
+    @test occursin("<atom:link href=\"https://github.com/tlienart/Franklin.jl/feed.xml\" rel=\"self\" type=\"application/rss+xml\" />", fc)
     @test findfirst("Fri, 30 Oct 2020", fc) < findfirst("27 Oct 2020", fc) # ordered by pubDate
 
     ## Tag filtered feeds
@@ -77,6 +80,7 @@ end
     @test occursin("<description><![CDATA[Page with tag foo.", foo_feed)
     @test occursin("<pubDate>Fri, 30 Oct 2020 00:00:00 UT</pubDate>", foo_feed)
     @test occursin("<pubDate>Tue, 27 Oct 2020 00:00:00 UT</pubDate>", foo_feed)
+    @test occursin("<atom:link href=\"https://github.com/tlienart/Franklin.jl/tag/foo/feed.xml\" rel=\"self\" type=\"application/rss+xml\" />", foo_feed)
     @test findfirst("Fri, 30 Oct 2020", foo_feed) < findfirst("27 Oct 2020", foo_feed) # ordered by pubDate
     ### bar tag
     feed = joinpath(F.PATHS[:tag], "bar", "feed.xml")
@@ -86,4 +90,5 @@ end
     @test !occursin("<description><![CDATA[Page with tag foo.", bar_feed)
     @test occursin("<pubDate>Fri, 30 Oct 2020 00:00:00 UT</pubDate>", bar_feed)
     @test !occursin("<pubDate>Tue, 27 Oct 2020 00:00:00 UT</pubDate>", bar_feed)
+    @test occursin("<atom:link href=\"https://github.com/tlienart/Franklin.jl/tag/bar/feed.xml\" rel=\"self\" type=\"application/rss+xml\" />", bar_feed)
 end
diff --git a/test/utils/warnings.jl b/test/utils/warnings.jl
index 561cce02..39eb0967 100644
--- a/test/utils/warnings.jl
+++ b/test/utils/warnings.jl
@@ -28,7 +28,7 @@ end
     s = @capture_out F.add_rss_item()
     @test occursin("Warning: in <input string>", s)
     @test occursin("An RSS description was found but without title", s)
-    @test occursin("for page '/hey/ho/index.html'.", s)
+    @test occursin("for page '/hey/ho/'.", s)
 end
 
 @testset "warn-paginate" begin