2018-07-21 23:30:16 +02:00
|
|
|
import React, { Fragment } from 'react'
|
2018-07-19 16:49:20 +02:00
|
|
|
import PropTypes from 'prop-types'
|
2018-08-08 22:26:42 +02:00
|
|
|
import { Link } from 'gatsby'
|
2018-09-24 22:28:07 +02:00
|
|
|
import { ReactComponent as Forward } from '../../images/forward.svg'
|
2018-07-19 16:49:20 +02:00
|
|
|
import styles from './PostTitle.module.scss'
|
|
|
|
|
2018-08-08 22:26:42 +02:00
|
|
|
const PostTitle = ({ type, slug, linkurl, title }) => {
|
2018-07-21 23:30:16 +02:00
|
|
|
const linkHostname = linkurl ? new URL(linkurl).hostname : null
|
|
|
|
|
|
|
|
return type === 'link' ? (
|
|
|
|
<Fragment>
|
|
|
|
<h1
|
|
|
|
className={[styles.hentry__title, styles.hentry__title__link].join(' ')}
|
|
|
|
>
|
|
|
|
<a href={linkurl} title={`Go to source: ${linkurl}`}>
|
|
|
|
{title} <Forward />
|
|
|
|
</a>
|
|
|
|
</h1>
|
|
|
|
<div className={styles.linkurl}>{linkHostname}</div>
|
|
|
|
</Fragment>
|
2018-08-08 22:26:42 +02:00
|
|
|
) : slug ? (
|
|
|
|
<h1 className={styles.hentry__title}>
|
|
|
|
<Link to={slug}>{title}</Link>
|
|
|
|
</h1>
|
2018-07-19 16:49:20 +02:00
|
|
|
) : (
|
|
|
|
<h1 className={styles.hentry__title}>{title}</h1>
|
|
|
|
)
|
2018-07-21 23:30:16 +02:00
|
|
|
}
|
2018-07-19 16:49:20 +02:00
|
|
|
|
|
|
|
PostTitle.propTypes = {
|
|
|
|
type: PropTypes.string,
|
|
|
|
title: PropTypes.string.isRequired,
|
2018-08-08 22:26:42 +02:00
|
|
|
slug: PropTypes.string,
|
2018-07-19 16:49:20 +02:00
|
|
|
linkurl: PropTypes.string
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PostTitle
|