import React, { useState, useEffect } from "react"; import Layout from "../components/Layout"; import { MetaData } from "../components/meta"; import { graphql, navigate } from "gatsby"; import { GhostPage } from "../models/page-description.model"; import Img from "gatsby-image"; import CtaMini from "../components/CtaMini"; 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"; type IndexPageProps = { data: { ghostPage: GhostPage; }; location: any; }; const PageTemplate: React.FC = ({ data, location }) => { const { ghostPage } = data; const [href, sethref] = useState(""); const [origin, setOrigin] = useState(""); useEffect(() => { if (typeof window !== "undefined") { sethref(window.location.href); setOrigin(window.location.origin); } }, []); const twitterShareUrl = `https://twitter.com/share?text=${ghostPage.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=${ghostPage.title}`; const mailShareUrl = `mailto:?subject=${ghostPage.title}&body=${href}`; let pinterestShareUrl = `https://www.pinterest.com/pin/create/button/?url=${href}&description=${data.ghostPage.title}`; if (ghostPage.localFeatureImage && ghostPage.localFeatureImage.publicURL) { pinterestShareUrl += `&media=${ origin + ghostPage.localFeatureImage.publicURL }`; } const whatsAppShareUrl = `https://wa.me/?text=${encodeURIComponent( ghostPage.title + "\n" + href )}`; const handleNavigation = (e: any, slug) => { e.stopPropagation(); navigate(slug); }; return (

{ghostPage.localFeatureImage && ghostPage.localFeatureImage.childImageSharp && (
{ghostPage.title}
)} {ghostPage.localFeatureImage && !ghostPage.localFeatureImage.childImageSharp && (
{ghostPage.title}
)}
{ghostPage.childHtmlRehype && ghostPage.childHtmlRehype.html && (
)}
Share:
); }; export default PageTemplate; export const PageTemplateQuery = graphql` query($slug: String!) { ghostPage(slug: { eq: $slug }) { ...GhostPageDetails } } `;