1
1
/* eslint-disable global-require */
2
2
/* eslint-disable import/no-dynamic-require */
3
- import PropTypes from 'prop-types ' ;
3
+ import { GetStaticProps } from 'next ' ;
4
4
import matter from 'gray-matter' ;
5
5
import ReactMarkdown from 'react-markdown' ;
6
6
import remarkGfm from 'remark-gfm' ;
@@ -14,6 +14,7 @@ import isExternalImage from 'helpers/is-external-image';
14
14
import generateArticleStructuredData from 'helpers/generate-article-structured-data' ;
15
15
import generateFaqStructuredData from 'helpers/generate-faq-structured-data' ;
16
16
import parsePosts from '../../helpers/parse-posts' ;
17
+ import { Post , StaticPropsContextParams , BlogPostProps } from 'interfaces' ;
17
18
18
19
export default function BlogPost ( {
19
20
siteTitle,
@@ -22,7 +23,7 @@ export default function BlogPost({
22
23
date,
23
24
slug,
24
25
image
25
- } ) {
26
+ } : BlogPostProps ) {
26
27
// eslint-disable-next-line react/jsx-no-useless-fragment
27
28
if ( ! frontmatter ) return < > </ > ;
28
29
@@ -105,23 +106,15 @@ export default function BlogPost({
105
106
) ;
106
107
}
107
108
108
- BlogPost . propTypes = {
109
- siteTitle : PropTypes . string ,
110
- frontmatter : PropTypes . object ,
111
- markdownBody : PropTypes . string ,
112
- date : PropTypes . array ,
113
- slug : PropTypes . string ,
114
- image : PropTypes . string
115
- } ;
109
+ export const getStaticProps : GetStaticProps = async context => {
110
+ const { postname = '' } = context . params as StaticPropsContextParams ;
116
111
117
- export async function getStaticProps ( { ...ctx } ) {
118
- const { postname } = ctx . params ;
119
- const slug = postname
112
+ const slug = `${ postname } `
120
113
. replace ( / ( \d { 1 , 4 } ( [ . \- - ] ) \d { 1 , 2 } ( [ . \- - ] ) \d { 1 , 4 } ) / g, '' )
121
114
. substring ( 1 ) ;
122
115
const content = await import ( `../../posts/${ slug } .md` ) ;
123
116
const config = await import ( '../../siteconfig.json' ) ;
124
- const date = postname . match ( / ( \d { 1 , 4 } ( [ . \- - ] ) \d { 1 , 2 } ( [ . \- - ] ) \d { 1 , 4 } ) / g) ;
117
+ const date = ` ${ postname } ` . match ( / ( \d { 1 , 4 } ( [ . \- - ] ) \d { 1 , 2 } ( [ . \- - ] ) \d { 1 , 4 } ) / g) ;
125
118
const data = matter ( content . default ) ;
126
119
let image = data . data . cover_image || null ;
127
120
@@ -141,16 +134,16 @@ export async function getStaticProps({ ...ctx }) {
141
134
image
142
135
}
143
136
} ;
144
- }
137
+ } ;
145
138
146
139
export async function getStaticPaths ( ) {
147
140
const allPosts = parsePosts (
148
141
require . context ( '../../posts' , true , / \. \/ .* \. m d $ / )
149
142
)
150
- . filter ( post => post . oldBlog )
151
- . map ( post => post . date . concat ( '-' , post . slug ) ) ;
143
+ . filter ( ( post : Post ) => post . oldBlog )
144
+ . map ( ( post : Post ) => post . date . concat ( '-' , post . slug ) ) ;
152
145
153
- const paths = allPosts . map ( slug => `/post/${ slug } ` ) ;
146
+ const paths = allPosts . map ( ( slug : string ) => `/post/${ slug } ` ) ;
154
147
155
148
return {
156
149
paths,
0 commit comments