Skip to content

Commit cea4832

Browse files
committed
Refactored post and layout to extract RelatedPosts, ShareButtons
Added BuyMeACofee button Created new article about management path
1 parent edf7940 commit cea4832

File tree

11 files changed

+5379
-4471
lines changed

11 files changed

+5379
-4471
lines changed

.ghost.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"contentApiKey": "b005756f83ee6e0d74275ac47c"
55
},
66
"production": {
7-
"apiUrl": "https://a75622ec71a4.ngrok.io",
7+
"apiUrl": "https://ca4a1eeabd14.ngrok.io",
88
"contentApiKey": "b005756f83ee6e0d74275ac47c"
99
}
1010
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"babel-plugin-prismjs": "^2.0.1",
4848
"babel-preset-gatsby": "^0.3.4",
4949
"cheerio": "1.0.0-rc.3",
50-
"gatsby": "2.19.23",
50+
"gatsby": "2.13.1",
5151
"gatsby-awesome-pagination": "0.3.5",
5252
"gatsby-image": "2.2.41",
5353
"gatsby-plugin-advanced-sitemap": "1.5.2",

src/components/common/BuyMeACoffee.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React, { useEffect } from "react";
2+
import Helmet from "react-helmet";
3+
4+
const BuyMeACoffee = ({}) => {
5+
/*Load BuyMeACoffeeWidget*/
6+
useEffect(() => {
7+
const script = document.createElement("script");
8+
script.src = "https://cdnjs.buymeacoffee.com/1.0.0/widget.prod.min.js";
9+
script.async = false;
10+
11+
//Call window on load to show the image
12+
script.onload = () => {
13+
var evt = document.createEvent("Event");
14+
evt.initEvent("DOMContentLoaded", false, false);
15+
window.dispatchEvent(evt);
16+
};
17+
document.body.appendChild(script);
18+
19+
return () => {
20+
const bmcButton = document.getElementById("bmc-wbtn");
21+
bmcButton.remove();
22+
document.body.removeChild(script);
23+
};
24+
}, []);
25+
26+
return (
27+
<>
28+
<Helmet>
29+
<script
30+
async={false}
31+
data-name="BMC-Widget"
32+
data-cfasync="false"
33+
src="https://cdnjs.buymeacoffee.com/1.0.0/widget.prod.min.js"
34+
data-id="javaad"
35+
data-description="Support me on Buy me a coffee!"
36+
data-message=""
37+
data-color="#FFDD00"
38+
data-position="Right"
39+
data-x_margin="10"
40+
data-y_margin="65"
41+
></script>
42+
</Helmet>
43+
</>
44+
);
45+
};
46+
47+
export default BuyMeACoffee;

