RSS kinda works.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
- ./gen_rss outputs all entries. - tag selection is implemented, but not exposed to the user.
This commit is contained in:
parent
37ddff8c00
commit
7518947766
|
@ -15,11 +15,15 @@
|
|||
*/
|
||||
|
||||
#include "rss.hpp"
|
||||
#include "files.hpp"
|
||||
#include "git.hpp"
|
||||
#include "time.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
@ -29,7 +33,9 @@
|
|||
namespace FediBlock::rss
|
||||
{
|
||||
|
||||
using std::find;
|
||||
using std::getenv;
|
||||
using std::none_of;
|
||||
using std::ostream;
|
||||
using std::string;
|
||||
using std::string_view;
|
||||
|
@ -74,6 +80,7 @@ void write_rss(ostream &out, const vector<entry_type> &entries,
|
|||
{
|
||||
selfurl += env;
|
||||
}
|
||||
const string baseurl{selfurl + "/blocklist/"};
|
||||
env = getenv("REQUEST_URI");
|
||||
if (env != nullptr)
|
||||
{
|
||||
|
@ -91,30 +98,122 @@ void write_rss(ostream &out, const vector<entry_type> &entries,
|
|||
<< R"(" rel="self" type="application/rss+xml"/>)" << '\n';
|
||||
write_line(out, 4, "title", "FediBlock: newest entries");
|
||||
write_line(out, 4, "link", blocklist_url);
|
||||
write_line(out, 4, "description", "FediBlock: Newest entries.");
|
||||
write_line(out,
|
||||
4,
|
||||
"lastBuildDate",
|
||||
string description;
|
||||
if (tags.empty())
|
||||
{
|
||||
description = "All tags.";
|
||||
}
|
||||
else
|
||||
{
|
||||
description = "Tags: ";
|
||||
}
|
||||
for (const auto &tag : tags)
|
||||
{
|
||||
if (tag == *(tags.begin()))
|
||||
{
|
||||
description += ", ";
|
||||
}
|
||||
description += tag;
|
||||
}
|
||||
write_line(out, 4, "description", description);
|
||||
write_line(out, 4, "lastBuildDate",
|
||||
time::to_string(system_clock::now(), rss_time_format));
|
||||
|
||||
// TODO: <item>s.
|
||||
for (const auto &entry : entries)
|
||||
{
|
||||
// If tags are specified and none of them match, go to the next entry.
|
||||
if (!tags.empty())
|
||||
{
|
||||
// clang-format off
|
||||
if (none_of(entry.tags.begin(), entry.tags.end(),
|
||||
[&tags](const auto &tag)
|
||||
{
|
||||
return find(tags.begin(), tags.end(), tag)
|
||||
!= tags.end();
|
||||
}))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
out << " <item>\n";
|
||||
write_line(out, 6, "title", entry.instance);
|
||||
write_line(out, 6, "guid isPermaLink=\"false\"",
|
||||
"FediBlock: " + entry.report_time + " " + entry.instance);
|
||||
write_line(out, 6, "pubDate",
|
||||
time::to_string(entry.report_time, rss_time_format));
|
||||
|
||||
string item_description{"<p>" + entry.description + "</p>"};
|
||||
item_description += "<p><strong>Tags:</strong> ";
|
||||
for (const auto &tag : entry.tags)
|
||||
{
|
||||
if (tag != *(entry.tags.begin()))
|
||||
{
|
||||
item_description += ", ";
|
||||
}
|
||||
item_description += tag;
|
||||
}
|
||||
item_description += "</p>";
|
||||
item_description += "<p><strong>Receipts:</strong> ";
|
||||
for (const auto &receipt : entry.receipts)
|
||||
{
|
||||
if (receipt != *(entry.receipts.begin()))
|
||||
{
|
||||
item_description += "<br>";
|
||||
}
|
||||
((((item_description += "<a href=\"") += receipt) += "\">") +=
|
||||
receipt) += "</a>";
|
||||
}
|
||||
item_description += "</p>";
|
||||
if (!entry.screenshot_filepath.empty())
|
||||
{
|
||||
item_description += "<p><strong>Screenshot:</strong><br>";
|
||||
((item_description += "<a href=\"") += baseurl) +=
|
||||
entry.screenshot_filepath;
|
||||
item_description += "\"><img src=\"";
|
||||
(item_description += baseurl) += entry.screenshot_filepath;
|
||||
(item_description += R"(" height="100"></a></p>)") += '\n';
|
||||
}
|
||||
write_line(out, 6, "description",
|
||||
"<![CDATA[" + item_description + "]]>");
|
||||
|
||||
out << " </item>\n";
|
||||
}
|
||||
|
||||
out << " </channel>\n</rss>\n";
|
||||
}
|
||||
|
||||
} // namespace FediBlock::rss
|
||||
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::exception;
|
||||
using std::string_view;
|
||||
using std::vector;
|
||||
|
||||
using namespace FediBlock;
|
||||
using namespace FediBlock::rss;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const vector<string_view> args(argv, argv + argc);
|
||||
|
||||
write_rss(cout, {}, {});
|
||||
git_libgit2_init();
|
||||
|
||||
try
|
||||
{
|
||||
git::clone();
|
||||
const auto entries{files::read_json_files()};
|
||||
write_rss(cout, entries, {});
|
||||
}
|
||||
catch (const exception &e)
|
||||
{
|
||||
cerr << "Error: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
files::remove_tmpdir();
|
||||
git_libgit2_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,8 @@ void write_line(ostream &out, uint8_t spaces, string_view rsstag,
|
|||
*
|
||||
* @param out The ostream to use for output.
|
||||
* @param entries The entries to write.
|
||||
* @param tags Only write entries with these tags (logical or).
|
||||
* @param tags Only write entries with these tags (logical or). An empty
|
||||
* vector selects all tags.
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
|
|
Reference in New Issue