startgit

Static page generator for git repositories
git clone git://git.dimitrijedobrota.com/startgit.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

common.cpp (4011B)


0 #include <format> 1 2 #include "common.hpp" 3 4 #include <hemplate/classes.hpp> 5 6 #include "arguments.hpp" 7 8 namespace startgit 9 { 10 11 void write_header(std::ostream& ost, 12 const std::string& title, 13 const std::string& description, 14 const std::string& author, 15 const std::string& relpath, 16 bool has_feed) 17 { 18 using namespace hemplate; // NOLINT 19 20 ost << html::doctype(); 21 ost << html::html().set("lang", "en"); 22 ost << html::head(); 23 ost << html::title(title); 24 25 // Meta tags 26 ost << html::meta({{"charset", "UTF-8"}}); 27 ost << html::meta({{"name", "author"}, {"content", author}}); 28 ost << html::meta({{"name", "description"}, {"content", description}}); 29 30 ost << html::meta({{"content", "width=device-width, initial-scale=1"}, 31 {"name", "viewport"}}); 32 33 // Stylesheets 34 ost << html::link({{"rel", "stylesheet"}, {"type", "text/css"}}) 35 .set("href", args.resource_url + "/css/index.css"); 36 ost << html::link({{"rel", "stylesheet"}, {"type", "text/css"}}) 37 .set("href", args.resource_url + "/css/colors.css"); 38 39 if (has_feed) { 40 // Rss feed 41 ost << html::link({{"rel", "alternate"}, 42 {"type", "application/atom+xml"}, 43 {"title", "RSS feed"}, 44 {"href", relpath + "rss.xml"}}); 45 // Atom feed 46 ost << html::link({{"rel", "alternate"}, 47 {"type", "application/atom+xml"}, 48 {"title", "Atom feed"}, 49 {"href", relpath + "atom.xml"}}); 50 } 51 52 // Icons 53 ost << html::link({{"rel", "icon"}, {"type", "image/png"}}) 54 .set("sizes", "32x32") 55 .set("href", args.resource_url + "/img/favicon-32x32.png"); 56 ost << html::link({{"rel", "icon"}, {"type", "image/png"}}) 57 .set("sizes", "16x16") 58 .set("href", args.resource_url + "/img/favicon-16x16.png"); 59 ost << html::head(); 60 ost << html::body(); 61 ost << html::input() 62 .set("type", "checkbox") 63 .set("id", "theme_switch") 64 .set("class", "theme_switch"); 65 66 ost << html::div().set("id", "content"); 67 html::div().tgl_state(); 68 69 ost << html::main(); 70 ost << html::label(" ") 71 .set("for", "theme_switch") 72 .set("class", "switch_label"); 73 } 74 75 void write_header(std::ostream& ost, 76 const repository& repo, 77 const branch& branch, 78 const std::string& description, 79 const std::string& relpath, 80 bool has_feed) 81 { 82 write_header(ost, 83 std::format("{} ({}) - {}", 84 repo.get_name(), 85 branch.get_name(), 86 repo.get_description()), 87 description, 88 repo.get_owner(), 89 relpath, 90 has_feed); 91 } 92 93 void write_footer(std::ostream& ost) 94 { 95 using namespace hemplate; // NOLINT 96 97 ost << html::main(); 98 99 html::div().tgl_state(); 100 ost << html::div(); 101 102 const auto jss = args.resource_url + "/scripts/main.js"; 103 ost << html::script(" ").set("src", jss); 104 ost << html::script( 105 "function switchPage(value) {" 106 " let arr = window.location.href.split('/');" 107 " arr[4] = value;" 108 " history.replaceState(history.state, '', arr.join('/'));" 109 " location.reload();" 110 "}"); 111 ost << html::style( 112 " table { " 113 " margin-left: 0;" 114 " background-color: inherit;" 115 " border: none" 116 "} select { " 117 " color: var(--theme_fg1);" 118 " background-color: inherit;" 119 " border: 1px solid var(--theme_bg4);" 120 "} select option {" 121 " color: var(--theme_fg2) !important;" 122 " background-color: var(--theme_bg3) !important;" 123 "} .add {" 124 " color: var(--theme_green);" 125 "} .del {" 126 " color: var(--theme_red);" 127 "}"); 128 ost << html::body(); 129 ost << html::html(); 130 } 131 132 } // namespace startgit