Add link to preview page

This commit is contained in:
blankie 2023-04-09 21:10:51 +07:00
parent 12156f3aaa
commit 26a5699487
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
2 changed files with 15 additions and 5 deletions

View File

@ -57,7 +57,10 @@ static inline Element generate_images(const httplib::Request& req, const Config&
Element div("div", {{"class", "illust"}}, {}); Element div("div", {{"class", "illust"}}, {});
bool show_pages = illust.images.size() > 1; bool show_pages = illust.images.size() > 1;
div.nodes.reserve(show_pages ? illust.images.size() * 2 : illust.images.size()); if (show_pages) {
div.nodes.push_back(Element("a", {{"href", "?preview=1"}}, {"Preview Images"}));
}
div.nodes.reserve(div.nodes.size() + (show_pages ? illust.images.size() * 2 : illust.images.size()));
for (size_t i = 0; i < illust.images.size(); i++) { for (size_t i = 0; i < illust.images.size(); i++) {
const Images& images = illust.images[i]; const Images& images = illust.images[i];
std::string thumbnail = proxy_image_url(config, images.thumbnail_or_original()); std::string thumbnail = proxy_image_url(config, images.thumbnail_or_original());
@ -76,19 +79,25 @@ static inline Element generate_images(const httplib::Request& req, const Config&
} }
static inline Element generate_preview_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) {
Element div("div", {{"class", "grid"}}, {}); std::string no_preview_link = get_origin(req, config) + "/artworks/" + std::to_string(illust.illust_id);
Element div("div", {
Element("a", {{"class", "center"}, {"href", no_preview_link}}, {"Go back"}),
Element("br")
});
Element grid("div", {{"class", "grid"}}, {});
div.nodes.reserve(illust.images.size()); grid.nodes.reserve(illust.images.size());
for (size_t i = 0; i < illust.images.size(); i++) { for (size_t i = 0; i < illust.images.size(); i++) {
const Images& images = illust.images[i]; const Images& images = illust.images[i];
std::string thumbnail = proxy_image_url(config, images.thumbnail_or_original(1)); 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); std::string link = no_preview_link + '#' + std::to_string(i + 1);
div.nodes.push_back(Element("a", {{"href", std::move(link)}}, { grid.nodes.push_back(Element("a", {{"href", std::move(link)}}, {
Element("img", {{"loading", "lazy"}, {"src", std::move(thumbnail)}}, {}) Element("img", {{"loading", "lazy"}, {"src", std::move(thumbnail)}}, {})
})); }));
} }
div.nodes.push_back(std::move(grid));
return div; return div;
} }

View File

@ -62,6 +62,7 @@ void css_route(const httplib::Request& req, httplib::Response& res) {
/* USER ILLUSTRATIONS PAGE (and illustrations page) */ /* USER ILLUSTRATIONS PAGE (and illustrations page) */
.center { .center {
text-align: center; text-align: center;
display: block;
} }
.grid { .grid {
display: flex; display: flex;