Add preview page
This commit is contained in:
parent
8674a9195d
commit
12156f3aaa
|
@ -21,7 +21,10 @@ const std::string& Images::original_or_thumbnail() const {
|
||||||
throw std::runtime_error("Images does not contain any images");
|
throw std::runtime_error("Images does not contain any images");
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& Images::thumbnail_or_original() const {
|
const std::string& Images::thumbnail_or_original(size_t back) const {
|
||||||
|
if (this->thumbnails.size() > back) {
|
||||||
|
return this->thumbnails[this->thumbnails.size() - back - 1];
|
||||||
|
}
|
||||||
if (!this->thumbnails.empty()) {
|
if (!this->thumbnails.empty()) {
|
||||||
return this->thumbnails.back();
|
return this->thumbnails.back();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct Images {
|
||||||
std::vector<std::string> thumbnails;
|
std::vector<std::string> thumbnails;
|
||||||
|
|
||||||
const std::string& original_or_thumbnail() const;
|
const std::string& original_or_thumbnail() const;
|
||||||
const std::string& thumbnail_or_original() const;
|
const std::string& thumbnail_or_original(size_t back = 0) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct User {
|
struct User {
|
||||||
|
|
|
@ -6,10 +6,12 @@
|
||||||
static inline bool is_true(const std::string& str);
|
static inline bool is_true(const std::string& str);
|
||||||
static inline Element generate_user_link(const httplib::Request& req, const Config& config, const Illust& illust);
|
static inline Element generate_user_link(const httplib::Request& req, const Config& config, const Illust& illust);
|
||||||
static inline Element generate_images(const httplib::Request& req, const Config& config, const Illust& illust);
|
static inline Element generate_images(const httplib::Request& req, const Config& config, const Illust& illust);
|
||||||
|
static inline Element generate_preview_images(const httplib::Request& req, const Config& config, const Illust& illust);
|
||||||
static inline Element generate_illust_metadata(const Illust& illust);
|
static inline Element generate_illust_metadata(const Illust& illust);
|
||||||
|
|
||||||
void artworks_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client) {
|
void artworks_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client) {
|
||||||
uint64_t illust_id = to_ull(req.matches.str(1));
|
uint64_t illust_id = to_ull(req.matches.str(1));
|
||||||
|
bool preview = is_true(req.get_param_value("preview"));
|
||||||
Illust illust;
|
Illust illust;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -32,7 +34,7 @@ void artworks_route(const httplib::Request& req, httplib::Response& res, const C
|
||||||
Element body("body", {
|
Element body("body", {
|
||||||
Element("h2", {illust.title}),
|
Element("h2", {illust.title}),
|
||||||
generate_user_link(req, config, illust),
|
generate_user_link(req, config, illust),
|
||||||
generate_images(req, config, illust),
|
!preview ? generate_images(req, config, illust) : generate_preview_images(req, config, illust),
|
||||||
Element("br"),
|
Element("br"),
|
||||||
generate_illust_metadata(illust)
|
generate_illust_metadata(illust)
|
||||||
});
|
});
|
||||||
|
@ -73,6 +75,23 @@ static inline Element generate_images(const httplib::Request& req, const Config&
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline Element generate_preview_images(const httplib::Request& req, const Config& config, const Illust& illust) {
|
||||||
|
Element div("div", {{"class", "grid"}}, {});
|
||||||
|
|
||||||
|
div.nodes.reserve(illust.images.size());
|
||||||
|
for (size_t i = 0; i < illust.images.size(); i++) {
|
||||||
|
const Images& images = illust.images[i];
|
||||||
|
std::string thumbnail = proxy_image_url(config, images.thumbnail_or_original(1));
|
||||||
|
std::string link = get_origin(req, config) + "/artworks/" + std::to_string(illust.illust_id) + "#" + std::to_string(i + 1);
|
||||||
|
|
||||||
|
div.nodes.push_back(Element("a", {{"href", std::move(link)}}, {
|
||||||
|
Element("img", {{"loading", "lazy"}, {"src", std::move(thumbnail)}}, {})
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return div;
|
||||||
|
}
|
||||||
|
|
||||||
static inline Element generate_illust_metadata(const Illust& illust) {
|
static inline Element generate_illust_metadata(const Illust& illust) {
|
||||||
Element div("div", {{"class", "illustmetadata"}}, {});
|
Element div("div", {{"class", "illustmetadata"}}, {});
|
||||||
|
|
||||||
|
|
|
@ -59,21 +59,21 @@ void css_route(const httplib::Request& req, httplib::Response& res) {
|
||||||
margin-left: .5em;
|
margin-left: .5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER ILLUSTRATIONS PAGE */
|
/* USER ILLUSTRATIONS PAGE (and illustrations page) */
|
||||||
.center {
|
.center {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
.userillustrations {
|
.grid {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
gap: 1em;
|
gap: 1em;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
.userillustrations img {
|
.grid img {
|
||||||
width: 15em;
|
width: 15em;
|
||||||
height: 15em;
|
height: 15em;
|
||||||
}
|
}
|
||||||
.userillustrations p {
|
.grid p {
|
||||||
width: 15em;
|
width: 15em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ void user_illustrations_route(const httplib::Request& req, httplib::Response& re
|
||||||
generate_content(req, config, illusts),
|
generate_content(req, config, illusts),
|
||||||
generate_pager(illusts, page, false)
|
generate_pager(illusts, page, false)
|
||||||
});
|
});
|
||||||
serve(req, res, config, user.display_name + " illustrations", std::move(body));
|
serve(req, res, config, user.display_name + "'s illustrations", std::move(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Element generate_pager(const Illusts& illusts, size_t page, bool first_selector) {
|
static Element generate_pager(const Illusts& illusts, size_t page, bool first_selector) {
|
||||||
|
@ -72,12 +72,12 @@ static Element generate_pager(const Illusts& illusts, size_t page, bool first_se
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Element generate_content(const httplib::Request& req, const Config& config, const Illusts& illusts) {
|
static inline Element generate_content(const httplib::Request& req, const Config& config, const Illusts& illusts) {
|
||||||
Element div("div", {{"class", "userillustrations"}}, {});
|
Element div("div", {{"class", "grid"}}, {});
|
||||||
|
|
||||||
div.nodes.reserve(illusts.illusts.size());
|
div.nodes.reserve(illusts.illusts.size());
|
||||||
for (const Illust& i : illusts.illusts) {
|
for (const Illust& i : illusts.illusts) {
|
||||||
std::string illust_url = get_origin(req, config) + "/artworks/" + std::to_string(i.illust_id);
|
std::string illust_url = get_origin(req, config) + "/artworks/" + std::to_string(i.illust_id);
|
||||||
std::string image_url = proxy_image_url(config, i.images[0].thumbnail_or_original());
|
std::string image_url = proxy_image_url(config, i.images[0].thumbnail_or_original(1));
|
||||||
|
|
||||||
div.nodes.push_back(Element("a", {{"href", {std::move(illust_url)}}}, {
|
div.nodes.push_back(Element("a", {{"href", {std::move(illust_url)}}}, {
|
||||||
Element("img", {{"loading", "lazy"}, {"src", std::move(image_url)}}, {}),
|
Element("img", {{"loading", "lazy"}, {"src", std::move(image_url)}}, {}),
|
||||||
|
|
Loading…
Reference in New Issue