1
0
Fork 0
blog/src/components/Post/PostLead.tsx

32 lines
624 B
TypeScript
Raw Normal View History

2018-07-22 04:27:37 +02:00
import React from 'react'
import styles from './PostLead.module.scss'
// Extract lead paragraph from content
// Grab everything before more tag, or just first paragraph
2019-10-02 13:35:50 +02:00
const PostLead = ({
post,
index
}: {
post: { html: string }
index?: boolean
}) => {
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
)
}
export default PostLead