Skip to content
This repository has been archived by the owner on Jul 3, 2021. It is now read-only.

Commit

Permalink
feat(disqus): add url into disqus config (close #135)
Browse files Browse the repository at this point in the history
  • Loading branch information
hitsuji_no_shippo committed Jan 20, 2020
1 parent 5eb35a0 commit aac121c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
13 changes: 8 additions & 5 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
:!author-email:
:author: {author-name}
:!email: {author-email}
:revnumber: Branch feat/change-disqus v1.0.0. (Base v1.55.1)
:revdate: 2020-01-19T23:20:47+0900
:revremark: Add log that Update prop type from `any` to `string` \
in `Disqus` component
:revnumber: Branch feat/change-disqus v1.1.0. (Base v1.55.1)
:revdate: 2020-01-20T07:37:58+0900
:revremark: Add log that add url into disqus config.
:doctype: article
:description: gatsby-simple-blog-with-asciidoctor Change Log
:title:
Expand Down Expand Up @@ -43,10 +42,14 @@ ifndef::env-github[:icons: font]
:repository-url: {hitsuji-no-shippo-github-profile-url}/gatsby-simple-blog-with-asciidoctor
:issues-url: {repository-url}/issues

== 0.4.0 (2020-01-19)
== 0.4.0 (2020-01-20)

=== Features

==== Add

* url into disqus config. (close link:{issues-url}/135[#135^])

==== Update

* Theme icon positions.
Expand Down
22 changes: 19 additions & 3 deletions src/components/Disqus/Disqus.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import PropTypes from 'prop-types';
import { graphql, useStaticQuery } from 'gatsby';
import { DiscussionEmbed } from 'disqus-react';

function Disqus({ identifier, title, show }) {
function Disqus({ identifier, title, slug, show }) {
const {
site: {
siteMetadata: { disqusShortName },
siteMetadata: { siteUrl, disqusShortName },
},
} = useStaticQuery(
graphql`
query {
site {
siteMetadata {
siteUrl
disqusShortName
}
}
Expand All @@ -25,12 +26,27 @@ function Disqus({ identifier, title, show }) {
return null;
}

return <DiscussionEmbed shortname={disqusShortName} config={{ identifier, title }} />;
const config = {
identifier,
title,
}

if (typeof siteUrl === `string`) {
config.url = `${siteUrl}/${slug}`
}

return (
<DiscussionEmbed
shortname={disqusShortName}
config={config}
/>
);
}

Disqus.propTypes = {
identifier: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
slug: PropTypes.string.isRequired,
show: PropTypes.bool,
};

Expand Down
6 changes: 5 additions & 1 deletion src/templates/blog-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ function BlogPostTemplate({ data, pageContext, location }) {
</li>
</ul>

<Disqus identifier={post.id} show={post.pageAttributes.disqus} title={post.document.title} />
<Disqus
identifier={post.id}
show={post.pageAttributes.disqus}
title={post.document.title}
slug={post.fields.slug} />
</Layout>
);
}
Expand Down

0 comments on commit aac121c

Please sign in to comment.