File tree 1 file changed +4
-11
lines changed
1 file changed +4
-11
lines changed Original file line number Diff line number Diff line change 1
- const IS_PROD = process . env . NODE_ENV === 'production'
2
- const BASE_URL = IS_PROD ? 'https://reactjs.wiki/' : 'http://localhost:3000'
3
-
4
- let posts = [ ]
1
+ import posts from '../public/content/index.json'
5
2
6
3
export const readIndex = async ( ) => {
7
- if ( posts . length ) return posts
8
-
9
- const res = await fetch ( `${ BASE_URL } /content/index.json` )
10
- posts = await res . json ( )
11
-
12
4
return posts
13
5
}
14
6
15
7
export const fetchPost = async ( slug ) => {
16
8
const posts = await readIndex ( )
17
9
18
- const res = await fetch ( `${ BASE_URL } /content/${ slug } .json` )
19
- const { content, level, title, id } = await res . json ( )
10
+ const post = await import ( `../public/content/${ slug } .json` )
11
+ console . log ( post )
12
+ const { content, level, title, id } = post
20
13
21
14
const currentIndex = posts . findIndex ( post => post . id === id )
22
15
const prev = currentIndex > 0 ? posts [ currentIndex - 1 ] : null
You can’t perform that action at this time.
0 commit comments