pixwhile/routes/users/common.cpp

42 lines
1.7 KiB
C++
Raw Normal View History

2023-04-05 16:36:20 +00:00
#include "common.h"
#include "../../config.h"
#include "../../servehelper.h"
#include "../../pixivmodels.h"
2023-04-05 16:36:20 +00:00
static inline Element generate_user_links(const User& user);
Element generate_user_header(const User& user, const Config& config) {
Element header("header");
if (user.cover_images) {
std::string cover_original = proxy_image_url(config, user.cover_images->original_or_thumbnail());
std::string cover_thumbnail = proxy_image_url(config, user.cover_images->thumbnail_or_original());
2023-04-06 12:24:09 +00:00
header.nodes.push_back(Element("a", {{"href", std::move(cover_original)}}, {
2023-04-09 05:38:45 +00:00
Element("img", {{"class", "cover"}, {"loading", "lazy"}, {"src", std::move(cover_thumbnail)}}, {})
2023-04-05 16:36:20 +00:00
}));
}
std::string profile_picture_original = proxy_image_url(config, user.profile_pictures.original_or_thumbnail());
std::string profile_picture_thumbnail = proxy_image_url(config, user.profile_pictures.thumbnail_or_original());
2023-04-05 16:36:20 +00:00
header.nodes.push_back(Element("div", {{"class", "usermetadata"}}, {
2023-04-06 12:24:09 +00:00
Element("a", {{"href", std::move(profile_picture_original)}}, {
2023-04-09 05:38:45 +00:00
Element("img", {{"class", "profilepicture"}, {"loading", "lazy"}, {"src", std::move(profile_picture_thumbnail)}}, {})
2023-04-05 16:36:20 +00:00
}),
Element("div", {
Element("p", {Element("b", {user.display_name}), " (@", user.username, ")"}),
generate_user_links(user)
})
}));
return header;
}
static inline Element generate_user_links(const User& user) {
Element p("p");
for (const auto &[name, url] : user.links) {
if (!p.nodes.empty()) {
p.nodes.push_back(", ");
}
p.nodes.push_back(Element("a", {{"href", url}}, {name}));
}
return p;
}