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)


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