1
0
Fork 0
blog/src/components/templates/Post/Lead.tsx

33 lines
684 B
TypeScript
Raw Normal View History

2020-05-22 14:38:19 +02:00
import React, { ReactElement } from 'react'
2019-12-14 15:46:43 +01:00
import styles from './Lead.module.scss'
import { Post } from '../../../@types/Post'
2018-07-22 04:27:37 +02:00
// Extract lead paragraph from content
// Grab everything before more tag, or just first paragraph
2020-05-22 14:38:19 +02:00
const PostLead = ({
post,
index
}: {
post: Post
index?: boolean
}): ReactElement => {
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