Finish the illustrations page

This commit is contained in:
blankie 2023-04-09 12:55:26 +07:00
parent 3d37733af9
commit 936851a478
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
2 changed files with 25 additions and 9 deletions

View File

@ -54,6 +54,19 @@ void css_route(const httplib::Request& req, httplib::Response& res) {
.center { .center {
text-align: center; text-align: center;
} }
.userillustrations {
display: flex;
flex-wrap: wrap;
gap: 1em;
justify-content: center;
}
.userillustrations img {
width: 15em;
height: 15em;
}
.userillustrations p {
width: 15em;
}
.error { .error {
text-align: center; text-align: center;

View File

@ -7,7 +7,7 @@
#include "common.h" #include "common.h"
static Element generate_pager(const Illusts& illusts, size_t page); static Element generate_pager(const Illusts& illusts, size_t page);
static inline Element generate_content(const Illusts& illusts); static inline Element generate_content(const httplib::Request& req, const Config& config, const Illusts& illusts);
void user_illustrations_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client) { void user_illustrations_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client) {
uint64_t user_id = to_ull(req.matches[1].str()); uint64_t user_id = to_ull(req.matches[1].str());
@ -37,7 +37,7 @@ void user_illustrations_route(const httplib::Request& req, httplib::Response& re
generate_user_header(std::move(user), config), generate_user_header(std::move(user), config),
generate_pager(illusts, page), generate_pager(illusts, page),
Element("br"), Element("br"),
generate_content(illusts), generate_content(req, config, illusts),
generate_pager(illusts, page) generate_pager(illusts, page)
}); });
serve(req, res, config, user.display_name + " illustrations", std::move(body)); serve(req, res, config, user.display_name + " illustrations", std::move(body));
@ -64,16 +64,19 @@ static Element generate_pager(const Illusts& illusts, size_t page) {
}); });
} }
static inline Element generate_content(const Illusts& illusts) { static inline Element generate_content(const httplib::Request& req, const Config& config, const Illusts& illusts) {
// TODO be real Element div("div", {{"class", "userillustrations"}}, {});
Element ul("ul");
ul.nodes.reserve(illusts.illusts.size()); div.nodes.reserve(illusts.illusts.size());
for (const Illust& i : illusts.illusts) { for (const Illust& i : illusts.illusts) {
ul.nodes.push_back(Element("li", { std::string illust_url = get_origin(req, config) + "/artworks/" + std::to_string(i.illust_id);
std::to_string(i.illust_id) std::string image_url = proxy_image_url(config, i.images[0].thumbnail_or_original());
div.nodes.push_back(Element("a", {{"href", {std::move(illust_url)}}}, {
Element("img", {{"loading", "lazy"}, {"src", std::move(image_url)}}, {}),
Element("p", {i.title})
})); }));
} }
return ul; return div;
} }