Lazyload images

This commit is contained in:
blankie 2023-11-25 14:53:34 +11:00
parent 788ad5eb58
commit 74a3eb2ae0
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
3 changed files with 5 additions and 5 deletions

View File

@ -27,7 +27,7 @@ void about_route(const httplib::Request& req, httplib::Response& res) {
Element body("body", { Element body("body", {
Element("a", {{"href", instance.thumbnail}}, { Element("a", {{"href", instance.thumbnail}}, {
Element("img", {{"class", "about_page-header"}, {"src", instance.thumbnail}}, {}), Element("img", {{"class", "about_page-header"}, {"loading", "lazy"}, {"src", instance.thumbnail}}, {}),
}), }),
Element("p", { Element("p", {
Element("b", {instance.title, ":"}), " ", instance.description, Element("b", {instance.title, ":"}), " ", instance.description,

View File

@ -99,11 +99,11 @@ static inline Element user_header(const httplib::Request& req, const std::string
Element header("header", { Element header("header", {
Element("a", {{"href", account.header}}, { Element("a", {{"href", account.header}}, {
Element("img", {{"class", "user_page-header"}, {"alt", "User header"}, {"src", account.header}}, {}), Element("img", {{"class", "user_page-header"}, {"alt", "User header"}, {"loading", "lazy"}, {"src", account.header}}, {}),
}), }),
Element("div", {{"class", "user_page-main_header"}}, { Element("div", {{"class", "user_page-main_header"}}, {
Element("a", {{"href", account.avatar}}, { Element("a", {{"href", account.avatar}}, {
Element("img", {{"class", "user_page-profile"}, {"alt", "User profile picture"}, {"src", account.avatar}}, {}), Element("img", {{"class", "user_page-profile"}, {"alt", "User profile picture"}, {"loading", "lazy"}, {"src", account.avatar}}, {}),
}), }),
Element("span", { Element("span", {
Element("b", {preprocess_html(req, account.emojis, account.display_name)}), account.bot ? " (bot)" : "", " (@", account.acct(), ")", view_on_original, Element("b", {preprocess_html(req, account.emojis, account.display_name)}), account.bot ? " (bot)" : "", " (@", account.acct(), ")", view_on_original,

View File

@ -394,7 +394,7 @@ static Element serialize_post(const httplib::Request& req, const std::string& se
Element div("div", {{"class", "post"}}, { Element div("div", {{"class", "post"}}, {
Element("div", {{"class", "post-header"}}, { Element("div", {{"class", "post-header"}}, {
Element("a", {{"href", get_origin(req) + '/' + server + "/@" + post.account.acct(false)}}, { Element("a", {{"href", get_origin(req) + '/' + server + "/@" + post.account.acct(false)}}, {
Element("img", {{"class", "post-avatar"}, {"alt", "User profile picture"}, {"src", post.account.avatar_static}}, {}), Element("img", {{"class", "post-avatar"}, {"alt", "User profile picture"}, {"loading", "lazy"}, {"src", post.account.avatar_static}}, {}),
Element("span", { Element("span", {
Element("b", {preprocess_html(req, post.account.emojis, post.account.display_name)}), Element("b", {preprocess_html(req, post.account.emojis, post.account.display_name)}),
Element("br"), "@", post.account.acct(), Element("br"), "@", post.account.acct(),
@ -423,7 +423,7 @@ static inline Element serialize_media(const Media& media) {
Element element = [&]() { Element element = [&]() {
if (media.type == "image") { if (media.type == "image") {
return Element("a", {{"href", media.url}}, { return Element("a", {{"href", media.url}}, {
Element("img", {{"src", media.preview_url.value_or(media.url)}}, {}), Element("img", {{"loading", "lazy"}, {"src", media.preview_url.value_or(media.url)}}, {}),
}); });
} else if (media.type == "video") { } else if (media.type == "video") {
Element video("video", {{"controls", ""}, {"src", media.url}}, {}); Element video("video", {{"controls", ""}, {"src", media.url}}, {});