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 = ` {{ head_title|default('UMass Amherst') }} ${headHtml} {{ page_top }} {{ page }} {{ page_bottom }} `; 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.');