- def build_tags(%{activity: activity, user: user}) do
- with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do
- [
- {:meta,
- [
- property: "og:title",
- content: user_name_string(user)
- ], []},
- {:meta, [property: "og:url", content: activity.data["id"]], []},
- {:meta, [property: "og:description", content: truncated_content], []},
- {:meta, [property: "og:image", content: user_avatar_url(user)], []},
- {:meta, [property: "og:image:width", content: 120], []},
- {:meta, [property: "og:image:height", content: 120], []},
- {:meta, [property: "twitter:card", content: "summary"], []}
- ]
- end
+ def build_tags(%{
+ object: object,
+ url: url,
+ user: user
+ }) do
+ attachments = build_attachments(object)
+ scrubbed_content = Utils.scrub_html_and_truncate(object)
+ # Zero width space
+ content =
+ if scrubbed_content != "" and scrubbed_content != "\u200B" do
+ ": “" <> scrubbed_content <> "”"
+ else
+ ""
+ end
+
+ # Most previews only show og:title which is inconvenient. Instagram
+ # hacks this by putting the description in the title and making the
+ # description longer prefixed by how many likes and shares the post
+ # has. Here we use the descriptive nickname in the title, and expand
+ # the full account & nickname in the description. We also use the cute^Wevil
+ # smart quotes around the status text like Instagram, too.
+ [
+ {:meta,
+ [
+ property: "og:title",
+ content: "#{user.name}" <> content
+ ], []},
+ {:meta, [property: "og:url", content: url], []},
+ {:meta,
+ [
+ property: "og:description",
+ content: "#{Utils.user_name_string(user)}" <> content
+ ], []},
+ {:meta, [property: "og:type", content: "website"], []}
+ ] ++
+ if attachments == [] or Metadata.activity_nsfw?(object) do
+ [
+ {:meta, [property: "og:image", content: Utils.attachment_url(User.avatar_url(user))],
+ []},
+ {:meta, [property: "og:image:width", content: 150], []},
+ {:meta, [property: "og:image:height", content: 150], []}
+ ]
+ else
+ attachments
+ end