mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-22 20:55:50 +00:00
add basis of logic
This commit is contained in:
35
scripts/fetchContentfulData.cjs
Normal file
35
scripts/fetchContentfulData.cjs
Normal file
@@ -0,0 +1,35 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const contentful = require('contentful');
|
||||
require('dotenv').config();
|
||||
|
||||
const space = process.env.CONTENTFUL_SPACE_ID;
|
||||
const accessToken = process.env.CONTENTFUL_ACCESS_TOKEN;
|
||||
|
||||
const client = contentful.createClient({
|
||||
space,
|
||||
accessToken,
|
||||
});
|
||||
|
||||
async function fetchData() {
|
||||
try {
|
||||
const entries = await client.getEntries();
|
||||
// Transform the entries into the required JSON format
|
||||
const data = entries.items.map((item) => {
|
||||
return {
|
||||
id: item.sys.id,
|
||||
...item.fields,
|
||||
image: item?.fields.image?.fields?.file?.url || '',
|
||||
};
|
||||
});
|
||||
// Write data to JSON file
|
||||
const filePath = path.join(__dirname, '../static/JSON/contentful-events.json');
|
||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
||||
console.log('Data fetched and written to contentful-events.json');
|
||||
} catch (error) {
|
||||
console.error('Error fetching data from Contentful:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
fetchData();
|
||||
Reference in New Issue
Block a user