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::ostringstream;
using std::stringstream;
using std::uint8_t;
using std::uint16_t;
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)));
}
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[])
{
const char *envquery = std::getenv("QUERY_STRING");
@ -177,20 +197,17 @@ int main(int argc, char *argv[])
{
const bool prerelease = release["prerelease"].asBool();
const string type = (prerelease ? "Pre-Release" : "Stable");
cout <<
" <item>\n"
" <title>"
<< project << ": " << release["name"].asString() << "</title>\n"
" <link>" << baseurl << "/" << repo << "/releases</link>\n"
" <guid isPermaLink=\"false\">"
<< domain << " release " << release["id"].asString() << "</guid>\n"
" <pubDate>"
<< strtime(release["published_at"].asString()) << "</pubDate>\n"
" <description><![CDATA[<p><strong>" << type << "</strong></p>"
<< "<pre>\n" << release["body"].asString() << "\n"
<< " </pre><a href=\"" << release["tarball_url"].asString()
<< "\">Download tarball</a>" << "]]></description>\n";
cout << " <item>\n";
write_line(6, "title", project + ": " + release["name"].asString());
write_line(6, "link", baseurl + "/" + repo + "/releases");
write_line(6, "guid isPermaLink=\"false\"",
domain + " release " + release["id"].asString());
write_line(6, "pubDate", strtime(release["published_at"].asString()));
write_line(6, "description",
"<![CDATA[<p><strong>" + type + "</strong></p><pre>\n"
+ release["body"].asString() + "\n"
" </pre><a href=\"" + release["tarball_url"].asString()
+ "\">Download tarball</a>" + "]]>");
cout << " </item>\n";
}