2018-07-22 04:27:37 +02:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import styles from './PostLead.module.scss'
|
|
|
|
|
|
|
|
// Extract lead paragraph from content
|
|
|
|
// Grab everything before more tag, or just first paragraph
|
2018-09-27 21:33:25 +02:00
|
|
|
const PostLead = ({ post, index }) => {
|
2018-07-22 04:27:37 +02:00
|
|
|
let lead
|
|
|
|
const content = post.html
|
|
|
|
const separator = '<!-- more -->'
|
|
|
|
|
|
|
|
if (post.frontmatter.type === 'post') {
|
|
|
|
if (content.includes(separator)) {
|
|
|
|
lead = content.split(separator)[0]
|
|
|
|
} else {
|
|
|
|
lead = content.split('\n')[0]
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2018-09-27 21:33:25 +02:00
|
|
|
<div
|
|
|
|
className={index ? styles.index : styles.lead}
|
|
|
|
dangerouslySetInnerHTML={{ __html: lead }}
|
|
|
|
/>
|
2018-07-22 04:27:37 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
PostLead.propTypes = {
|
2018-09-27 21:33:25 +02:00
|
|
|
post: PropTypes.object,
|
|
|
|
index: PropTypes.bool
|
2018-07-22 04:27:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PostLead
|