1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-10 11:35:10 +02:00
blog/src/components/Post/PostLead.jsx

32 lines
683 B
React
Raw Normal View History

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 -->'
2018-09-27 22:33:01 +02:00
if (content.includes(separator)) {
lead = content.split(separator)[0]
2018-07-22 04:27:37 +02:00
} else {
2018-09-27 22:33:01 +02:00
lead = content.split('\n')[0]
2018-07-22 04:27:37 +02:00
}
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