]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/features/status/components/card.js
1 import React
from 'react';
2 import ImmutablePropTypes
from 'react-immutable-proptypes';
3 import punycode
from 'punycode';
5 const IDNA_PREFIX
= 'xn--';
7 const decodeIDNA
= domain
=> {
10 .map(part
=> part
.indexOf(IDNA_PREFIX
) === 0 ? punycode
.decode(part
.slice(IDNA_PREFIX
.length
)) : part
)
14 const getHostname
= url
=> {
15 const parser
= document
.createElement('a');
17 return parser
.hostname
;
20 class Card
extends React
.PureComponent
{
23 card: ImmutablePropTypes
.map
,
27 const { card
} = this.props
;
30 let provider
= card
.get('provider_name');
32 if (card
.get('image')) {
34 <div className
='status-card__image'>
35 <img src
={card
.get('image')} alt
={card
.get('title')} className
='status-card__image-image' />
40 if (provider
.length
< 1) {
41 provider
= decodeIDNA(getHostname(card
.get('url')));
45 <a href
={card
.get('url')} className
='status-card' target
='_blank' rel
='noopener'>
48 <div className
='status-card__content'>
49 <strong className
='status-card__title' title
={card
.get('title')}>{card
.get('title')}</strong
>
50 <p className
='status-card__description'>{(card
.get('description') || '').substring(0, 50)}</p
>
51 <span className
='status-card__host'>{provider
}</span
>
58 const { card
} = this.props
;
61 <a href
={card
.get('url')} className
='status-card-photo' target
='_blank' rel
='noopener'>
62 <img src
={card
.get('url')} alt
={card
.get('title')} width
={card
.get('width')} height
={card
.get('height')} />
68 const { card
} = this.props
;
69 const content
= { __html: card
.get('html') };
73 className
='status-card-video'
74 dangerouslySetInnerHTML
={content
}
80 const { card
} = this.props
;
86 switch(card
.get('type')) {
88 return this.renderLink();
90 return this.renderPhoto();
92 return this.renderVideo();
This page took 0.107447 seconds and 4 git commands to generate.