-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require("dotenv").config({ path: `.env.development` }); | ||
const env = process.env; | ||
|
||
process.on("unhandledRejection", console.dir); | ||
|
||
const contentful = require("contentful-management"); | ||
const client = contentful.createClient({ | ||
accessToken: env.CONTENTFUL_PERSONAL_ACCESS_TOKEN, | ||
}); | ||
|
||
const convertNoUtcOffset = async (entries) => { | ||
for (let item of entries.items) { | ||
try { | ||
if (item.fields.publishDate.ja.split('+')[1]) { | ||
const convertedTime = await item.fields.publishDate.ja.split('+')[0]; | ||
console.log(`converted: ${item.fields.publishDate.ja} --> ${convertedTime}`); | ||
item.fields.publishDate.ja = convertedTime; | ||
const updatedEntry = await item.update(); | ||
await updatedEntry.publish(); | ||
} | ||
} catch (err) { | ||
console.log('skipped for some reason'); | ||
} | ||
}; | ||
} | ||
|
||
const checkPublishDate = (entries) => { | ||
for (let item of entries.items) { | ||
try { | ||
if (item.fields.publishDate.ja.split('+')[1]) { | ||
console.log(`warning: ${item.fields.title.ja}`); | ||
console.log(item.fields.publishDate.ja); | ||
} else { | ||
console.log(item.fields.publishDate.ja) | ||
} | ||
} catch (err) { | ||
throw err; | ||
} | ||
} | ||
} | ||
|
||
(async () => { | ||
const space = await client.getSpace(env.CONTENTFUL_SPACE_ID); | ||
const environment = await space.getEnvironment("master"); | ||
const entries = await environment.getEntries({ | ||
content_type: "blogPost", | ||
limit: 200, | ||
order: "sys.createdAt", | ||
}); | ||
convertNoUtcOffset(entries); | ||
checkPublishDate(entries); | ||
})(); |