Skip to content

Commit 339eacb

Browse files
committed
Lazy loading for FB, Disqus, fix for FB width and minor improvement
1 parent b3d0f29 commit 339eacb

File tree

5 files changed

+48
-15
lines changed

5 files changed

+48
-15
lines changed

example/src/@draftbox-co/gatsby-wordpress-theme-libre/components/disqus.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import React from "react";
22
import { DiscussionEmbed } from "disqus-react";
33

4-
const Disqus = props => {
4+
const Disqus = (props) => {
55
const disqusConfig = {
66
shortname: process.env.GATSBY_DISQUS_SHORTNAME,
77
identifier: props.slug,
8-
title: props.slug
8+
title: props.slug,
99
};
1010

1111
return process.env.GATSBY_DISQUS_SHORTNAME ? (
12-
<DiscussionEmbed {...disqusConfig} />
12+
<DiscussionEmbed
13+
shortname={disqusConfig.shortname}
14+
config={{
15+
identifier: disqusConfig.identifier,
16+
title: disqusConfig.title,
17+
}}
18+
/>
1319
) : (
1420
<></>
1521
);

example/src/@draftbox-co/gatsby-wordpress-theme-libre/components/fb-comments.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FacebookProvider, Comments } from 'react-facebook';
44
const FbComments = props => {
55
return process.env.GATSBY_FB_APP_ID ? (
66
<FacebookProvider appId={process.env.GATSBY_FB_APP_ID}>
7-
<Comments href={props.href}/>
7+
<Comments href={props.href} width={'100%'}/>
88
</FacebookProvider>
99
) : (
1010
<></>

gatsby-wordpress-theme-libre/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@draftbox-co/gatsby-wordpress-theme-libre",
3-
"version": "1.0.39",
3+
"version": "1.0.40",
44
"license": "MIT",
55
"resolutions": {
66
"sharp": "0.23.4"
@@ -67,6 +67,7 @@
6767
"html-to-text": "^5.1.1",
6868
"node-fetch": "^2.6.0",
6969
"react-helmet": "^5.2.1",
70+
"react-intersection-observer": "^8.26.2",
7071
"reading-time": "^1.2.0"
7172
}
7273
}

gatsby-wordpress-theme-libre/src/templates/post.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import twitterShare from "../images/twitter-share.svg";
1212
import linkedInShare from "../images/linkedin.svg";
1313
import mailShare from "../images/mail.svg";
1414
import CopyLink from "../components/copy-link";
15+
import { InView } from "react-intersection-observer";
1516

1617
const Post = ({ data, location }) => {
1718
const [href, sethref] = useState("");
@@ -29,6 +30,14 @@ const Post = ({ data, location }) => {
2930

3031
const mailShareUrl = `mailto:?subject=${data.wordpressPost.plainTitle}&body=${href}`;
3132

33+
const [showComments, setshowComments] = useState(false);
34+
35+
const handleCommentsVisibility = (inView) => {
36+
if (inView && !showComments) {
37+
setshowComments(true);
38+
}
39+
};
40+
3241
return (
3342
<Layout>
3443
<ArticleMeta data={data.wordpressPost} amp={false} location={location} />
@@ -245,7 +254,7 @@ const Post = ({ data, location }) => {
245254
<div className="nav-links">
246255
{data.prev && (
247256
<div className="nav-previous">
248-
<Link to={`/${data.prev.slug}`} rel="prev">
257+
<Link to={`${data.prev.slug}`} rel="prev">
249258
<span className="meta-nav">Previous Post</span>{" "}
250259
<span
251260
dangerouslySetInnerHTML={{
@@ -258,7 +267,7 @@ const Post = ({ data, location }) => {
258267

259268
{data.next && (
260269
<div className="nav-next">
261-
<Link to={`/${data.next.slug}`} rel="next">
270+
<Link to={`${data.next.slug}`} rel="next">
262271
<span className="meta-nav">Next Post</span>{" "}
263272
<span
264273
dangerouslySetInnerHTML={{
@@ -271,9 +280,19 @@ const Post = ({ data, location }) => {
271280
</div>{" "}
272281
</nav>
273282
</article>
283+
<InView
284+
as="div"
285+
onChange={(inView) => handleCommentsVisibility(inView)}
286+
></InView>
287+
<div>
288+
{process.env.GATSBY_DISQUS_SHORTNAME && showComments && (
289+
<Disqus />
290+
)}
291+
{process.env.GATSBY_FB_APP_ID && showComments && (
292+
<FbComments href={href} />
293+
)}
294+
</div>
274295

275-
<Disqus />
276-
<FbComments href={href} />
277296
<SubscribeForm />
278297
</main>
279298
</div>

yarn.lock

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,11 +1738,6 @@
17381738
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-0.0.30.tgz#dc1e40f7af3b9c815013a7860e6252f6352a84df"
17391739
integrity sha512-orGL5LXERPYsLov6CWs3Fh6203+dXzJkR7OnddIr2514Hsecwc8xRpzCapshBbKFImCsvS/mk6+FWiN5LyZJAQ==
17401740

1741-
"@types/eslint-visitor-keys@^1.0.0":
1742-
version "1.0.0"
1743-
resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"
1744-
integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==
1745-
17461741
"@types/events@*":
17471742
version "3.0.0"
17481743
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
@@ -11349,6 +11344,13 @@ react-hot-loader@^4.12.20:
1134911344
shallowequal "^1.1.0"
1135011345
source-map "^0.7.3"
1135111346

11347+
react-intersection-observer@^8.26.2:
11348+
version "8.26.2"
11349+
resolved "https://registry.yarnpkg.com/react-intersection-observer/-/react-intersection-observer-8.26.2.tgz#0562ff0c06b2b10e809190c2fa9b6ded656e6e16"
11350+
integrity sha512-GmSjLNK+oV7kS+BHfrJSaA4wF61ELA33gizKHmN+tk59UT6/aW8kkqvlrFGPwxGoaIzLKS2evfG5fgkw5MIIsg==
11351+
dependencies:
11352+
tiny-invariant "^1.1.0"
11353+
1135211354
react-is@^16.12.0:
1135311355
version "16.13.1"
1135411356
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
@@ -12214,7 +12216,7 @@ shallowequal@^1.0.1, shallowequal@^1.1.0:
1221412216
resolved "https://registry.yarnpkg.com/shallowequal/-/shallowequal-1.1.0.tgz#188d521de95b9087404fd4dcb68b13df0ae4e7f8"
1221512217
integrity sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==
1221612218

12217-
sharp@^0.23.4:
12219+
sharp@0.23.4, sharp@^0.23.4:
1221812220
version "0.23.4"
1221912221
resolved "https://registry.yarnpkg.com/sharp/-/sharp-0.23.4.tgz#ca36067cb6ff7067fa6c77b01651cb9a890f8eb3"
1222012222
integrity sha512-fJMagt6cT0UDy9XCsgyLi0eiwWWhQRxbwGmqQT6sY8Av4s0SVsT/deg8fobBQCTDU5iXRgz0rAeXoE2LBZ8g+Q==
@@ -13217,6 +13219,11 @@ timsort@^0.3.0:
1321713219
resolved "https://registry.yarnpkg.com/timsort/-/timsort-0.3.0.tgz#405411a8e7e6339fe64db9a234de11dc31e02bd4"
1321813220
integrity sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=
1321913221

13222+
tiny-invariant@^1.1.0:
13223+
version "1.1.0"
13224+
resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.1.0.tgz#634c5f8efdc27714b7f386c35e6760991d230875"
13225+
integrity sha512-ytxQvrb1cPc9WBEI/HSeYYoGD0kWnGEOR8RY6KomWLBVhqz0RgTwVO9dLrGz7dC+nN9llyI7OKAgRq8Vq4ZBSw==
13226+
1322013227
tinycolor2@^1.4.1:
1322113228
version "1.4.1"
1322213229
resolved "https://registry.yarnpkg.com/tinycolor2/-/tinycolor2-1.4.1.tgz#f4fad333447bc0b07d4dc8e9209d8f39a8ac77e8"

0 commit comments

Comments
 (0)