Skip to content

Instantly share code, notes, and snippets.

@tomsansome
Created April 27, 2018 09:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomsansome/bac869b17a4877817674993df1d67f27 to your computer and use it in GitHub Desktop.
Save tomsansome/bac869b17a4877817674993df1d67f27 to your computer and use it in GitHub Desktop.
import fs from 'fs'
import path from 'path'
import { createClient } from 'contentful'
const SPACE = process.env.CONTENTFUL_SPACE
const TOKEN = process.env.CONTENTFUL_TOKEN
const client = createClient({
space: SPACE,
accessToken: TOKEN
})
const types = [
'pageHome'
]
export const getcontent = async () => {
console.log('> Starting import...')
for (const type of types) {
console.log('> Getting content for', type)
const entries = await client.getEntries({
content_type: type,
include: 3
})
if (entries.total === 1) {
const { fields } = entries.items[0]
fs.writeFileSync(
path.join(__dirname, '..', 'data', `${type}.json`),
JSON.stringify(fields)
)
console.log('> Content gotten and written for', type)
}
}
return true
}
if (process.argv[2] === 'install') {
getcontent()
}
@anderskitson
Copy link

anderskitson commented Sep 30, 2018

I am following your tutorial on contentful, next js and netlify, I am stuck at npm run postinstall, I get the following error
Couldn't find preset "env" relative to directory Hope you can help, Thanks!

@mac81
Copy link

mac81 commented Oct 2, 2018

Hi. I got it working by installing:

"@babel/cli": "^7.1.2", "@babel/core": "^7.1.2", "@babel/node": "^7.0.0", "@babel/preset-env": "^7.1.0"

and updating .babelrc to

{ "presets": ["@babel/preset-env", "next/babel"] }

@sorknes
Copy link

sorknes commented Jun 26, 2019

Hi. I'm following your tutorial and I can't get the npm run postinstall to work. I had to install the @babel packages as mentioned in the previous post to get past the first error. But now I get this UnhandledPromiseRejectionWarning: Error: Request failed with status code 400. I hope you can help me solve this issue - Thanks!

@taylorhayduk
Copy link

Hi! I found this via this blog post, but the snippet link pointed to the wrong file. Was still able to find this but took some digging. Great post btw!

@VeRTeXR
Copy link

VeRTeXR commented Apr 24, 2020

Great stuff! Tom, I think you're missing some steps on the tutorial about the BackgroundImage.js, if you could elaborate furthur would be perfect.

@andrejaeger
Copy link

Hi Tom, thank you for that nice ramp up. I'm blocked in the tutorial at the component creation. Because, there is a "/config" file which is not defined and also the css classes. Also like VeRTeXR said the BackgroundImage.js isn't there. Could you pleas help us here?
Tanke you, Andre

@craigmilliken
Copy link

craigmilliken commented May 3, 2020

Hi! I found this via this blog post, but the snippet link pointed to the wrong file. Was still able to find this but took some digging. Great post btw!

@taylorhayduk I'm finding myself blocked at the point of running npm run postinstall && next build && next export in this tutorial, and wondering if the wrong file in the snippet is the culprit. Where was the issue and how did you get past it?

@huangh32
Copy link

Hi! I found this via this blog post, but the snippet link pointed to the wrong file. Was still able to find this but took some digging. Great post btw!

@taylorhayduk I'm finding myself blocked at the point of running npm run postinstall && next build && next export in this tutorial, and wondering if the wrong file in the snippet is the culprit. Where was the issue and how did you get past it?

I got the same issue. Please tell how to overcome the problem. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment