143 lines
4.9 KiB
JavaScript
143 lines
4.9 KiB
JavaScript
|
|
import fs from 'fs';
|
||
|
|
import path from 'path';
|
||
|
|
|
||
|
|
// 修改版简历文件夹路径
|
||
|
|
const modifiedResumesPath = './网页未导入数据/能源产业/能源修改版简历';
|
||
|
|
|
||
|
|
// 读取所有修改版简历文件
|
||
|
|
const modifiedFiles = fs.readdirSync(modifiedResumesPath).filter(f => f.endsWith('.md'));
|
||
|
|
|
||
|
|
console.log(`找到 ${modifiedFiles.length} 个修改版简历文件`);
|
||
|
|
|
||
|
|
// 构建修改版简历映射
|
||
|
|
const modifiedResumes = {};
|
||
|
|
const modifiedPositionNames = [];
|
||
|
|
|
||
|
|
modifiedFiles.forEach(file => {
|
||
|
|
// 从文件名获取岗位名称
|
||
|
|
const positionName = file.replace('.md', '');
|
||
|
|
modifiedPositionNames.push(positionName);
|
||
|
|
|
||
|
|
// 读取文件内容
|
||
|
|
const content = fs.readFileSync(path.join(modifiedResumesPath, file), 'utf8');
|
||
|
|
modifiedResumes[positionName] = content;
|
||
|
|
|
||
|
|
console.log(`- ${positionName}`);
|
||
|
|
});
|
||
|
|
|
||
|
|
// 读取resumeInterviewMock.js文件
|
||
|
|
let mockFileContent = fs.readFileSync('./src/mocks/resumeInterviewMock.js', 'utf8');
|
||
|
|
|
||
|
|
// 更新resumeTemplates中的modified内容
|
||
|
|
console.log('\n开始更新简历模板的modified内容...');
|
||
|
|
|
||
|
|
// 处理每个修改版简历
|
||
|
|
Object.keys(modifiedResumes).forEach(positionName => {
|
||
|
|
const modifiedContent = modifiedResumes[positionName];
|
||
|
|
|
||
|
|
// 查找这个岗位在resumeTemplates中的位置
|
||
|
|
const positionPattern = new RegExp(`"position":\\s*"${positionName}"`, 'g');
|
||
|
|
|
||
|
|
let match;
|
||
|
|
let updateCount = 0;
|
||
|
|
|
||
|
|
while ((match = positionPattern.exec(mockFileContent)) !== null) {
|
||
|
|
const startPos = match.index;
|
||
|
|
|
||
|
|
// 找到该岗位对应的content对象
|
||
|
|
const contentStartPattern = /"content":\s*{/;
|
||
|
|
const searchStart = startPos;
|
||
|
|
const searchEnd = startPos + 5000; // 限制搜索范围
|
||
|
|
const searchArea = mockFileContent.substring(searchStart, searchEnd);
|
||
|
|
|
||
|
|
const contentMatch = contentStartPattern.exec(searchArea);
|
||
|
|
if (contentMatch) {
|
||
|
|
const contentPos = searchStart + contentMatch.index;
|
||
|
|
|
||
|
|
// 找到content对象的结束位置
|
||
|
|
let braceCount = 0;
|
||
|
|
let contentEndPos = contentPos + contentMatch[0].length - 1;
|
||
|
|
let inString = false;
|
||
|
|
let escapeNext = false;
|
||
|
|
|
||
|
|
for (let i = contentEndPos; i < mockFileContent.length; i++) {
|
||
|
|
const char = mockFileContent[i];
|
||
|
|
|
||
|
|
if (escapeNext) {
|
||
|
|
escapeNext = false;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (char === '\\') {
|
||
|
|
escapeNext = true;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (char === '"' && !escapeNext) {
|
||
|
|
inString = !inString;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!inString) {
|
||
|
|
if (char === '{') braceCount++;
|
||
|
|
if (char === '}') {
|
||
|
|
braceCount--;
|
||
|
|
if (braceCount === 0) {
|
||
|
|
contentEndPos = i + 1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 提取content对象
|
||
|
|
const contentStr = mockFileContent.substring(contentPos, contentEndPos);
|
||
|
|
|
||
|
|
// 检查是否已有modified字段
|
||
|
|
if (contentStr.includes('"modified":')) {
|
||
|
|
// 替换现有的modified内容
|
||
|
|
const modifiedPattern = /"modified":\s*"[^"]*(?:\\.[^"]*)*"/;
|
||
|
|
const escapedContent = JSON.stringify(modifiedContent);
|
||
|
|
const newModified = `"modified": ${escapedContent}`;
|
||
|
|
|
||
|
|
const newContentStr = contentStr.replace(modifiedPattern, newModified);
|
||
|
|
mockFileContent = mockFileContent.substring(0, contentPos) + newContentStr + mockFileContent.substring(contentEndPos);
|
||
|
|
} else {
|
||
|
|
// 添加modified字段到content对象
|
||
|
|
// 在original字段后添加
|
||
|
|
const originalPattern = /("original":\s*"[^"]*(?:\\.[^"]*)*")/;
|
||
|
|
const escapedContent = JSON.stringify(modifiedContent);
|
||
|
|
|
||
|
|
const newContentStr = contentStr.replace(originalPattern, `$1,\n "modified": ${escapedContent}`);
|
||
|
|
mockFileContent = mockFileContent.substring(0, contentPos) + newContentStr + mockFileContent.substring(contentEndPos);
|
||
|
|
}
|
||
|
|
|
||
|
|
updateCount++;
|
||
|
|
console.log(`✅ 更新了 ${positionName} 的修改版简历`);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (updateCount === 0) {
|
||
|
|
console.log(`⚠️ 未找到 ${positionName} 的岗位模板`);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
// 更新hasRealModifiedVersion函数
|
||
|
|
console.log('\n更新hasRealModifiedVersion函数...');
|
||
|
|
|
||
|
|
const hasModifiedFunctionPattern = /const hasRealModifiedVersion = \(positionTitle\) => \{[\s\S]*?\n \};/;
|
||
|
|
const newFunction = `const hasRealModifiedVersion = (positionTitle) => {
|
||
|
|
const modifiedPositions = [
|
||
|
|
// 能源产业岗位
|
||
|
|
${modifiedPositionNames.map(name => `"${name}"`).join(',\n ')}
|
||
|
|
];
|
||
|
|
return modifiedPositions.includes(positionTitle);
|
||
|
|
};`;
|
||
|
|
|
||
|
|
mockFileContent = mockFileContent.replace(hasModifiedFunctionPattern, newFunction);
|
||
|
|
|
||
|
|
// 写回文件
|
||
|
|
fs.writeFileSync('./src/mocks/resumeInterviewMock.js', mockFileContent);
|
||
|
|
|
||
|
|
console.log('\n✅ 修改版简历更新完成!');
|
||
|
|
console.log(`📝 共更新了 ${modifiedPositionNames.length} 个岗位的修改版简历`);
|
||
|
|
console.log('📋 岗位列表:', modifiedPositionNames.join(', '));
|