Skip to content

Commit fae4984

Browse files
committed
better handling of rss
1 parent 737cca4 commit fae4984

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/MarkdownRenderer.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,13 @@ function PlainImage(imageProps) {
124124
justify="center"
125125
style={{display: 'flex'}}>
126126
{/*eslint-disable-next-line jsx-a11y/alt-text*/}
127-
<img style={{maxWidth: '100%'}} src={imageUrl({src})} {...props} />
128-
{props.isRss ? <br /> : null}
127+
<img
128+
style={{maxWidth: '100%'}}
129+
// Don't proxy image if it's served on an RSS feed to avoid CORs errors
130+
src={isRss ? src : imageUrl({src})}
131+
{...props}
132+
/>
133+
{isRss ? <br /> : null}
129134
{props.title ? (
130135
<Text
131136
style={{display: 'block'}}
@@ -134,7 +139,7 @@ function PlainImage(imageProps) {
134139
weight={300}
135140
color="dark-1"
136141
textAlign="center">
137-
{props.isRss ? <em>{props.title}</em> : props.title}
142+
{isRss ? <em>{props.title}</em> : props.title}
138143
</Text>
139144
) : null}
140145
</Box>
@@ -147,7 +152,7 @@ function isGif(src: string) {
147152
}
148153

149154
function Image(props) {
150-
if (props.src && isGif(props.src)) {
155+
if (props.src && isGif(props.src) && !props.isRss) {
151156
return (
152157
<Box margin={{vertical: 'medium'}}>
153158
<GifPlayer style={{maxWidth: '100%'}} src={props.src} />

src/imageUrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const imageUrl = ({
1212
}): ?string => {
1313
const basePath = useBasePath();
1414
if (src) {
15-
return `${basePath}/api/image/${
15+
return `${basePath || ''}/api/image/${
1616
firstFrame ? 'firstFrame/' : ''
1717
}${base64Encode(src)}`;
1818
}

src/lib/useBasePath.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
// @flow
2+
13
import {useRouter} from 'next/router';
24

3-
export default function useBasePath() {
5+
export default function useBasePath(): string {
46
try {
57
const router = useRouter();
68
if (router) {
7-
return router.basePath;
9+
return router.basePath || '';
10+
} else {
11+
return process.env.BASE_PATH || '';
812
}
913
} catch (_e) {
1014
return process.env.BASE_PATH || '';

0 commit comments

Comments
 (0)