Skip to content

Commit

Permalink
Merge pull request #347 from adobe/unify-head-foot
Browse files Browse the repository at this point in the history
chore: unify header/footer decoration
  • Loading branch information
fkakatie authored Apr 15, 2024
2 parents 72e2aa5 + 1449ba1 commit 1043b03
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions blocks/footer/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { loadFragment } from '../fragment/fragment.js';
* @param {Element} block The footer block element
*/
export default async function decorate(block) {
// load footer as fragment
const footerMeta = getMetadata('footer');
block.textContent = '';

// load footer fragment
const footerPath = footerMeta ? new URL(footerMeta, window.location).pathname : '/footer';
const fragment = await loadFragment(footerPath);

// decorate footer DOM
block.textContent = '';
const footer = document.createElement('div');
while (fragment.firstElementChild) footer.append(fragment.firstElementChild);

Expand Down
3 changes: 2 additions & 1 deletion blocks/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function toggleMenu(nav, navSections, forceExpanded = null) {
}

/**
* decorates the header, mainly the nav
* loads and decorates the header, mainly the nav
* @param {Element} block The header block element
*/
export default async function decorate(block) {
Expand All @@ -97,6 +97,7 @@ export default async function decorate(block) {
const fragment = await loadFragment(navPath);

// decorate nav DOM
block.textContent = '';
const nav = document.createElement('nav');
nav.id = 'nav';
while (fragment.firstElementChild) nav.append(fragment.firstElementChild);
Expand Down

0 comments on commit 1043b03

Please sign in to comment.