src/html.cpp

changeset 76
110a234a3260
parent 75
857af79337d5
equal deleted inserted replaced
75:857af79337d5 76:110a234a3260
90 static std::string build_tag_list(fm::tag_lists tags, bool hide_repo_names) { 90 static std::string build_tag_list(fm::tag_lists tags, bool hide_repo_names) {
91 std::string tags_json; 91 std::string tags_json;
92 if (hide_repo_names) { 92 if (hide_repo_names) {
93 for (const auto &tags_vector: tags | std::views::values) { 93 for (const auto &tags_vector: tags | std::views::values) {
94 for (const auto &tag: tags_vector) { 94 for (const auto &tag: tags_vector) {
95 tags_json += escape_json(tag); 95 tags_json += escape_json(tag.message);
96 tags_json += ' '; 96 tags_json += ' ';
97 } 97 }
98 } 98 }
99 if (!tags_json.empty()) { 99 if (!tags_json.empty()) {
100 tags_json.pop_back(); 100 tags_json.pop_back();
102 } else { 102 } else {
103 tags_json += '{'; 103 tags_json += '{';
104 for (const auto &[repo, tags_vector] : tags) { 104 for (const auto &[repo, tags_vector] : tags) {
105 tags_json += "\"" + escape_json(repo) + "\":\""; 105 tags_json += "\"" + escape_json(repo) + "\":\"";
106 for (const auto &tag: tags_vector) { 106 for (const auto &tag: tags_vector) {
107 tags_json += escape_json(tag); 107 tags_json += escape_json(tag.message);
108 tags_json += ' '; 108 tags_json += ' ';
109 } 109 }
110 if (!tags_vector.empty()) { 110 if (!tags_vector.empty()) {
111 tags_json.pop_back(); 111 tags_json.pop_back();
112 } 112 }
118 } 118 }
119 } 119 }
120 return tags_json; 120 return tags_json;
121 } 121 }
122 122
123 static std::string build_tag_array(fm::tag_lists tags, bool hide_repo_names) { 123 static std::string build_tag_summary(fm::tag_summaries tags, bool hide_repo_names) {
124 std::string tags_json; 124 std::string tags_json;
125 if (hide_repo_names) { 125 if (hide_repo_names) {
126 tags_json += '['; 126 tags_json += '[';
127 for (const auto &tags_vector: tags | std::views::values) { 127 for (const auto &tags_vector: tags | std::views::values) {
128 for (const auto &tag: tags_vector) { 128 for (const auto &tag: tags_vector) {
480 commit_summary_json.pop_back(); 480 commit_summary_json.pop_back();
481 } 481 }
482 commit_summary_json += '}'; 482 commit_summary_json += '}';
483 commit_summary = std::format("data-commits=\"{}\"", encode(commit_summary_json)); 483 commit_summary = std::format("data-commits=\"{}\"", encode(commit_summary_json));
484 } 484 }
485 std::string tags = build_tag_array(summary.tags_with_date, hide_repo_names); 485 std::string tags = build_tag_summary(summary.tags_with_date, hide_repo_names);
486 printf("<th scope=\"col\" title=\"Total commits: %u\" colspan=\"%d\" data-total=\"%u\" %s data-tags=\"%s\">%s</th>\n", 486 printf("<th scope=\"col\" title=\"Total commits: %u\" colspan=\"%d\" data-total=\"%u\" %s data-tags=\"%s\">%s</th>\n",
487 total, colspans[i], total, 487 total, colspans[i], total,
488 commit_summary.c_str(), 488 commit_summary.c_str(),
489 encode(tags).c_str(), months[i]); 489 encode(tags).c_str(), months[i]);
490 } else { 490 } else {
533 } else { 533 } else {
534 color_class = "commit-spam"; 534 color_class = "commit-spam";
535 } 535 }
536 536
537 // Build a JSON object of commit summaries 537 // Build a JSON object of commit summaries
538 auto add_summaries = [](std::string &json, const std::vector<std::string> &summaries) static { 538 auto add_summaries = [](std::string &json, const std::vector<fm::commit_info> &summaries) static {
539 // We have to iterate in reverse order to sort the summaries chronologically 539 // We have to iterate in reverse order to sort the summaries chronologically
540 for (const auto &summary : summaries | std::views::reverse) { 540 for (const auto &summary : summaries | std::views::reverse) {
541 json += "\"" + escape_json(summary) + "\","; 541 json += "\"" + escape_json(summary.message) + "\",";
542 } 542 }
543 json.pop_back(); 543 json.pop_back();
544 }; 544 };
545 std::string summaries_json; 545 std::string summaries_json;
546 if (hide_repo_names) { 546 if (hide_repo_names) {

mercurial