make it right

This commit is contained in:
Adam 2023-02-04 21:34:15 -05:00
parent 35c82a253d
commit 9bfdd2f9ca
2 changed files with 30 additions and 14 deletions

View file

@ -1,15 +1,21 @@
import { Component } from 'react' import { Component } from 'react'
import BlogPost from './BlogPost.tsx' import BlogPost from './BlogPost.js'
class Blog extends Component { interface IBlogProps {
constructor(props) { }
interface IBlogState {
}
class Blog extends Component<IBlogProps, IBlogState> {
constructor(props: IBlogProps) {
super(props) super(props)
} }
render() { render() {
return ( return (
<> <>
<BlogPost post='blog/20220506-change.html' /> <BlogPost postURL='blog/20220506-change.html' />
<BlogPost post='blog/000000000-swim.html' /> <BlogPost postURL='blog/000000000-swim.html' />
</> </>
) )
} }

View file

@ -1,28 +1,38 @@
import { Component } from 'react' import { Component } from 'react'
import ReactMarkdown from 'react-markdown' import ReactMarkdown from 'react-markdown'
import rehypeRaw from 'rehype-raw' import rehypeRaw from 'rehype-raw'
class BlogPost extends Component { interface IBlogPostProps {
constructor(props) { postURL: string;
}
interface IBlogPostState {
postHTML: string;
}
class BlogPost extends Component<IBlogPostProps, IBlogPostState> {
constructor(props: IBlogPostProps) {
super(props) super(props)
this.state = { this.state = {
'post': '' 'postHTML': ''
} }
} }
async getPost(post) { async getPost(post: string) {
return fetch(post) return fetch(post)
.then((res) => res.text()) .then((res) => res.text())
} }
componentDidMount(props) { componentDidMount() {
this.getPost(this.props.post) this.getPost(this.props.postURL)
.then((text) => this.setState({ post: text })) .then((text) => this.setState({ postHTML: text }))
} }
render() { render() {
return ( return (
<div className="content-container"> <div className="content-container">
<div className="content"> <div className="content">
<ReactMarkdown rehypePlugins={[rehypeRaw]} children={this.state.post} /> <ReactMarkdown
rehypePlugins={[rehypeRaw]}
children={this.state.postHTML} />
</div> </div>
</div> </div>
) )