Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/helpers/generate-image-from-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ type GetMetaImageInput = {
footer: string,
};

const generateImageFromText = ({ title, footer }: GetMetaImageInput) => {
const generateImageFromText = ({
title,
footer,
}: GetMetaImageInput): ?string => {
const base64title = btoa(title);
const base64footer = btoa(footer);
if (!base64title || !base64footer) return;
if (!base64title || !base64footer) return null;

const titleUrl = `${IMGIX_TEXT_ENDPOINT}?${stringify(
{ ...TITLE_PARAMS, txt64: base64title.replace(/=/g, '') },
Expand All @@ -55,7 +58,7 @@ const generateImageFromText = ({ title, footer }: GetMetaImageInput) => {
const base64titleurl = btoa(titleUrl);
const base64footerurl = btoa(footerUrl);

if (!base64titleurl || !base64footerurl) return;
if (!base64titleurl || !base64footerurl) return null;

const BACKGROUND_PARAMS = {
w: WIDTH,
Expand Down
17 changes: 10 additions & 7 deletions src/views/thread/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ class ThreadContainer extends React.Component<Props, State> {
const headDescription = isWatercooler
? `Watercooler chat for the ${thread.community.name} community`
: description;
const metaImage = generateImageFromText({
title: isWatercooler
? `Chat with the ${thread.community.name} community`
: thread.content.title,
footer: `spectrum.chat/${thread.community.slug}`,
});

return (
<ErrorBoundary>
Expand All @@ -458,14 +464,11 @@ class ThreadContainer extends React.Component<Props, State> {
title={headTitle}
description={headDescription}
type="article"
image={generateImageFromText({
title: isWatercooler
? `Chat with the ${thread.community.name} community`
: thread.content.title,
footer: `spectrum.chat/${thread.community.slug}`,
})}
image={metaImage}
>
<meta name="twitter:card" content="summary_large_image" />
{metaImage && (
<meta name="twitter:card" content="summary_large_image" />
)}
<meta
property="article:published_time"
content={new Date(thread.createdAt).toISOString()}
Expand Down