Created
April 27, 2018 09:15
-
-
Save tomsansome/bac869b17a4877817674993df1d67f27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got the same issue. Please tell how to overcome the problem. Thanks