diff options
Diffstat (limited to 'juick-www/src/main/java/com/juick/www')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/controllers/UserThread.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/UserThread.java b/juick-www/src/main/java/com/juick/www/controllers/UserThread.java index f15861f4..400f231a 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/UserThread.java +++ b/juick-www/src/main/java/com/juick/www/controllers/UserThread.java @@ -16,11 +16,15 @@ */ package com.juick.www.controllers; +import com.juick.formatters.PlainTextFormatter; import com.juick.server.util.HttpForbiddenException; import com.juick.server.util.HttpNotFoundException; import com.juick.server.util.UserUtils; +import com.juick.service.CrosspostService; import com.juick.service.MessagesService; import com.juick.service.UserService; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.StringEscapeUtils; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; @@ -46,6 +50,8 @@ public class UserThread { private MessagesService messagesService; @Inject private UserService userService; + @Inject + private CrosspostService crosspostService; @GetMapping("/{uname}/{mid}") protected String threadAction(ModelMap model, @@ -94,12 +100,25 @@ public class UserThread { model.addAttribute("title", title); model.addAttribute("visitor", visitor); String headers = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + msg.getUser().getName() + "\" href=\"//rss.juick.com/" + msg.getUser().getName() + "/blog\"/>"; + String pageUrl = "//juick.com/" + msg.getUser().getName() + "/" + msg.getMid(); if (paramView != null) { - headers += "<link rel=\"canonical\" href=\"http://juick.com/" + msg.getUser().getName() + "/" + msg.getMid() + "\"/>"; + headers += "<link rel=\"canonical\" href=\"" + pageUrl + "\"/>"; } if (msg.Hidden) { headers += "<meta name=\"robots\" content=\"noindex\"/>"; } + String cardType = StringUtils.isNotEmpty(msg.getAttachmentType()) ? "summary_large_image" : "summary"; + String msgImage = StringUtils.isNotEmpty(msg.getAttachmentType()) ? msg.getAttachmentURL() : "//i.juick.com/a/" + msg.getUser().getUid() + ".png"; + headers += "<meta name=\"twitter:card\" content=\"" + cardType + "\" />\n" + + "<meta name=\"twitter:site\" content=\"@juick\" />\n" + + "<meta property=\"og:url\" content=\"" + pageUrl + "\" />\n" + + "<meta property=\"og:title\" content=\"" + msg.getUser().getName() + " at Juick\" />\n" + + "<meta property=\"og:description\" content=\"" + StringEscapeUtils.escapeHtml4(PlainTextFormatter.formatTwitterCard(msg)) + "\" />\n" + + "<meta property=\"og:image\" content=\"" + msgImage + "\" />"; + String twitterName = crosspostService.getTwitterName(msg.getUser().getUid()); + if (StringUtils.isNotEmpty(twitterName)) { + headers += "<meta name=\"twitter:creator\" content=\"@" + twitterName + "\" />\n"; + } model.addAttribute("headers", headers); model.addAttribute("contentStyle", "margin-left: 0; width: 100%"); model.addAttribute("isModerator", visitor.getUid() == 3694); |