19 package org.turro.elephant.web;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.List;
24 import org.turro.string.Strings;
25 import org.turro.elephant.context.ElephantContext;
26 import org.turro.elephant.impl.repository.Repository;
27 import org.turro.elephant.impl.repository.RepositoryFile;
28 import org.turro.html.HtmlContent;
36 private final String url, title, description;
39 public SocialNet(String url, String title, String description, Collection<RepositoryFile> files) {
42 this.description = escape(description);
49 return image !=
null && !image.
isEmpty();
65 ArrayList<String> metas =
new ArrayList<>();
69 metas.add(
"<meta name=\"twitter:card\" content=\"summary\">");
71 metas.add(
"<meta name=\"twitter:card\" content=\"summary_large_image\">");
73 metas.add(
"<meta name=\"twitter:title\" content=\"" + escape(title) +
"\"/>");
74 if(!Strings.isBlank(description)) {
75 metas.add(
"<meta name=\"twitter:description\" content=\"" + Strings.truncateAndWarn(description, 250) +
"\"/>");
83 metas.add(
"<meta property=\"og:type\" content=\"website\"/>");
85 metas.add(
"<meta property=\"og:title\" content=\"" + escape(title) +
"\"/>");
86 if(!Strings.isBlank(description)) {
87 metas.add(
"<meta property=\"og:description\" content=\"" + Strings.truncateAndWarn(description, 250) +
"\"/>");
96 private String escape(String text) {
97 if(!Strings.isBlank(text)) {
98 text = HtmlContent.text(text);
99 text = text.replaceAll(
"\"",
"'");
100 text = text.replaceAll(
"\n",
" ");
static String getServerBase(String scheme)
static String getSiteName()
Set< RepositoryFile > getRepositoryFiles(String pattern)
static ElContext getRoot()
Repository getRepository()
static void initialize(SocialNet context, Collection< RepositoryFile > files)
SocialNet(String url, String title, String description, Collection< RepositoryFile > files)
List< String > getMetas()
void setImage(SocialImage image)