Skip to content

Commit 9973d0b

Browse files
author
Alex Patterson
committed
update dot env for sanity post updates
1 parent 5dcbc7c commit 9973d0b

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

‎scripts/sanity-update-posts.js‎

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎scripts/sanity-update-posts.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Run using
3+
* npx dotenvx run -f .env.local -- npx tsx ./scripts/sanity-update-posts.ts
4+
*/
5+
6+
import { createClient } from "@sanity/client";
7+
import 'dotenv/config'
8+
9+
export const client = createClient({
10+
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
11+
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
12+
useCdn: false,
13+
token: process.env.SANITY_API_WRITE_TOKEN,
14+
});
15+
const updatePosts = async () => {
16+
const posts = await client.fetch(`*[_type in ["author", "course", "guest", "page", "podcast","post", "sponsor"]]`);
17+
for (const post of posts) {
18+
console.log(`Updating ${post.title}`)
19+
20+
await client.patch(post._id).set({ _updatedAt: new Date().toISOString() }).commit()
21+
}
22+
};
23+
updatePosts();

0 commit comments

Comments
 (0)