diff --git a/routes/artworks.cpp b/routes/artworks.cpp index 9a2830e..9c72165 100644 --- a/routes/artworks.cpp +++ b/routes/artworks.cpp @@ -4,10 +4,11 @@ #include "../pixivclient.h" static inline bool is_true(const std::string& str); +static inline std::string time_to_string(time_t time); 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_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_tags(const Illust& illust); 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)); @@ -36,7 +37,8 @@ void artworks_route(const httplib::Request& req, httplib::Response& res, const C generate_user_link(req, config, illust), !preview ? generate_images(req, config, illust) : generate_preview_images(req, config, illust), Element("br"), - generate_illust_metadata(illust) + generate_illust_tags(illust), + Element("p", {time_to_string(illust.upload_time)}) }); serve(req, res, config, std::move(illust.title), std::move(body)); } @@ -101,8 +103,8 @@ static inline Element generate_preview_images(const httplib::Request& req, const return div; } -static inline Element generate_illust_metadata(const Illust& illust) { - Element div("div", {{"class", "illustmetadata"}}, {}); +static inline Element generate_illust_tags(const Illust& illust) { + Element div("div", {{"class", "illusttags"}}, {}); if (illust.ai_generated) { div.nodes.push_back(Element("b", {"AI-Generated "})); @@ -124,3 +126,18 @@ static inline Element generate_illust_metadata(const Illust& illust) { static inline bool is_true(const std::string& str) { return !str.empty() && str != "0" && str != "false" && str != "no"; } + +static inline std::string time_to_string(time_t time) { + struct tm tm; + char str[1024] = {0}; + + if (!gmtime_r(&time, &tm)) { + return std::to_string(time); + } + size_t len = strftime(str, 1024, "%F %H:%M:%S %z", &tm); + if (len == 0) { + return std::to_string(time); + } + + return std::string(str, len); +} diff --git a/routes/css.cpp b/routes/css.cpp index fed660f..0e4eb2b 100644 --- a/routes/css.cpp +++ b/routes/css.cpp @@ -79,7 +79,7 @@ void css_route(const httplib::Request& req, httplib::Response& res) { } /* ILLUSTRATIONS PAGE */ - .illustmetadata { + .illusttags { display: flex; flex-wrap: wrap; gap: 1em;