import React, { useState, useEffect } from "react"; import Layout from "../components/Layout"; import { graphql, Link, navigate } from "gatsby"; import { GhostPostDescription, GhostPost, } from "../models/post-description.model"; import CtaPost from "../components/CtaPost"; import Img from "gatsby-image"; import { MetaData } from "../components/meta"; import Disqus from "../components/disqus"; import FbComments from "../components/fb-comments"; import "../styles/richtext.css"; import "../styles/prism.css"; import facebookShare from "../images/facebook-share.svg"; import twitterShare from "../images/twitter-share.svg"; import linkedInShare from "../images/linkedin-share.svg"; import mailShare from "../images/mail.svg"; import pintrestShare from "../images/pinterest-share.svg"; import whatsappShare from "../images/whatsapp-share.svg"; import CopyLink from "../components/copy-link"; import NextPrevPost from "../components/NextPrevPosts"; import { InView } from "react-intersection-observer"; type PostTemplateProps = { data: { ghostPost: GhostPost; prevPost: GhostPost; nextPost: GhostPost }; location: any; }; const PostTemplate: React.FC = ({ data, location }) => { const { ghostPost, prevPost, nextPost } = data; const [href, sethref] = useState(""); const [origin, setOrigin] = useState(""); const [showComments, setshowComments] = useState(false); const handleCommentsVisibility = (inView) => { if (inView && !showComments) { setshowComments(true); } }; useEffect(() => { if (typeof window !== "undefined") { sethref(window.location.href); setOrigin(window.location.origin); } }, []); const twitterShareUrl = `https://twitter.com/share?text=${ghostPost.title}&url=${href}`; const facebookShareUrl = `https://www.facebook.com/sharer/sharer.php?u=${href}`; const linkedInShareUrl = `https://www.linkedin.com/shareArticle?mini=true&url=${href}&title=${ghostPost.title}`; const mailShareUrl = `mailto:?subject=${ghostPost.title}&body=${href}`; let pinterestShareUrl = `https://www.pinterest.com/pin/create/button/?url=${href}&description=${data.ghostPost.title}`; if (ghostPost.localFeatureImage && ghostPost.localFeatureImage.publicURL) { pinterestShareUrl += `&media=${ origin + ghostPost.localFeatureImage.publicURL }`; } const whatsAppShareUrl = `https://wa.me/?text=${encodeURIComponent( ghostPost.title + "\n" + href )}`; const handleNavigation = (e: any, slug) => { e.stopPropagation(); navigate(slug); }; return (

{ghostPost.published_at} {ghostPost.primary_author && ( <> {ghostPost.primary_author.name} )}

{ghostPost.localFeatureImage && ghostPost.localFeatureImage.childImageSharp && (
)} {ghostPost.localFeatureImage && !ghostPost.localFeatureImage.childImageSharp && (
{ghostPost.title}
)}
{ghostPost.childHtmlRehype && ghostPost.childHtmlRehype.html && (
)}
{ghostPost.tags && ghostPost.tags.length > 0 && (
{ghostPost.tags.map((tag, index) => { return (
handleNavigation(e, `/tag/${tag.slug}`)} className="px-3 py-1 rounded mr-3 text-gray-700 cursor-pointer hover:text-white hover:bg-primary bg-gray-300 mb-4" key={index} > {tag.name}
); })}
)}
Share:
handleCommentsVisibility(inView)} >
{process.env.GATSBY_DISQUS_SHORTNAME && showComments && ( <> {/*
*/}
)} {process.env.GATSBY_FB_APP_ID && showComments && ( <> {/*
*/}
)}
{/* */}
); }; export const postDataQuery = graphql` query($slug: String!, $prev: String, $next: String) { ghostPost(slug: { eq: $slug }) { ...GhostPostDetails } prevPost: ghostPost(slug: { eq: $prev }) { title excerpt slug updated_at(formatString: "DD MMMM YYYY") published_at(formatString: "DD MMMM YYYY") } nextPost: ghostPost(slug: { eq: $next }) { title excerpt slug updated_at(formatString: "DD MMMM YYYY") published_at(formatString: "DD MMMM YYYY") } } `; export default PostTemplate;