From 26a5699487d8653d504a0b97d3e33e7110c0e0bb Mon Sep 17 00:00:00 2001 From: blankie Date: Sun, 9 Apr 2023 21:10:51 +0700 Subject: [PATCH] Add link to preview page --- routes/artworks.cpp | 19 ++++++++++++++----- routes/css.cpp | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/routes/artworks.cpp b/routes/artworks.cpp index 83df449..9a2830e 100644 --- a/routes/artworks.cpp +++ b/routes/artworks.cpp @@ -57,7 +57,10 @@ static inline Element generate_images(const httplib::Request& req, const Config& Element div("div", {{"class", "illust"}}, {}); 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++) { const Images& images = illust.images[i]; 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) { - 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++) { 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); + 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)}}, {}) })); } + div.nodes.push_back(std::move(grid)); return div; } diff --git a/routes/css.cpp b/routes/css.cpp index b0c471f..fed660f 100644 --- a/routes/css.cpp +++ b/routes/css.cpp @@ -62,6 +62,7 @@ void css_route(const httplib::Request& req, httplib::Response& res) { /* USER ILLUSTRATIONS PAGE (and illustrations page) */ .center { text-align: center; + display: block; } .grid { display: flex;