Skip to content

Commit

Permalink
Fix template generation for WWW + Community
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 committed Apr 2, 2024
1 parent 30d2e81 commit fdc0e6e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/build/fetchTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const ensureDir = require('./ensureDir');

const fetch = import('node-fetch');

const wwwSelectors = {
content: '[class^="Layout"] > *, [class*=" Layout"] > *',
header: 'nav, [class^="Header"], [class*=" Header"]',
footer: 'footer, [class^="Footer"], [class*=" Footer"], #footer',
};

const baseHtml = async mode => {
// Support a blank template for completely local dev
if (mode === 'blank') {
Expand Down Expand Up @@ -105,17 +111,22 @@ module.exports = async () => {
document.head.insertBefore(charset, document.head.firstChild);
}

let contentAnchor;
if (mode === 'www' || mode === 'community') {
// Remove nav log in + sign up buttons
document.querySelectorAll('nav li').forEach(node => {
document.querySelectorAll('header li').forEach(node => {
if (node.textContent.toLowerCase().includes('log in')) node.remove();
if (node.textContent.toLowerCase().includes('sign up')) node.remove();
});

// Remove www + community content
document.querySelectorAll('div[class^="Layout"] > *').forEach(node => {
if (node.querySelector('nav, [class^="Header"], [class*=" Header"]')) return;
if (node.querySelector('footer, [class^="Footer"], [class*=" Footer"]')) return;
document.querySelectorAll(wwwSelectors.content).forEach(node => {
if (node.querySelector(wwwSelectors.header)) return;
if (node.querySelector(wwwSelectors.footer)) return;

// If this is the first content node on the page,
// we'll inject the content block where it is
if (!contentAnchor) contentAnchor = node.previousElementSibling;
node.remove();
});
}
Expand All @@ -127,7 +138,7 @@ module.exports = async () => {
document.querySelector('body > .app').appendChild(content);
}
if (mode === 'www' || mode === 'community') {
document.querySelector('nav').parentElement.insertAdjacentElement('afterend', content);
contentAnchor.insertAdjacentElement('afterend', content);
}

// Inject the title block
Expand Down

0 comments on commit fdc0e6e

Please sign in to comment.