const fs = require('fs'); let fileContent = fs.readFileSync('src/main/resources/templates/dao-tao-detail.html', 'utf8'); // 1. Remove the hardcoded tabs from the HTML layout fileContent = fileContent.replace( `
`, `
` ); // 2. Add the trainingCourseInfo block renderer to blocksToHtml function const newBlockHandler = ` case "trainingCourseInfo": var d = block.data; var introHtml = d.introText ? d.introText.split('\\n').filter(p=>p.trim()!=='').map(p => '

'+p+'

').join('') : ''; var hoSoHtml = d.documents ? d.documents.split('\\n').filter(p=>p.trim()!=='').map(p => '
  • '+p+'
  • ').join('') : ''; if(hoSoHtml) hoSoHtml = ''; var luuYHtml = d.notes ? d.notes.split('\\n').filter(p=>p.trim()!=='').map(p => '
  • '+p+'
  • ').join('') : ''; if(luuYHtml) luuYHtml = ''; var locationHtml = d.location ? d.location.split('\\n').filter(p=>p.trim()!=='').map(p => '

    '+p+'

    ').join('') : ''; // Generating the complete Tabs HTML html += '
    '; html += '
    '; html += '
    '; html += ' '; html += ' '; html += '
    '; html += '
    '; // Tab 1 html += '
    '; if(introHtml) html += introHtml; if(d.bannerText) { html += '
    ' + d.bannerText + '
    '; } html += '
    '; html += ''; if(d.time) html += ''; if(d.audience) html += ''; var thongTinLopHoc = ''; if(d.fileChieuSinh) thongTinLopHoc += 'Thông báo chiêu sinh file đính kèm'; if(d.filePhieuDangKy) thongTinLopHoc += (thongTinLopHoc?' và ':'') + 'phiếu đăng ký file đính kèm'; if(thongTinLopHoc) html += ''; if(d.quantity) html += ''; if(hoSoHtml) html += ''; if(luuYHtml) html += ''; html += '
    Thời gian:' + d.time.replace(/\\n/g, '
    ') + '
    Đối tượng đăng ký:' + d.audience.replace(/\\n/g, '
    ') + '
    Thông tin lớp học

    ' + thongTinLopHoc + '

    Số lượng:' + d.quantity + '
    Hồ sơ đăng ký tham dự:' + hoSoHtml + '
    Lưu ý:' + luuYHtml + '
    '; html += '
    '; // Tab 2 html += '
    '; html += '
    '; html += ''; if(d.tuitionFee) html += ''; if(locationHtml) html += ''; var bankHtml = ''; if(d.bankAccountName) bankHtml += '
  • Tên tài khoản: ' + d.bankAccountName + '
  • '; if(d.bankAccountNumber) bankHtml += '
  • Số tài khoản: ' + d.bankAccountNumber + '
  • '; if(d.bankName) bankHtml += '
  • Tên ngân hàng: ' + d.bankName + '
  • '; if(d.transferContent) bankHtml += '
  • Nội dung: ' + d.transferContent + '
  • '; if(bankHtml) { html += ''; html += ''; } html += '
    Học phí:' + d.tuitionFee + '
    Địa điểm nhận hồ sơ và học phí:' + locationHtml + '
    Hình thức nộp học phí: 
    Chuyển khoản:
      ' + bankHtml + '
    '; html += '
    '; html += '
    '; break; case "raw":`; fileContent = fileContent.replace('case "raw":', newBlockHandler); // 3. Remove the complicated tabSplit logic and leave just normal parsing const tabSplitLogicRegex = /var isJsonSplit = false;[\s\S]*?if \(!isJsonSplit\) \{[\s\S]*?if \(contentText.indexOf\(''\) !== -1\) \{[\s\S]*?\} else \{[\s\S]*?parseEditorContent\(contentText, 'postContentParsed'\);[\s\S]*?parseEditorContent\(excerptText, 'postGeneralInfoParsed'\);[\s\S]*?\}[\s\S]*?\}/; fileContent = fileContent.replace(tabSplitLogicRegex, "parseEditorContent(contentText, 'postContentParsed');"); // 4. Add the switchTrainingTab function script const scriptToAppend = ` `; if (!fileContent.includes('function switchTrainingTab')) { fileContent = fileContent.replace('', scriptToAppend + '\n '); } fs.writeFileSync('src/main/resources/templates/dao-tao-detail.html', fileContent);