Skip to content

Commit fd95efe

Browse files
committed
Add featuredImageCaption feature
1 parent 0379d0a commit fd95efe

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"scripts": {
1919
"build-move": "gatsby build && bash ./src/scripts/move-index.sh",
2020
"build": "gatsby build",
21-
"start": "TAILWIND_MODE=watch NODE_OPTIONS='--max_old_space_size=8192' gatsby develop -H 0.0.0.0 -p 8001",
21+
"start": "NODE_TLS_REJECT_UNAUTHORIZED=0 TAILWIND_MODE=watch NODE_OPTIONS='--max_old_space_size=8192' gatsby develop -H 0.0.0.0 -p 8001",
2222
"serve": "gatsby serve",
2323
"format": "prettier --write \"**/*.{html,js,ts,tsx,json,yml,css,scss}\"",
2424
"clean": "gatsby clean",

src/components/ReaderView/index.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ interface ReaderViewProps {
4848
type: 'mdx' | 'plain'
4949
content: string
5050
featuredImage?: any
51+
featuredImageCaption?: string
5152
contributors?: any[]
5253
date?: string
5354
featuredVideo?: string
@@ -596,6 +597,7 @@ function ReaderViewContent({
596597
})
597598
}
598599
}, [appWindow?.path, hash])
600+
const image = getImage(body.featuredImage)
599601

600602
return (
601603
<SearchProvider>
@@ -680,12 +682,23 @@ function ReaderViewContent({
680682
>
681683
{/* <DebugContainerQuery /> */}
682684
{body.featuredImage && !body.featuredVideo && (
683-
<div className="not-prose mb-4 text-center">
684-
<GatsbyImage
685-
image={getImage(body.featuredImage)}
686-
alt={title}
687-
className="rounded"
688-
/>
685+
<div className="not-prose mb-6 relative">
686+
<div className="text-center">
687+
{image ? (
688+
<GatsbyImage image={image} alt={title} className="rounded" />
689+
) : body.featuredImage?.publicURL ? (
690+
<img
691+
src={body.featuredImage.publicURL}
692+
alt={title}
693+
className="rounded w-full"
694+
/>
695+
) : null}
696+
</div>
697+
{body.featuredImageCaption && (
698+
<div className="absolute right-0 bottom-0 m-2 text-sm text-white bg-black bg-opacity-75 font-medium py-1 px-2 rounded-sm italic text-right">
699+
{body.featuredImageCaption}
700+
</div>
701+
)}
689702
</div>
690703
)}
691704
{title && !hideTitle && (
@@ -701,7 +714,7 @@ function ReaderViewContent({
701714
)}
702715
{(body.date || body.contributors || body.tags) && (
703716
<div
704-
className={`flex items-center space-x-2 mb-4 flex-wrap mx-auto transition-all ${
717+
className={`flex items-center space-x-2 mt-4 flex-wrap mx-auto transition-all ${
705718
fullWidthContent || body?.type !== 'mdx'
706719
? 'max-w-full'
707720
: contentMaxWidthClass || 'max-w-2xl'

src/templates/BlogPost.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,17 @@ const Filters = ({ tag, setTag, sort, setSort, activeMenu }) => {
284284
export default function BlogPost({ data, pageContext, location, mobile = false }) {
285285
const { postData } = data
286286
const { body, excerpt, fields } = postData
287-
const { date, title, featuredImage, featuredVideo, featuredImageType, contributors, tags, seo } =
288-
postData?.frontmatter
287+
const {
288+
date,
289+
title,
290+
featuredImage,
291+
featuredImageCaption,
292+
featuredVideo,
293+
featuredImageType,
294+
contributors,
295+
tags,
296+
seo,
297+
} = postData?.frontmatter
289298
const lastUpdated = postData?.parent?.fields?.gitLogLatestDate
290299
const filePath = postData?.parent?.relativePath
291300
const category = postData?.parent?.category
@@ -419,6 +428,7 @@ export default function BlogPost({ data, pageContext, location, mobile = false }
419428
type: 'mdx',
420429
content: body,
421430
featuredImage,
431+
featuredImageCaption,
422432
contributors,
423433
date,
424434
featuredVideo,
@@ -477,6 +487,7 @@ export const query = graphql`
477487
gatsbyImageData
478488
}
479489
}
490+
featuredImageCaption
480491
contributors: authorData {
481492
id
482493
name

tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ module.exports = {
9999
borderRadius: {
100100
xs: '2px',
101101
sm: '4px',
102+
DEFAULT: '6px',
102103
lg: '20px',
103104
},
104105
borderWidth: {

0 commit comments

Comments
 (0)