Improved feed library:

- Added missing link to FEED.
- Closer to ATOM validation, especially for xhtml content.
- Closer to RSS2 specification.
- Removed unwanted conversion from STRING_32 to STRING_8. (fixing feed generation when dealing with Unicode content).
This commit is contained in:
2020-02-26 22:32:24 +01:00
parent 5ac7ce7483
commit 98452e13e2
5 changed files with 35 additions and 12 deletions

View File

@@ -83,13 +83,9 @@ feature -- Visitor
append_content_tag_to ("summary", Void, a_entry.description, buffer)
if attached a_entry.content as l_content then
if attached a_entry.content_type_or_default ("xhtml").is_case_insensitive_equal_general ("xhtml") then
-- if l_content.has_substring ("<div xmlns=%"http://www.w3.org/1999/xhtml%">") then
append_content_tag_to ("content", <<["type", "xhtml"]>>, l_content, buffer)
-- else
-- append_content_tag_to ("content", <<["type", "xhtml"]>>, {STRING_32} "<div xmlns=%"http://www.w3.org/1999/xhtml%">" + l_content + {STRING_32} "</div>", buffer)
-- end
else
append_content_tag_to ("content", <<["type", a_entry.content_type]>>, a_entry.content, buffer)
append_content_tag_to ("content", <<["type", a_entry.content_type]>>, l_content, buffer)
end
end

View File

@@ -138,6 +138,18 @@ feature -- Element change
Result.sort
end
set_link (a_url: READABLE_STRING_8; rel: detachable READABLE_STRING_GENERAL)
-- Set link `a_url` for relation `rel`.
local
lnk: FEED_LINK
do
create lnk.make (a_url)
if rel /= Void then
lnk.set_relation (rel)
end
links.force (lnk, lnk.relation)
end
sort
-- Sort `items', (recent first).
local

View File

@@ -33,7 +33,11 @@ feature -- Visitor
indent
indent
append_content_tag_to ("title", Void, a_feed.title, buffer)
append_content_tag_to ("description", Void, a_feed.description, buffer)
if attached a_feed.description as desc then
append_content_tag_to ("description", Void, desc, buffer)
else
append_content_tag_to ("description", Void, a_feed.title, buffer)
end
across
a_feed.links as tb
loop
@@ -120,7 +124,7 @@ feature {NONE} -- Helpers
htdate: HTTP_DATE
do
create htdate.make_from_date_time (dt)
Result := htdate.rfc850_string
Result := htdate.rfc1123_string
end
end

View File

@@ -46,6 +46,8 @@ feature {NONE} -- Helpers
indentation: STRING
append_content_tag_to (a_tagname: READABLE_STRING_8; a_attr: detachable ITERABLE [TUPLE [name: READABLE_STRING_8; value: detachable READABLE_STRING_GENERAL]]; a_content: detachable READABLE_STRING_GENERAL; a_output: STRING)
local
l_is_xhtml_type: BOOLEAN
do
if a_content /= Void or a_attr /= Void then
a_output.append (indentation)
@@ -60,8 +62,11 @@ feature {NONE} -- Helpers
a_output.append (ic.item.name)
a_output.append_character ('=')
a_output.append_character ('%"')
a_output.append (escaped_unicode_xml (l_att_value.as_string_32))
a_output.append (escaped_xml (l_att_value))
a_output.append_character ('%"')
if ic.item.name.same_string ("type") and then l_att_value.same_string ("xhtml") then
l_is_xhtml_type := True
end
end
end
end
@@ -69,7 +74,13 @@ feature {NONE} -- Helpers
a_output.append ("/>%N")
else
a_output.append (">")
a_output.append (escaped_unicode_xml (a_content.as_string_32))
if l_is_xhtml_type then
a_output.append ("<div xmlns=%"http://www.w3.org/1999/xhtml%">")
a_output.append (escaped_xml (a_content))
a_output.append ("</div>")
else
a_output.append (escaped_xml (a_content))
end
a_output.append ("</" + a_tagname + ">%N")
end
end
@@ -89,7 +100,7 @@ feature {NONE} -- Helpers
a_output.append (ic.item.name)
a_output.append_character ('=')
a_output.append_character ('%"')
a_output.append (escaped_unicode_xml (ic.item.value))
a_output.append (escaped_xml (ic.item.value))
a_output.append_character ('%"')
end
end

View File

@@ -50,7 +50,7 @@ feature -- Access
if attached xml_attribute_text (x_link, "href") as l_href and then
l_href.is_valid_as_string_8
then
create lnk.make (l_href.as_string_8)
create lnk.make (l_href.to_string_8)
lnk.set_relation (xml_attribute_text (x_link, "rel"))
lnk.set_type (xml_attribute_text (x_link, "type"))
Result.force (lnk)