import { Link as GatsbyLink } from "gatsby"
import React from "react"

const styles = {
  borderRadius: "0.3em",
  code: {
    textShadow: "none",
  },
}

const Link = props => {
  if (props.hasOwnProperty("to")) {
    return <GatsbyLink css={styles} {...props} />
  }

  return <a css={styles} {...props} />
}

export default Link

import { Link as GatsbyLink } from "gatsby"
import React from "react"

const styles = {
  borderRadius: "0.3em",
  code: {
    textShadow: "none",
  },
}

const Link = ({ to, href, ...props }) => {
  if (to) {
    return <GatsbyLink css={styles} to={to} {...props} />
  }

  if (/^https?:\/\/(?!jbhannah\.net)/.test(href)) {
    props.rel = "noopener"
    props.target = "_blank"
  }

  return <a css={styles} href={href} {...props} />
}

export default Link

Add rel="noopener" target="_blank" to external links
Add rel="noopener" target="_blank" to external links
