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

34 lines
882 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 Changelog from '../../atoms/Changelog'
import { Post } from '../../../@types/Post'
import PostToc from './Toc'
2018-07-22 04:27:37 +02:00
// Remove lead paragraph from content
2020-05-22 14:38:19 +02:00
const PostContent = ({ post }: { post: Post }): ReactElement => {
2018-07-22 04:27:37 +02:00
const separator = '<!-- more -->'
2018-11-21 23:39:09 +01:00
const changelog = post.frontmatter.changelog
2018-07-22 04:27:37 +02:00
2018-11-21 23:39:09 +01:00
let content = post.html
2018-07-22 04:27:37 +02:00
2021-02-28 04:50:05 +01:00
if (post.fields.type === 'article') {
2018-07-22 04:27:37 +02:00
if (content.includes(separator)) {
content = content.split(separator)[1]
} else {
const lead = content.split('\n')[0]
content = content.replace(lead, '')
}
}
2018-11-21 23:39:09 +01:00
return (
2019-10-02 13:35:50 +02:00
<>
2019-11-08 20:47:23 +01:00
{post.frontmatter.toc && (
<PostToc tableOfContents={post.tableOfContents} />
)}
2018-11-21 23:39:09 +01:00
<div dangerouslySetInnerHTML={{ __html: content }} />
{changelog && <Changelog repo={changelog} />}
2019-10-02 13:35:50 +02:00
</>
2018-11-21 23:39:09 +01:00
)
2018-07-22 04:27:37 +02:00
}
export default PostContent