Skip to content

Commit 4019636

Browse files
authored
syncDBスクリプトを追加し、全ページを処理する機能を実装しました。また、package.jsonから不要なスクリプトを削除しました。 (#540)
2 parents f650234 + f67457f commit 4019636

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

web/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"sync-github": "tsx scripts/syncGIthub.ts",
1515
"translate": "tsx scripts/translate.ts",
1616
"test-process-markdown": "vitest run scripts/processMarkdownContent.test.ts",
17-
"sync-db": "tsx scripts/syncDB.ts",
18-
"encrypt-gemini-keys": "tsx scripts/encrypt.ts"
17+
"sync-db": "tsx scripts/syncDB.ts"
1918
},
2019
"prisma": {
2120
"seed": "tsx prisma/seed.ts"

web/scripts/syncDB.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { processPageHtml } from "~/routes/$locale+/user.$handle+/page+/$slug+/edit/utils/processHtmlContent";
2+
import { prisma } from "~/utils/prisma";
3+
4+
// 全ページに対して処理を実行するメイン関数
5+
async function main(): Promise<void> {
6+
// 1. DB から全ページを取得
7+
const pages = await prisma.page.findMany({
8+
include: {
9+
pageSegments: { where: { number: 0 } },
10+
},
11+
});
12+
13+
// 2. 取得したページを順番に処理
14+
for (const page of pages) {
15+
if (!page.pageSegments[0]) {
16+
console.log(
17+
`pageSegments[0] が存在しません。userId=${page.userId}, sourceLocale=${page.sourceLocale}, status=${page.status}`,
18+
);
19+
// スキップする場合は continue を使用
20+
continue;
21+
}
22+
// 例: pageSlug プロパティ名が異なる場合は適宜修正
23+
await processPageHtml(
24+
page.pageSegments[0].text,
25+
page.content,
26+
page.slug,
27+
page.userId,
28+
page.sourceLocale,
29+
page.status,
30+
);
31+
}
32+
33+
console.log("全ページの処理が完了しました。");
34+
}
35+
36+
// スクリプト実行
37+
main().catch((error) => {
38+
console.error("ページ処理中にエラーが発生しました:", error);
39+
process.exit(1);
40+
});

0 commit comments

Comments
 (0)