src/components/common/Footer/Footer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const Footer = ({ site }) => {
1818
alt="Javaad Patel"
1919
/>
2020
</Link>{" "}
21-
© {new Date().getFullYear()}
21+
© 2020 - {new Date().getFullYear()}
2222
</div>
2323
<div className="site-foot-nav-right">
2424
<Navigation

src/components/common/Header/Header__SocialIcons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const Header__SocialIcons = ({ anchorClassName, imageClassName }) => {
4040
className={anchorClassName}
4141
target={iconData.target}
4242
rel="noopener noreferrer"
43+
key={iconData.name}
4344
>
4445
<div>
4546
<img

src/components/common/Layout.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const DefaultLayout = ({ data, children, bodyClass, isHome }) => {
3535
window.dataLayer = window.dataLayer || [];
3636
function gtag(){dataLayer.push(arguments);}
3737
gtag('js', new Date());
38-
38+
3939
gtag('config', 'UA-164501208-1');
4040
`}
4141
</script>
@@ -59,29 +59,6 @@ const DefaultLayout = ({ data, children, bodyClass, isHome }) => {
5959
<div className="viewport-bottom">
6060
{/* The footer at the very bottom of the screen */}
6161
<Footer site={site} />
62-
{/* <footer className="site-foot">
63-
<div className="site-foot-nav container">
64-
<div className="site-foot-nav-left">
65-
<Link to="/">{site.title}</Link> ©{" "}
66-
{new Date().getFullYear()} &mdash; Published
67-
with{" "}
68-
<a
69-
className="site-foot-nav-item"
70-
href="https://ghost.org"
71-
target="_blank"
72-
rel="noopener noreferrer"
73-
>
74-
Ghost
75-
</a>
76-
</div>
77-
<div className="site-foot-nav-right">
78-
<Navigation
79-
data={site.navigation}
80-
navClass="site-foot-nav-item"
81-
/>
82-
</div>
83-
</div>
84-
</footer> */}
8562
</div>
8663
</div>
8764
</>

src/components/common/RelatedPosts.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import React from "react";
2+
import _ from "lodash";
3+
import { Grid } from "semantic-ui-react";
4+
import {PostCard} from ".";
5+
6+
import "../../styles/semantic-ui/grid.css";
7+
8+
const RelatedPosts = ({allPosts, post}) => {
9+
10+
let relatedPosts;
11+
let relatedPostsLimit = 2;
12+
13+
const findRelatedArticles = () => {
14+
const primaryTag = post.primary_tag.slug;
15+
const secondaryTag = _.chain(post.tags)
16+
.filter(function (p) {
17+
return p.slug !== primaryTag;
18+
})
19+
.head()
20+
.value()?.slug;
21+
const primaryRelatedArticles = _.chain(allPosts)
22+
.filter(function ({ node }) {
23+
return (
24+
node.tags.some(function ({ slug }) {
25+
return slug == primaryTag || slug == secondaryTag;
26+
}) && node.id !== post.id
27+
);
28+
})
29+
.value();
30+
31+
relatedPosts = _.map(
32+
_.take(primaryRelatedArticles, relatedPostsLimit),
33+
(article, key) => {
34+
return article.node;
35+
}
36+
);
37+
};
38+
39+
findRelatedArticles();
40+
41+
const renderPosts = (relatedPosts) => {
42+
return !_.isEmpty(relatedPosts) ? (
43+
<Grid
44+
inverted
45+
container
46+
stackable
47+
columns="equal"
48+
divided
49+
className="related-articles-grid"
50+
>
51+
<Grid.Row textAlign="center">
52+
<Grid.Column>
53+
<strong>You might also enjoy</strong>
54+
</Grid.Column>
55+
</Grid.Row>
56+
<Grid.Row textAlign="center">
57+
{_.map(relatedPosts, (post) => {
58+
return (
59+
<Grid.Column>
60+
<PostCard
61+
key={post.id}
62+
post={post}
63+
views={null}
64+
/>
65+
</Grid.Column>
66+
);
67+
})}
68+
</Grid.Row>
69+
</Grid>
70+
) : <></>
71+
}
72+
73+
return renderPosts(relatedPosts);
74+
}
75+
76+
export default RelatedPosts;

src/components/common/ShareButtons.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from "react";
2+
import {
3+
TwitterShareButton,
4+
TwitterIcon,
5+
RedditShareButton,
6+
RedditIcon,
7+
EmailShareButton,
8+
EmailIcon,
9+
LinkedinShareButton,
10+
LinkedinIcon,
11+
} from "react-share";
12+
13+
const ShareButtons = ({postShareUrl, postShareTitle}) => {
14+
15+
const twitterHandle = "@javaadpatel";
16+
const siteUrl = "https://javaadpatel.com";
17+
18+
return (
19+
<div
20+
style={{
21+
float: "right",
22+
paddingBottom: "1em",
23+
fontFamily: "Georgia, Times, serif",
24+
}}
25+
>
26+
Share this post on {" "}
27+
<TwitterShareButton
28+
url={postShareUrl}
29+
title={postShareTitle}
30+
related={[twitterHandle]}
31+
>
32+
<TwitterIcon size={32} round />
33+
</TwitterShareButton>
34+
<LinkedinShareButton
35+
url={postShareUrl}
36+
title={postShareTitle}
37+
source={siteUrl}
38+
>
39+
<LinkedinIcon size={32} round />
40+
</LinkedinShareButton>
41+
<RedditShareButton
42+
url={postShareUrl}
43+
title={postShareTitle}
44+
windowWidth={660}
45+
windowHeight={460}
46+
>
47+
<RedditIcon size={32} round />
48+
</RedditShareButton>
49+
<EmailShareButton
50+
url={postShareUrl}
51+
subject={postShareTitle}
52+
body="body"
53+
>
54+
<EmailIcon size={32} round />
55+
</EmailShareButton>
56+
</div>
57+
)
58+
}
59+
60+
export default ShareButtons;

src/components/common/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ export { default as SubscribeForm } from "./SubscribeForm";
66
export { default as ScrollArrow } from "./ScrollArrow";
77
export { default as Header } from "./Header/Header";
88
export { default as Footer } from "./Footer/Footer";
9+
export {default as ShareButtons} from "./ShareButtons";
10+
export {default as RelatedPosts} from "./RelatedPosts";

0 commit comments

Comments
 (0)