74 lines
2.6 KiB
JavaScript
74 lines
2.6 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const cheerio = require('cheerio');
|
|
|
|
const themeDir = path.join(__dirname, 'sis_theme');
|
|
const templatesDir = path.join(themeDir, 'templates');
|
|
const includesDir = path.join(templatesDir, 'includes');
|
|
const layoutDir = path.join(templatesDir, 'layout');
|
|
|
|
const htmlPath = path.join(__dirname, 'UMASS_sample', 'UMass Amherst _ UMass Amherst.html');
|
|
const htmlContent = fs.readFileSync(htmlPath, 'utf8');
|
|
|
|
const $ = cheerio.load(htmlContent);
|
|
|
|
// 1. Extract Head
|
|
let headHtml = $('head').html();
|
|
headHtml = headHtml.replace(/\.\/[^"]+_files\//g, "{{ directory }}/images/umass/");
|
|
|
|
// Wrap in html.html.twig structure
|
|
const htmlTwig = `<!DOCTYPE html>
|
|
<html{{ html_attributes }}>
|
|
<head>
|
|
<head-placeholder token="{{ placeholder_token|raw }}">
|
|
<title>{{ head_title|default('UMass Amherst') }}</title>
|
|
<css-placeholder token="{{ placeholder_token|raw }}">
|
|
<js-placeholder token="{{ placeholder_token|raw }}">
|
|
${headHtml}
|
|
</head>
|
|
<body{{ attributes }} class="umass-platform-homepage path-frontpage page-node-type-homepage homepage transparent-header">
|
|
{{ page_top }}
|
|
{{ page }}
|
|
{{ page_bottom }}
|
|
<js-bottom-placeholder token="{{ placeholder_token|raw }}">
|
|
</body>
|
|
</html>`;
|
|
|
|
fs.writeFileSync(path.join(layoutDir, 'html.html.twig'), htmlTwig);
|
|
|
|
// 2. Extract Header
|
|
let headerHtml = '';
|
|
if ($('header').length > 0) {
|
|
headerHtml = $.html($('header').first());
|
|
} else if ($('#l--main-header').length > 0) {
|
|
headerHtml = $.html($('#l--main-header').first());
|
|
}
|
|
if (headerHtml) {
|
|
headerHtml = headerHtml.replace(/\.\/[^"]+_files\//g, "{{ directory }}/images/umass/");
|
|
fs.writeFileSync(path.join(includesDir, 'header.html.twig'), headerHtml);
|
|
}
|
|
|
|
// 3. Extract Footer
|
|
let footerHtml = '';
|
|
if ($('footer').length > 0) {
|
|
footerHtml = $.html($('footer').first());
|
|
} else if ($('.footer').length > 0) {
|
|
footerHtml = $.html($('.footer').first());
|
|
} else if ($('#l--main-footer').length > 0) {
|
|
footerHtml = $.html($('#l--main-footer').first());
|
|
} else if ($('#footer').length > 0) {
|
|
footerHtml = $.html($('#footer').first());
|
|
} else {
|
|
// maybe there is a div with id main-footer
|
|
const possibleFooter = $('[data-component-id="umass_base:site-footer"]');
|
|
if (possibleFooter.length > 0) {
|
|
footerHtml = $.html(possibleFooter);
|
|
}
|
|
}
|
|
if (footerHtml) {
|
|
footerHtml = footerHtml.replace(/\.\/[^"]+_files\//g, "{{ directory }}/images/umass/");
|
|
fs.writeFileSync(path.join(includesDir, 'footer.html.twig'), footerHtml);
|
|
}
|
|
|
|
console.log('✅ Reverted Head, Header and Footer to UMass original successfully.');
|