Skip to content

Commit d9bcd68

Browse files
committed
add setting to prevent rendering image titles as captions
1 parent e534179 commit d9bcd68

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/MarkdownRenderer.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,13 @@ export class CodeBlock extends React.PureComponent<
144144
}
145145

146146
function PlainImage(imageProps) {
147+
const {
148+
config: {displayImageTitleAsCaption},
149+
} = React.useContext(ConfigContext);
147150
const {isRss, src, ...props} = imageProps;
151+
const title = displayImageTitleAsCaption
152+
? props.title || props['data-caption']
153+
: props['data-caption'];
148154
return (
149155
<Box
150156
margin={{vertical: 'medium'}}
@@ -160,15 +166,15 @@ function PlainImage(imageProps) {
160166
{...props}
161167
/>
162168
{isRss ? <br /> : null}
163-
{props.title ? (
169+
{title ? (
164170
<Text
165171
style={{display: 'block'}}
166172
size="xsmall"
167173
margin="small"
168174
weight={300}
169175
color="dark-1"
170176
textAlign="center">
171-
{isRss ? <em>{props.title}</em> : props.title}
177+
{isRss ? <em>{title}</em> : title}
172178
</Text>
173179
) : null}
174180
</Box>

src/config.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ if (
3939
);
4040
}
4141

42+
function parseBool({
43+
value,
44+
defaultValue,
45+
}: {
46+
value: any,
47+
defaultValue: boolean,
48+
}): boolean {
49+
if (value == null) {
50+
return defaultValue;
51+
}
52+
try {
53+
return JSON.parse(value);
54+
} catch (e) {
55+
return defaultValue;
56+
}
57+
}
58+
4259
const config: Config = {
4360
// Owner of the repo that OneBlog should pull issues from
4461
repoOwner: ensureEnv(
@@ -59,12 +76,19 @@ const config: Config = {
5976
description: process.env.NEXT_PUBLIC_DESCRIPTION,
6077
defaultLogin: process.env.NEXT_PUBLIC_DEFAULT_GITHUB_LOGIN,
6178
siteHostname: removeTrailingSlash(process.env.NEXT_PUBLIC_SITE_HOSTNAME),
62-
hideAttribution: process.env.NEXT_PUBLIC_HIDE_ATTRIBUTION,
79+
hideAttribution: parseBool({
80+
value: process.env.NEXT_PUBLIC_HIDE_ATTRIBUTION,
81+
defaultValue: false,
82+
}),
6383
gaTrackingId: process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID,
6484
vercelUrl: process.env.NEXT_PUBLIC_VERCEL_URL
6585
? removeTrailingSlash(`https://${process.env.NEXT_PUBLIC_VERCEL_URL}`)
6686
: null,
6787
codeTheme: process.env.NEXT_PUBLIC_CODE_THEME || 'dark-plus',
88+
displayImageTitleAsCaption: parseBool({
89+
value: process.env.NEXT_PUBLIC_DISPLAY_IMAGE_TITLE_AS_CAPTION,
90+
defaultValue: true,
91+
}),
6892
};
6993

7094
export default config;

0 commit comments

Comments
 (0)