Skip to content

Commit 55ed8d7

Browse files
committed
f
1 parent f050906 commit 55ed8d7

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

web/app/routes/$userName+/page+/$slug+/edit/utils/processHtmlContent.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ describe("processHtmlContent", () => {
248248
<p>Line B</p>
249249
<p>Line C</p>
250250
`;
251-
251+
252252
const user = await prisma.user.upsert({
253253
where: { id: 13 },
254254
create: {
@@ -260,46 +260,46 @@ describe("processHtmlContent", () => {
260260
},
261261
update: {},
262262
});
263-
263+
264264
// 初回処理
265265
await processHtmlContent(title, htmlInput, pageSlug, user.id, "en", true);
266-
266+
267267
const dbPage1 = await prisma.page.findUnique({
268268
where: { slug: pageSlug },
269269
include: { sourceTexts: true },
270270
});
271271
expect(dbPage1).not.toBeNull();
272272
if (!dbPage1) return;
273-
273+
274274
// 初回処理時のIDを記憶
275275
const originalTextIdMap = new Map<string, number>();
276276
for (const st of dbPage1.sourceTexts) {
277277
originalTextIdMap.set(st.text, st.id);
278278
}
279279
expect(originalTextIdMap.size).toBeGreaterThanOrEqual(3);
280-
280+
281281
// 変更なしで再度同一HTMLを処理
282282
await processHtmlContent(title, htmlInput, pageSlug, user.id, "en", true);
283-
283+
284284
const dbPage2 = await prisma.page.findUnique({
285285
where: { slug: pageSlug },
286286
include: { sourceTexts: true },
287287
});
288288
expect(dbPage2).not.toBeNull();
289289
if (!dbPage2) return;
290-
290+
291291
// 再処理後のIDマッピングを取得
292292
const afterTextIdMap = new Map<string, number>();
293293
for (const st of dbPage2.sourceTexts) {
294294
afterTextIdMap.set(st.text, st.id);
295295
}
296-
296+
297297
// 全てのテキストでIDが変わっていないことを確認
298298
for (const [text, originalId] of originalTextIdMap.entries()) {
299299
console.log(text, originalId);
300300
expect(afterTextIdMap.get(text)).toBe(originalId);
301301
}
302-
302+
303303
// source_textsの数が増減していないこと(無駄な消去がないこと)
304304
expect(dbPage2.sourceTexts.length).toBe(dbPage1.sourceTexts.length);
305305
});

web/app/routes/$userName+/page+/$slug+/edit/utils/processHtmlContent.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ function extractTextFromHAST(node: Parent): string {
4242
});
4343
return result;
4444
}
45-
export function rehypeAddDataId(pageId: number, title: string): Plugin<[], Root> {
45+
export function rehypeAddDataId(
46+
pageId: number,
47+
title: string,
48+
): Plugin<[], Root> {
4649
return function attacher() {
4750
return async (tree: Root, file: VFile) => {
4851
const textOccurrenceMap = new Map<string, number>();
@@ -74,13 +77,12 @@ export function rehypeAddDataId(pageId: number, title: string): Plugin<[], Root>
7477
}
7578
});
7679

77-
7880
const allTextsForDb = blocks.map((block, index) => ({
7981
text: block.text,
8082
textAndOccurrenceHash: block.textAndOccurrenceHash,
8183
number: index + 1,
82-
}))
83-
84+
}));
85+
8486
allTextsForDb.push({
8587
text: title,
8688
textAndOccurrenceHash: generateHashForText(title, 0),

0 commit comments

Comments
 (0)