Export as RSS feed.
More...
#include <remwharead/export/rss.hpp>
Export as RSS feed.
- Since
- 0.8.0
◆ ExportBase()
remwharead::Export::ExportBase::ExportBase |
|
explicit |
Export list of Database::entry.
- Parameters
-
list< Database::entry > sort_entries(list< Database::entry > entries) const
Sort entries from newest to oldest and remove duplicates.
Definition: export.cpp:28
◆ print()
void remwharead::Export::RSS::print |
( |
| ) |
const |
|
overridevirtual |
Print output to std::ostream.
Implements remwharead::Export::ExportBase.
43 XMLWriter writer(_out, XMLWriter::CANONICAL);
44 AttributesImpl attrs_rss;
45 AttributesImpl attrs_guid;
46 constexpr
char timefmt_rfc822[] =
"%w, %d %b %Y %H:%M:%S %Z";
48 attrs_rss.addAttribute(
"",
"",
"version",
"",
"2.0");
49 attrs_rss.addAttribute(
"",
"",
"xmlns:atom",
"",
50 "http://www.w3.org/2005/Atom");
51 attrs_guid.addAttribute(
"",
"",
"isPermaLink",
"",
"false");
53 writer.startDocument();
54 writer.startElement(
"",
"",
"rss", attrs_rss);
55 writer.startElement(
"",
"",
"channel");
57 writer.startElement(
"",
"",
"title");
58 writer.characters(
"Visited things");
59 writer.endElement(
"",
"",
"title");
61 writer.startElement(
"",
"",
"link");
62 writer.endElement(
"",
"",
"link");
64 writer.startElement(
"",
"",
"description");
65 writer.characters(
"Export from remwharead.");
66 writer.endElement(
"",
"",
"description");
68 writer.startElement(
"",
"",
"generator");
69 writer.characters(
string(
"remwharead ") + global::version);
70 writer.endElement(
"",
"",
"generator");
72 const string now = DateTimeFormatter::format(DateTime(),
74 writer.startElement(
"",
"",
"lastBuildDate");
75 writer.characters(now);
76 writer.endElement(
"",
"",
"lastBuildDate");
78 for (
const Database::entry &entry : _entries)
80 writer.startElement(
"",
"",
"item");
82 writer.startElement(
"",
"",
"title");
83 if (!entry.title.empty())
85 writer.characters(entry.title);
89 constexpr std::uint8_t maxlen = 100;
90 string title = entry.description.substr(0, maxlen);
91 if (entry.description.length() > maxlen)
95 writer.characters(title);
97 writer.endElement(
"",
"",
"title");
99 writer.startElement(
"",
"",
"link");
100 writer.characters(entry.uri);
101 writer.endElement(
"",
"",
"link");
103 writer.startElement(
"",
"",
"guid", attrs_guid);
104 writer.characters(entry.uri +
" at " 105 + timepoint_to_string(entry.datetime));
106 writer.endElement(
"",
"",
"guid");
108 const time_t time = system_clock::to_time_t(entry.datetime);
109 const string time_visited = DateTimeFormatter::format(
110 Timestamp::fromEpochTime(time), timefmt_rfc822);
111 writer.startElement(
"",
"",
"pubDate");
112 writer.characters(time_visited);
113 writer.endElement(
"",
"",
"pubDate");
115 string description = entry.description;
116 if (!description.empty())
118 description =
"<p>" + description.append(
"</p>");
120 if (!entry.tags.empty())
122 description +=
"<p><strong>Tags:</strong> ";
123 for (
const string &tag : entry.tags)
126 if (tag != *(entry.tags.rbegin()))
131 description +=
"</p>";
133 if (!entry.archive_uri.empty())
135 description +=
"<p><strong>Archived version:</strong> " 136 "<a href=\"" + entry.archive_uri +
"\">" 137 + entry.archive_uri +
"</a></p>";
139 writer.startElement(
"",
"",
"description");
140 writer.characters(description);
141 writer.endElement(
"",
"",
"description");
143 writer.endElement(
"",
"",
"item");
146 writer.endElement(
"",
"",
"channel");
147 writer.endElement(
"",
"",
"rss");
148 writer.endDocument();
151 catch (std::exception &e)
153 cerr <<
"Error in " << __func__ <<
": " << e.what() << endl;
The documentation for this class was generated from the following files:
- include/export/rss.hpp
- src/lib/export/rss.cpp