forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-post.js
35 lines (29 loc) · 875 Bytes
/
update-post.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require("dotenv").config({
path: `.env.${process.env.NODE_ENV || 'development'}`,
})
const Cosmic = require('cosmicjs')
const bucket = Cosmic().bucket({
slug: process.env.BENCHMARK_COSMIC_BUCKET,
read_key: process.env.BENCHMARK_COSMIC_READ_KEY,
write_key: process.env.BENCHMARK_COSMIC_WRITE_KEY
})
const DATASET = (Number(process.env.BENCHMARK_COSMIC_DATASET) || 512)
const randomDoc = Math.floor(Math.random() * DATASET)
console.log(`Getting article number ${randomDoc}`)
const run = async () => {
const { objects } = await bucket.getObjects({
skip: randomDoc,
limit: 1,
props: 'slug,title'
})
if (objects && objects.length > 0) {
const { slug, title } = objects[0];
await bucket.editObject({
slug,
title: `${title}!`,
trigger_webhook: true
})
console.log(`Updated article number ${randomDoc}`)
}
}
run();