diff --git a/src/manager/rss_generator.jl b/src/manager/rss_generator.jl index c866b6cf9..7c7c3c723 100644 --- a/src/manager/rss_generator.jl +++ b/src/manager/rss_generator.jl @@ -14,15 +14,17 @@ # 3. save the file struct RSSItem + # -- required fields title::String link::String - description::String - author::String + description::String # note: should not contain
+ # -- optional fields + author::String # note: should be a valid email category::String - comments::String + comments::String # note: should be a valid URL enclosure::String - # guid -- hash of link - pubDate::Date + # guid == link + pubDate::Date # note: should respect RFC822 (https://www.w3.org/Protocols/rfc822/) end const RSS_DICT = Dict{String,RSSItem}() @@ -31,6 +33,17 @@ const RSS_DICT = Dict{String,RSSItem}() """Convenience function for fallback fields""" jor(v::PageVars, a::String, b::String) = ifelse(isempty(first(v[a])), first(v[b]), first(v[a])) +"""Convenience function to remove
and
in RSS description (not supposed to happen)""" +remove_html_ps(s::String)::String = replace(s, r"?p>" => "") + +""" +$SIGNATURES + +RSS should not contain relative links so this finds relative links and prepends them with the +canonical link. +""" +fix_relative_links(s::String, link::String) = + replace(s, r"(href|src)\s*?=\s*?\"\/" => SubstitutionString("\\1=\"$link")) """ $SIGNATURES @@ -41,10 +54,10 @@ function add_rss_item(jdv::PageVars)::RSSItem link = url_curpage() title = jor(jdv, "rss_title", "title") descr = jor(jdv, "rss", "rss_description") - author = jor(jdv, "rss_author", "author") - descr = jd2html(descr; internal=true) + descr = jd2html(descr; internal=true) |> remove_html_ps + author = jdv["rss_author"] |> first category = jdv["rss_category"] |> first comments = jdv["rss_comments"] |> first enclosure = jdv["rss_enclosure"] |> first @@ -61,8 +74,8 @@ function add_rss_item(jdv::PageVars)::RSSItem isnothing(title) && (title = "") isempty(title) && @warn "Found an RSS description but no title for page $link." - RSS_DICT[link] = RSSItem(title, link, descr, - author, category, comments, enclosure, pubDate) + RSS_DICT[link] = RSSItem(title, link, descr, author, + category, comments, enclosure, pubDate) end @@ -88,6 +101,10 @@ function rss_generator()::Nothing The feed will not be (re)generated.""" return nothing end + + endswith(rss_link, "/") || (rss_link *= "/") + rss_descr = jd2html(rss_descr; internal=true) |> remove_html_ps + # is there an RSS file already? if so remove it rss_path = joinpath(PATHS[:folder], "feed.xml") isfile(rss_path) && rm(rss_path) @@ -96,45 +113,39 @@ function rss_generator()::Nothing rss_buff = IOBuffer() write(rss_buff, """ -A short description of the page which would serve as blurb in a A description done. A description done.RSS
feed;""", fc)
+ @test occursin(raw"""RSS
feed;""", fc)
end
diff --git a/test/manager/rss.jl b/test/manager/rss.jl
index 3a45855c4..60c5740ac 100644
--- a/test/manager/rss.jl
+++ b/test/manager/rss.jl
@@ -1,13 +1,13 @@
@testset "RSSItem" begin
rss = J.RSSItem(
- "title", "link", "description", "author", "category",
- "comments", "enclosure", Date(2012,12,12))
+ "title", "www.link.com", "description", "author@author.com", "category",
+ "www.comments.com", "enclosure", Date(2012,12,12))
@test rss.title == "title"
- @test rss.link == "link"
+ @test rss.link == "www.link.com"
@test rss.description == "description"
- @test rss.author == "author"
+ @test rss.author == "author@author.com"
@test rss.category == "category"
- @test rss.comments == "comments"
+ @test rss.comments == "www.comments.com"
@test rss.enclosure == "enclosure"
@test rss.pubDate == Date(2012,12,12)
end
@@ -21,12 +21,12 @@ end
jdv = merge(J.GLOBAL_PAGE_VARS, copy(J.LOCAL_PAGE_VARS))
J.set_var!(jdv, "rss_title", "title")
J.set_var!(jdv, "rss", "A **description** done.")
- J.set_var!(jdv, "author", "Chuck")
+ J.set_var!(jdv, "rss_author", "chuck@norris.com")
item = J.add_rss_item(jdv)
@test item.title == "title"
- @test item.description == "