Skip to content

Commit

Permalink
syncDBスクリプトを追加し、全ページを処理する機能を実装しました。また、package.jsonから不要なスクリプトを削除しました。 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ttizze authored Jan 28, 2025
2 parents f650234 + f67457f commit 4019636
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
3 changes: 1 addition & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"sync-github": "tsx scripts/syncGIthub.ts",
"translate": "tsx scripts/translate.ts",
"test-process-markdown": "vitest run scripts/processMarkdownContent.test.ts",
"sync-db": "tsx scripts/syncDB.ts",
"encrypt-gemini-keys": "tsx scripts/encrypt.ts"
"sync-db": "tsx scripts/syncDB.ts"
},
"prisma": {
"seed": "tsx prisma/seed.ts"
Expand Down
40 changes: 40 additions & 0 deletions web/scripts/syncDB.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { processPageHtml } from "~/routes/$locale+/user.$handle+/page+/$slug+/edit/utils/processHtmlContent";
import { prisma } from "~/utils/prisma";

// 全ページに対して処理を実行するメイン関数
async function main(): Promise<void> {
// 1. DB から全ページを取得
const pages = await prisma.page.findMany({
include: {
pageSegments: { where: { number: 0 } },
},
});

// 2. 取得したページを順番に処理
for (const page of pages) {
if (!page.pageSegments[0]) {
console.log(
`pageSegments[0] が存在しません。userId=${page.userId}, sourceLocale=${page.sourceLocale}, status=${page.status}`,
);
// スキップする場合は continue を使用
continue;
}
// 例: pageSlug プロパティ名が異なる場合は適宜修正
await processPageHtml(
page.pageSegments[0].text,
page.content,
page.slug,
page.userId,
page.sourceLocale,
page.status,
);
}

console.log("全ページの処理が完了しました。");
}

// スクリプト実行
main().catch((error) => {
console.error("ページ処理中にエラーが発生しました:", error);
process.exit(1);
});

0 comments on commit 4019636

Please sign in to comment.