From 4586931adf0cd04c097eba0270faee0c0ec972dc Mon Sep 17 00:00:00 2001 From: blankie Date: Fri, 28 Apr 2023 17:32:01 +0700 Subject: [PATCH] Add illustration search box --- README.md | 2 ++ blankie/serializer.cpp | 6 +++++- main.cpp | 9 +++++++++ routes/home.cpp | 11 +++++++++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c181e31..0962c4f 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,13 @@ Pixwhile is an alternative frontend to Pixiv that utilizes no Javascript. - Does not contain an asinine amount of Javascript - Allows you to open the original versions of cover images and profile pictures - Can view illustrations and list user illustrations +- Can search for newest and oldest illustrations ## Missing Features This list is not exhaustive, nor does it mean that these are being worked on. +- Can only search for newest and oldest illustrations - No search - No ability to login - No ability to see comments or like counts diff --git a/blankie/serializer.cpp b/blankie/serializer.cpp index 65bbf88..ec35e13 100644 --- a/blankie/serializer.cpp +++ b/blankie/serializer.cpp @@ -52,5 +52,9 @@ std::string Element::serialize() const { } // namespace blankie static inline bool is_autoclosing_tag(const char* tag) { - return !strncmp(tag, "link", 5) || !strncmp(tag, "meta", 5) || !strncmp(tag, "img", 4) || !strncmp(tag, "br", 3); + return !strncmp(tag, "link", 5) + || !strncmp(tag, "meta", 5) + || !strncmp(tag, "img", 4) + || !strncmp(tag, "br", 3) + || !strncmp(tag, "label", 6); } diff --git a/main.cpp b/main.cpp index d5e745d..a65d616 100644 --- a/main.cpp +++ b/main.cpp @@ -62,6 +62,15 @@ int main(int argc, char** argv) { } serve_redirect(req, res, config, get_origin(req, config) + "/artworks/" + illust_id); }); + server.Get("/search", [&](const httplib::Request& req, httplib::Response& res) { + std::string q = req.get_param_value("q"); + if (q.empty()) { + res.status = 400; + serve_error(req, res, config, "400: Bad Request", "Missing or empty search query"); + return; + } + serve_redirect(req, res, config, get_origin(req, config) + "/tags/" + blankie::murl::escape(std::move(q))); + }); #ifndef NDEBUG server.Get("/debug/exception/known", [](const httplib::Request& req, httplib::Response& res) { diff --git a/routes/home.cpp b/routes/home.cpp index 60c88c4..3830b46 100644 --- a/routes/home.cpp +++ b/routes/home.cpp @@ -15,6 +15,12 @@ void home_route(const httplib::Request& req, httplib::Response& res, const Confi "Pixwhile is an alternative frontend to Pixiv that utilizes no Javascript. (", Element("a", {{"href", "https://gitlab.com/blankX/pixwhile"}}, {"source code"}), ")", + Element("form", {{"method", "get"}, {"action", "search"}}, { + Element("br"), + Element("input", {{"name", "q"}, {"required", ""}}, {}), + " ", + Element("button", {"Search for illustrations"}) + }), Element("h2", {"Try it out"}), Element("ul", { get_artwork_element(106623268, "アル社長の日常", 1960050, "torino"), @@ -24,12 +30,13 @@ void home_route(const httplib::Request& req, httplib::Response& res, const Confi Element("ul", { Element("li", {"Does not contain an asinine amount of Javascript"}), Element("li", {"Allows you to open the original versions of cover images and profile pictures"}), - Element("li", {"Can view illustrations and list user illustrations"}) + Element("li", {"Can view illustrations and list user illustrations"}), + Element("li", {"Can search for newest and oldest illustrations"}) }), Element("h2", {"Missing Features"}), Element("p", {"This list is not exhaustive, nor does it mean that these are being worked on."}), Element("ul", { - Element("li", {"No search"}), + Element("li", {"Can only search for newest and oldest illustrations"}), Element("li", {"No ability to login"}), Element("li", {"No ability to see comments or like counts"}), })