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
-
const list< Database::entry > sort_entries(list< Database::entry > entries) const
Sort entries from newest to oldest and remove duplicates.
Definition: export.cpp:30
◆ 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, attrs_guid;
45 constexpr
char timefmt_rfc822[] =
"%w, %d %b %Y %H:%M:%S %Z";
47 attrs_rss.addAttribute(
"",
"",
"version",
"",
"2.0");
48 attrs_rss.addAttribute(
"",
"",
"xmlns:atom",
"",
49 "http://www.w3.org/2005/Atom");
50 attrs_guid.addAttribute(
"",
"",
"isPermaLink",
"",
"false");
52 writer.startDocument();
53 writer.startElement(
"",
"",
"rss", attrs_rss);
54 writer.startElement(
"",
"",
"channel");
56 writer.startElement(
"",
"",
"title");
57 writer.characters(
"Visited things");
58 writer.endElement(
"",
"",
"title");
60 writer.startElement(
"",
"",
"link");
61 writer.endElement(
"",
"",
"link");
63 writer.startElement(
"",
"",
"description");
64 writer.characters(
"Export from remwharead.");
65 writer.endElement(
"",
"",
"description");
67 writer.startElement(
"",
"",
"generator");
68 writer.characters(
string(
"remwharead ") + global::version);
69 writer.endElement(
"",
"",
"generator");
71 const string now = DateTimeFormatter::format(DateTime(),
73 writer.startElement(
"",
"",
"lastBuildDate");
74 writer.characters(now);
75 writer.endElement(
"",
"",
"lastBuildDate");
79 writer.startElement(
"",
"",
"item");
81 writer.startElement(
"",
"",
"title");
82 if (!entry.title.empty())
84 writer.characters(entry.title);
88 constexpr std::uint8_t maxlen = 100;
89 string title = entry.description.substr(0, maxlen);
90 if (entry.description.length() > maxlen)
94 writer.characters(title);
96 writer.endElement(
"",
"",
"title");
98 writer.startElement(
"",
"",
"link");
99 writer.characters(entry.uri);
100 writer.endElement(
"",
"",
"link");
102 writer.startElement(
"",
"",
"guid", attrs_guid);
103 writer.characters(entry.uri +
" at " +
104 timepoint_to_string(entry.datetime));
105 writer.endElement(
"",
"",
"guid");
107 const time_t time = system_clock::to_time_t(entry.datetime);
108 const string time_visited = DateTimeFormatter::format(
109 Timestamp::fromEpochTime(time), timefmt_rfc822);
110 writer.startElement(
"",
"",
"pubDate");
111 writer.characters(time_visited);
112 writer.endElement(
"",
"",
"pubDate");
114 string description = entry.description;
115 if (!description.empty())
117 description =
"<p>" + description +
"</p>";
119 if (!entry.tags.empty())
121 description +=
"<p><strong>Tags:</strong> ";
122 for (
const string &tag : entry.tags)
125 if (tag != *(entry.tags.rbegin()))
130 description +=
"</p>";
132 if (!entry.archive_uri.empty())
134 description +=
"<p><strong>Archived version:</strong> " 135 "<a href=\"" + entry.archive_uri +
"\">" 136 + entry.archive_uri +
"</a>";
138 writer.startElement(
"",
"",
"description");
139 writer.characters(description);
140 writer.endElement(
"",
"",
"description");
142 writer.endElement(
"",
"",
"item");
145 writer.endElement(
"",
"",
"channel");
146 writer.endElement(
"",
"",
"rss");
147 writer.endDocument();
150 catch (std::exception &e)
152 cerr <<
"Error in " << __func__ <<
": " << e.what() << endl;
struct remwharead::Database::entry entry
Describes a database entry.
The documentation for this class was generated from the following files:
- include/export/rss.hpp
- src/lib/export/rss.cpp