Skip to content

Commit

Permalink
[Glitch] Add support for fediverse:creator OpenGraph tag
Browse files Browse the repository at this point in the history
Port 128987e to glitch-soc

Signed-off-by: Claire <[email protected]>
  • Loading branch information
Gargron authored and ClearlyClaire committed May 29, 2024
1 parent 2e3d6e4 commit 4069fae
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
31 changes: 26 additions & 5 deletions app/javascript/flavours/glitch/features/status/components/card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
import DescriptionIcon from '@/material-icons/400-24px/description-fill.svg?react';
import OpenInNewIcon from '@/material-icons/400-24px/open_in_new.svg?react';
import PlayArrowIcon from '@/material-icons/400-24px/play_arrow-fill.svg?react';
import { Avatar } from 'flavours/glitch/components/avatar';
import { Blurhash } from 'flavours/glitch/components/blurhash';
import { Icon } from 'flavours/glitch/components/icon';
import { Permalink } from 'flavours/glitch/components/permalink';
import { RelativeTimestamp } from 'flavours/glitch/components/relative_timestamp';
import { useBlurhash } from 'flavours/glitch/initial_state';
import { decode as decodeIDNA } from 'flavours/glitch/utils/idna';
Expand Down Expand Up @@ -46,6 +48,20 @@ const addAutoPlay = html => {
return html;
};

const MoreFromAuthor = ({ author }) => (
<div className='more-from-author'>
<svg viewBox='0 0 79 79' className='logo logo--icon' role='img'>
<use xlinkHref='#logo-symbol-icon' />
</svg>

<FormattedMessage id='link_preview.more_from_author' defaultMessage='More from {name}' values={{ name: <Permalink href={author.get('url')} to={`/@${author.get('acct')}`}><Avatar account={author} size={16} /> {author.get('display_name')}</Permalink> }} />
</div>
);

MoreFromAuthor.propTypes = {
author: ImmutablePropTypes.map,
};

export default class Card extends PureComponent {

static propTypes = {
Expand Down Expand Up @@ -126,6 +142,7 @@ export default class Card extends PureComponent {
const interactive = card.get('type') === 'video';
const language = card.get('language') || '';
const largeImage = (card.get('image')?.length > 0 && card.get('width') > card.get('height')) || interactive;
const showAuthor = !!card.get('author_account');

const description = (
<div className='status-card__content'>
Expand All @@ -136,7 +153,7 @@ export default class Card extends PureComponent {

<strong className='status-card__title' title={card.get('title')} lang={language}>{card.get('title')}</strong>

{card.get('author_name').length > 0 ? <span className='status-card__author'><FormattedMessage id='link_preview.author' defaultMessage='By {name}' values={{ name: <strong>{card.get('author_name')}</strong> }} /></span> : <span className='status-card__description' lang={language}>{card.get('description')}</span>}
{!showAuthor && (card.get('author_name').length > 0 ? <span className='status-card__author'><FormattedMessage id='link_preview.author' defaultMessage='By {name}' values={{ name: <strong>{card.get('author_name')}</strong> }} /></span> : <span className='status-card__description' lang={language}>{card.get('description')}</span>)}
</div>
);

Expand Down Expand Up @@ -225,10 +242,14 @@ export default class Card extends PureComponent {
}

return (
<a href={card.get('url')} className={classNames('status-card', { expanded: largeImage })} target='_blank' rel='noopener noreferrer' ref={this.setRef}>
{embed}
{description}
</a>
<>
<a href={card.get('url')} className={classNames('status-card', { expanded: largeImage, bottomless: showAuthor })} target='_blank' rel='noopener noreferrer' ref={this.setRef}>
{embed}
{description}
</a>

{showAuthor && <MoreFromAuthor author={card.get('author_account')} />}
</>
);
}

Expand Down
43 changes: 43 additions & 0 deletions app/javascript/flavours/glitch/styles/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4133,6 +4133,10 @@ input.glitch-setting-text {
border: 1px solid var(--background-border-color);
border-radius: 8px;

&.bottomless {
border-radius: 8px 8px 0 0;
}

&__actions {
bottom: 0;
inset-inline-start: 0;
Expand Down Expand Up @@ -10811,3 +10815,42 @@ noscript {
}
}
}

.more-from-author {
font-size: 14px;
color: $darker-text-color;
background: var(--surface-background-color);
border: 1px solid var(--background-border-color);
border-top: 0;
border-radius: 0 0 8px 8px;
padding: 15px;
display: flex;
align-items: center;
gap: 8px;

.logo {
height: 16px;
color: $darker-text-color;
}

& > span {
display: flex;
align-items: center;
gap: 8px;
}

a {
display: inline-flex;
align-items: center;
gap: 4px;
font-weight: 500;
color: $primary-text-color;
text-decoration: none;

&:hover,
&:focus,
&:active {
color: $highlight-text-color;
}
}
}

0 comments on commit 4069fae

Please sign in to comment.