diff --git a/src/generators/rss.cpp b/src/generators/rss.cpp index e13fd26..5c4eac9 100644 --- a/src/generators/rss.cpp +++ b/src/generators/rss.cpp @@ -15,11 +15,15 @@ */ #include "rss.hpp" +#include "files.hpp" +#include "git.hpp" #include "time.hpp" +#include #include #include #include +#include #include #include #include @@ -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 &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 &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: 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 << " \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{"

" + entry.description + "

"}; + item_description += "

Tags: "; + for (const auto &tag : entry.tags) + { + if (tag != *(entry.tags.begin())) + { + item_description += ", "; + } + item_description += tag; + } + item_description += "

"; + item_description += "

Receipts: "; + for (const auto &receipt : entry.receipts) + { + if (receipt != *(entry.receipts.begin())) + { + item_description += "
"; + } + ((((item_description += "") += + receipt) += ""; + } + item_description += "

"; + if (!entry.screenshot_filepath.empty()) + { + item_description += "

Screenshot:
"; + ((item_description += "

)") += '\n'; + } + write_line(out, 6, "description", + ""); + + out << "
\n"; + } out << " \n\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 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; } diff --git a/src/generators/rss.hpp b/src/generators/rss.hpp index 532dbc2..3df2be6 100644 --- a/src/generators/rss.hpp +++ b/src/generators/rss.hpp @@ -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 */