mirror of https://github.com/kremalicious/blog.git
32 lines
624 B
TypeScript
32 lines
624 B
TypeScript
import React from 'react'
|
|
import styles from './PostLead.module.scss'
|
|
|
|
// Extract lead paragraph from content
|
|
// Grab everything before more tag, or just first paragraph
|
|
const PostLead = ({
|
|
post,
|
|
index
|
|
}: {
|
|
post: { html: string }
|
|
index?: boolean
|
|
}) => {
|
|
let lead
|
|
const content = post.html
|
|
const separator = '<!-- more -->'
|
|
|
|
if (content.includes(separator)) {
|
|
lead = content.split(separator)[0]
|
|
} else {
|
|
lead = content.split('\n')[0]
|
|
}
|
|
|
|
return (
|
|
<div
|
|
className={index ? styles.index : styles.lead}
|
|
dangerouslySetInnerHTML={{ __html: lead }}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export default PostLead
|