Skip to content

Commit bb8d939

Browse files
committed
修复YAML生成函数,确保所有字段都能被正确保留
1 parent ec6b9fb commit bb8d939

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/components/ChallengeContributePage/handleImportYaml.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,17 @@ export function updateChallengeInCollection(
306306
updatedLines.push(`${indent} - ${solution}`);
307307
});
308308
}
309+
} else {
310+
// 处理所有其他普通字段
311+
if (typeof fieldValue === 'string' || typeof fieldValue === 'number' || typeof fieldValue === 'boolean') {
312+
updatedLines.push(`${indent} ${fieldName}: ${fieldValue}`);
313+
} else if (fieldValue === null || fieldValue === undefined) {
314+
// 跳过空值
315+
return;
316+
} else {
317+
// 对于复杂对象,使用YAML.stringify
318+
updatedLines.push(`${indent} ${fieldName}: ${YAML.stringify(fieldValue)}`);
319+
}
309320
}
310321
});
311322

0 commit comments

Comments
 (0)