Skip to content

Commit

Permalink
Update data-fetching.md
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanRJohnston authored Oct 1, 2020
1 parent 5b98300 commit a3f8ed3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/basic-features/data-fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ import fs from 'fs'
import path from 'path'
import util from 'util'

const readFile = util.promisify(fs.readFile)

// posts will be populated at build time by getStaticProps()
function Blog({ posts }) {
return (
Expand All @@ -251,12 +249,15 @@ function Blog({ posts }) {
)
}

const readFile = util.promisify(fs.readFile)
const readdir = util.promisify(fs.readdir)

// This function gets called at build time on server-side.
// It won't be called on client-side, so you can even do
// direct database queries. See the "Technical details" section.
export async function getStaticProps() {
const postsDirectory = path.join(process.cwd(), 'posts')
const filenames = fs.readdirSync(postsDirectory)
const filenames = await readdir(postsDirectory)

const posts = filenames.map(async (filename) => {
const filePath = path.join(postsDirectory, filename)
Expand Down

0 comments on commit a3f8ed3

Please sign in to comment.