Files
sisvietnamvn_01/sisvietnamvn/apply_layout.js
T
2026-06-01 16:45:26 +07:00

50 lines
2.2 KiB
JavaScript

const fs = require('fs');
const aboutPath = 'd:\\website_sisvietnam_moi\\website_sisvietnam.vn\\sisvietnamvn\\src\\main\\resources\\templates\\about.html';
const layoutPath = 'd:\\website_sisvietnam_moi\\website_sisvietnam.vn\\sisvietnamvn\\src\\main\\resources\\templates\\fragments\\layout.html';
const footerPath = 'd:\\website_sisvietnam_moi\\website_sisvietnam.vn\\sisvietnamvn\\src\\main\\resources\\templates\\fragments\\footer.html';
let aboutHtml = fs.readFileSync(aboutPath, 'utf8');
let layoutHtml = fs.readFileSync(layoutPath, 'utf8');
// 1. Extract Head
const headMatch = aboutHtml.match(/<head>([\s\S]*?)<\/head>/i);
const headContent = headMatch ? headMatch[1] : '';
// 2. Extract Main Content (everything between </header> and <footer ...>)
const mainMatch = aboutHtml.match(/<\/header>([\s\S]*?)<footer/i);
let mainContent = mainMatch ? mainMatch[1] : '';
// The match stops at `<footer`, so it doesn't include it.
// 3. Extract Footer (from <footer id="l--main-footer"... to </footer>)
const footerMatch = aboutHtml.match(/(<footer id="l--main-footer"[\s\S]*?<\/footer>)/i);
let footerContent = footerMatch ? footerMatch[1] : '';
// Create footer.html with fragment
footerContent = footerContent.replace('<footer id="l--main-footer" class="site-footer">', '<footer id="l--main-footer" class="site-footer" th:fragment="footer">');
fs.writeFileSync(footerPath, footerContent, 'utf8');
// Update layout.html to include footer
layoutHtml = layoutHtml.replace(/<footer>[\s\S]*?<\/footer>/i, '<footer th:replace="~{fragments/footer :: footer}"></footer>');
fs.writeFileSync(layoutPath, layoutHtml, 'utf8');
// Construct new about.html
const newAboutHtml = `<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{fragments/layout}">
<head>
<th:block layout:fragment="head">
${headContent}
</th:block>
</head>
<body>
<div layout:fragment="content" class="dialog-off-canvas-main-canvas umass-platform-homepage path-node page-node-type-landing-page landing-page transparent-header" data-off-canvas-main-canvas="">
${mainContent}
</div>
</body>
</html>
`;
fs.writeFileSync(aboutPath, newAboutHtml, 'utf8');
console.log("Transformation completed successfully!");