Add URL query parameters to the canonical URL

This commit is contained in:
blankie 2023-06-07 15:12:39 +07:00
parent 21fc3e43d8
commit 7c772b924c
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
3 changed files with 20 additions and 8 deletions

View File

@ -13,7 +13,7 @@ static inline Nodes parse_description_line(const httplib::Request& req, const Co
static inline Element generate_description(const httplib::Request& req, const Config& config, const std::string& description);
static inline Element generate_illust_tags(const httplib::Request& req, const Config& config, const Illust& illust);
static inline std::string generate_description_text(const httplib::Request& req, const Config& config, std::string description);
static inline Nodes generate_ogp_nodes(const httplib::Request& req, const Config& config, const Illust& illust);
static inline Nodes generate_ogp_nodes(const httplib::Request& req, const Config& config, const Illust& illust, bool preview);
static inline bool is_true(const std::string& str);
static inline std::string time_to_string(time_t time);
@ -53,7 +53,7 @@ void artworks_route(const httplib::Request& req, httplib::Response& res, const C
}
body.nodes.push_back(generate_illust_tags(req, config, illust));
body.nodes.push_back(Element("p", {time_to_string(illust.upload_time)}));
serve(req, res, config, illust.title, std::move(body), generate_ogp_nodes(req, config, illust));
serve(req, res, config, illust.title, std::move(body), generate_ogp_nodes(req, config, illust, preview));
}
static inline Element generate_user_link(const httplib::Request& req, const Config& config, const Illust& illust) {
@ -227,12 +227,16 @@ static inline std::string generate_description_text(const httplib::Request& req,
return new_description;
}
static inline Nodes generate_ogp_nodes(const httplib::Request& req, const Config& config, const Illust& illust) {
static inline Nodes generate_ogp_nodes(const httplib::Request& req, const Config& config, const Illust& illust, bool preview) {
std::string url = get_origin(req, config) + "/artworks/" + std::to_string(illust.illust_id);
if (preview) {
url += "?preview=1";
}
Nodes nodes({
Element("meta", {{"property", "og:title"}, {"content", illust.title}}, {}),
Element("meta", {{"property", "og:type"}, {"content", "photo"}}, {}),
Element("meta", {{"property", "og:site_name"}, {"content", "Pixwhile"}}, {}),
Element("meta", {{"property", "og:url"}, {"content", get_origin(req, config) + "/artworks/" + std::to_string(illust.illust_id)}}, {})
Element("meta", {{"property", "og:url"}, {"content", std::move(url)}}, {})
});
if (illust.comment) {
nodes.push_back(Element("meta", {{"property", "og:description"}, {"content", generate_description_text(req, config, *illust.comment)}}, {}));

View File

@ -6,7 +6,7 @@
#include "../../pixivclient.h"
#include "common.h"
static inline Nodes generate_ogp_nodes(const httplib::Request& req, const Config& config, const User& user);
static inline Nodes generate_ogp_nodes(const httplib::Request& req, const Config& config, const User& user, uint64_t page);
void user_illustrations_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client) {
uint64_t user_id = to_ull(req.matches[1].str());
@ -36,15 +36,21 @@ void user_illustrations_route(const httplib::Request& req, httplib::Response& re
generate_user_header(std::move(user), config),
generate_illusts_pager(req, config, illusts, page, "illusts")
});
serve(req, res, config, user.display_name + "'s illustrations", std::move(body), generate_ogp_nodes(req, config, user));
serve(req, res, config, user.display_name + "'s illustrations", std::move(body), generate_ogp_nodes(req, config, user, page));
}
static inline Nodes generate_ogp_nodes(const httplib::Request& req, const Config& config, const User& user) {
static inline Nodes generate_ogp_nodes(const httplib::Request& req, const Config& config, const User& user, uint64_t page) {
using namespace std::string_literals;
std::string url = get_origin(req, config) + "/users/" + std::to_string(user.user_id) + "/illustrations";
if (page != 0) {
url += "?p="s + std::to_string(page + 1);
}
Nodes nodes({
Element("meta", {{"property", "og:title"}, {"content", user.display_name + " (@" + user.username + ')'}}, {}),
Element("meta", {{"property", "og:type"}, {"content", user.ogp_image ? "photo" : "website"}}, {}),
Element("meta", {{"property", "og:site_name"}, {"content", "Pixwhile"}}, {}),
Element("meta", {{"property", "og:url"}, {"content", get_origin(req, config) + "/users/" + std::to_string(user.user_id) + "/illustrations"}}, {})
Element("meta", {{"property", "og:url"}, {"content", std::move(url)}}, {})
});
if (user.ogp_image) {
nodes.push_back(Element("meta", {{"property", "og:image"}, {"content", proxy_image_url(config, *user.ogp_image)}}, {}));

View File

@ -37,6 +37,8 @@
// Source: fast-hash https://github.com/ztanml/fast-hash (26 Nov 2021)
// Changes: General uplift and providing a general constant hash for ranges
#include <cstdint>
#pragma once
// Compression function for Merkle-Damgard construction.