pixwhile/routes/css.cpp

158 lines
3.7 KiB
C++
Raw Normal View History

2023-05-12 09:56:22 +00:00
#include <string>
#include <FastHash.h>
2023-04-03 15:10:08 +00:00
2023-05-12 09:56:22 +00:00
#include "routes.h"
#include "../servehelper.h"
2023-04-03 15:10:08 +00:00
2023-05-12 10:23:26 +00:00
static const constexpr char css[] = R"EOF(
2023-04-09 13:31:50 +00:00
/* GENERAL */
2023-04-03 15:10:08 +00:00
:root {
--background-color: black;
--text-color: white;
2023-04-03 15:27:07 +00:00
--illust-badge-background-color: rgba(0, 0, 0, .5);
--illust-badge-ai-background-color: rgba(255, 0, 0, .5);
2023-04-03 15:27:07 +00:00
--error-background-color: rgb(100, 0, 0);
--error-border-color: red;
--error-text-color: white;
2023-04-03 15:10:08 +00:00
--accent-color: #962AC3;
--dark-accent-color: #7D3F7D;
--bright-accent-color: #DE6DE6;
}
body {
background-color: var(--background-color);
color: var(--text-color);
2023-04-03 15:45:05 +00:00
font-family: sans-serif;
2023-04-03 15:10:08 +00:00
}
2023-04-06 15:28:02 +00:00
img {
2023-04-10 15:01:38 +00:00
max-width: 100%;
height: auto; /* https://stackoverflow.com/a/17183996 */
object-fit: cover;
2023-04-06 15:28:02 +00:00
}
2023-05-01 16:40:33 +00:00
.center {
text-align: center;
display: block;
}
2023-05-05 17:11:41 +00:00
a {
color: var(--accent-color);
text-decoration: none;
2023-04-05 16:36:20 +00:00
}
2023-05-05 17:11:41 +00:00
a:hover {
color: var(--bright-accent-color);
text-decoration: underline;
2023-04-05 16:36:20 +00:00
}
2023-05-05 17:11:41 +00:00
/* ILLUSTRATIONS GRID and ILLUSTRATION PREVIEW PAGE */
2023-04-09 13:50:44 +00:00
.grid {
gap: 1em;
2023-04-09 05:55:26 +00:00
display: flex;
flex-wrap: wrap;
justify-content: center;
}
2023-04-09 13:50:44 +00:00
.grid img {
2023-04-09 05:55:26 +00:00
width: 15em;
height: 15em;
}
2023-05-05 17:11:41 +00:00
/* ILLUSTRATIONS GRID (used in user illustrations page and search results page) */
2023-05-12 10:13:55 +00:00
.illusts_grid p {
2023-04-09 05:55:26 +00:00
width: 15em;
}
2023-05-12 10:13:55 +00:00
.illusts_grid-illust {
position: relative;
}
2023-05-12 10:13:55 +00:00
.illusts_grid-illust_badge {
position: absolute;
top: .25em;
right: .25em;
padding: .25em;
color: var(--text-color);
background-color: var(--illust-badge-background-color);
text-decoration: none !important;
}
2023-05-12 10:13:55 +00:00
.illusts_grid-illust_badge.ai {
background-color: var(--illust-badge-ai-background-color);
}
2023-04-07 15:06:31 +00:00
2023-05-12 10:13:55 +00:00
/* USER PAGE AND ILLUSTRATIONS PAGE */
.user_profile_picture {
margin-right: .5em;
width: 5em;
height: 5em;
}
.user_metadata {
display: flex;
align-items: center;
margin-left: .5em;
}
.user_profile_picture.small {
2023-05-05 17:11:41 +00:00
width: 2.5em;
height: 2.5em;
2023-04-09 13:31:50 +00:00
}
2023-05-12 10:13:55 +00:00
/* ILLUSTRATIONS PAGE */
.illust-images {
2023-04-09 13:31:50 +00:00
display: grid;
text-align: center;
}
2023-05-12 10:13:55 +00:00
.illust-images .landmark {
2023-04-09 13:31:50 +00:00
padding-top: 1em;
padding-bottom: 1em;
}
2023-05-12 10:13:55 +00:00
.illust-tags {
2023-05-05 17:11:41 +00:00
display: flex;
flex-wrap: wrap;
gap: 0 1em;
}
/* USER PAGE */
2023-05-12 10:13:55 +00:00
.user-cover {
2023-05-05 17:11:41 +00:00
width: 100%;
height: 50vh;
margin-bottom: 1em;
}
2023-04-09 13:31:50 +00:00
2023-05-02 08:24:27 +00:00
/* SEARCH RESULTS PAGE */
2023-05-12 10:13:55 +00:00
.search_results-suggestions {
2023-05-02 08:24:27 +00:00
text-align: left;
display: inline-block;
margin-top: .5em;
margin-bottom: 0;
}
2023-04-09 13:31:50 +00:00
/* ERROR PAGE */
2023-04-03 15:27:07 +00:00
.error {
text-align: center;
background-color: var(--error-background-color);
color: var(--error-text-color);
border-style: solid;
border-color: var(--error-border-color);
}
2023-05-12 10:23:26 +00:00
)EOF";
#define CSS_LEN sizeof(css) / sizeof(css[0]) - 1
2023-05-12 09:56:22 +00:00
2023-05-12 10:23:26 +00:00
#if __cpp_constinit
#define CONSTINIT constinit
#else
#define CONSTINIT
#endif
CONSTINIT const uint64_t css_hash = FastHash(css, CSS_LEN, 0);
2023-04-03 15:27:07 +00:00
2023-05-12 09:56:22 +00:00
void css_route(const httplib::Request& req, httplib::Response& res) {
res.set_header("ETag", std::string(1, '"') + std::to_string(css_hash) + '"');
res.set_header("Cache-Control", "max-age=31536000, immutable");
if (should_send_304(req, css_hash)) {
res.status = 304;
res.set_header("Content-Length", std::to_string(CSS_LEN));
res.set_header("Content-Type", "text/css");
} else {
2023-05-12 10:23:26 +00:00
res.set_content(css, CSS_LEN, "text/css");
2023-05-12 09:56:22 +00:00
}
2023-04-03 15:10:08 +00:00
}