Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header footer #51

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions blocks/footer/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ export default async function decorate(block) {
const cfg = readBlockConfig(block);
block.textContent = '';

let baseFooterUrl = '/fragments/footer/master';
if (window.location.hostname !== 'www.24petwatch.com') {
baseFooterUrl = 'https://main--24petwatch-crosswalk--hlxsites.hlx.live/fragments/footer/master';
}

// fetch footer content
const footerPath = cfg.footer || '/fragments/footer/master';
const footerPath = cfg.footer || baseFooterUrl;
const resp = await fetch(`${footerPath}.plain.html`, window.location.pathname.endsWith('/footer') ? { cache: 'reload' } : {});

if (false) {
if (resp.ok) {
const html = await resp.text();

// decorate footer DOM
Expand Down
34 changes: 30 additions & 4 deletions blocks/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ import { trackGTMEvent } from '../../scripts/lib-analytics.js';
let positionY = 0;
const SCROLL_STEP = 25;

const urls = {
usa: {
url: '/',
name: 'US',
icon: 'icon-flagusa',
lang: 'en-US',
},
canada: {
url: '/ca/',
name: 'Canada',
icon: 'icon-flagcanada',
lang: 'en-CA',
},
};

function closeOnEscape(e) {
if (e.code === 'Escape') {
const nav = document.getElementById('nav');
Expand Down Expand Up @@ -105,11 +120,18 @@ function toggleMenu(nav, navSections, closeAll = null) {
}

function decorateLanguageSelector(block) {
let currentCountry = urls.usa;
let alternateCountry = urls.canada;
if (window.location.pathname.startsWith('/ca/')) {
currentCountry = urls.canada;
alternateCountry = urls.usa;
}

const languageSelector = document.createElement('li');
languageSelector.classList.add('language-selector');
languageSelector.innerHTML = `<span class="icon icon-flagusa"></span>
languageSelector.innerHTML = `<span class="icon ${currentCountry.icon}"></span>
<ul>
<li><a href="https://www.24petwatch.com/ca" hreflang="en-CA" rel="alternate" title="Canada"><span class="icon icon-flagcanada"></span>Canada</a></li>
<li><a href="${alternateCountry.url}" hreflang="${alternateCountry.lang}" rel="alternate" title="${alternateCountry.name}"><span class="icon ${alternateCountry.icon}"></span>${alternateCountry.name}</a></li>
</ul>`;
block.querySelector(':scope > ul').prepend(languageSelector);

Expand Down Expand Up @@ -176,11 +198,15 @@ export default async function decorate(block) {
// fetch nav content
const navMeta = getMetadata('nav');
block.textContent = '';
let baseHeaderUrl = '/fragments/header/master';
if (window.location.hostname !== 'www.24petwatch.com') {
baseHeaderUrl = 'https://main--24petwatch-crosswalk--hlxsites.hlx.live/fragments/header/master';
}

const navPath = navMeta ? new URL(navMeta).pathname : '/fragments/header/master';
const navPath = navMeta ? new URL(navMeta).pathname : baseHeaderUrl;
const resp = await fetch(`${navPath}.plain.html`);

if (false) {
if (resp.ok) {
const html = await resp.text();

// decorate nav DOM
Expand Down
Loading