Made item-generating code more readable.

This commit is contained in:
tastytea 2019-04-17 09:13:01 +02:00
parent 7473e7e8ca
commit 87001819a3
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 31 additions and 14 deletions

View File

@ -38,6 +38,7 @@ using std::endl;
using std::string; using std::string;
using std::ostringstream; using std::ostringstream;
using std::stringstream; using std::stringstream;
using std::uint8_t;
using std::uint16_t; using std::uint16_t;
using std::chrono::system_clock; using std::chrono::system_clock;
@ -105,6 +106,25 @@ const string strtime(const string &time)
return strtime(std::chrono::system_clock::from_time_t(std::mktime(&tm))); return strtime(std::chrono::system_clock::from_time_t(std::mktime(&tm)));
} }
void write_line(const uint8_t spaces, const string &tag, const string &value)
{
string endtag;
// If there is a space in the tag, use only the part up until the space for
// the ending tag.
const size_t pos = tag.find(' ');
if (pos == std::string::npos)
{
endtag = tag;
}
else
{
endtag = tag.substr(0, pos);
}
cout << std::string(spaces, ' ');
cout << '<' << tag << '>' << value << "</" << endtag << ">\n";
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const char *envquery = std::getenv("QUERY_STRING"); const char *envquery = std::getenv("QUERY_STRING");
@ -177,20 +197,17 @@ int main(int argc, char *argv[])
{ {
const bool prerelease = release["prerelease"].asBool(); const bool prerelease = release["prerelease"].asBool();
const string type = (prerelease ? "Pre-Release" : "Stable"); const string type = (prerelease ? "Pre-Release" : "Stable");
cout << cout << " <item>\n";
" <item>\n" write_line(6, "title", project + ": " + release["name"].asString());
" <title>" write_line(6, "link", baseurl + "/" + repo + "/releases");
<< project << ": " << release["name"].asString() << "</title>\n" write_line(6, "guid isPermaLink=\"false\"",
" <link>" << baseurl << "/" << repo << "/releases</link>\n" domain + " release " + release["id"].asString());
" <guid isPermaLink=\"false\">" write_line(6, "pubDate", strtime(release["published_at"].asString()));
<< domain << " release " << release["id"].asString() << "</guid>\n" write_line(6, "description",
" <pubDate>" "<![CDATA[<p><strong>" + type + "</strong></p><pre>\n"
<< strtime(release["published_at"].asString()) << "</pubDate>\n" + release["body"].asString() + "\n"
" <description><![CDATA[<p><strong>" << type << "</strong></p>" " </pre><a href=\"" + release["tarball_url"].asString()
<< "<pre>\n" << release["body"].asString() << "\n" + "\">Download tarball</a>" + "]]>");
<< " </pre><a href=\"" << release["tarball_url"].asString()
<< "\">Download tarball</a>" << "]]></description>\n";
cout << " </item>\n"; cout << " </item>\n";
} }