Skip to content

Commit 4507539

Browse files
committed
chore: unify header/footer decoration
1 parent 34be78b commit 4507539

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

blocks/footer/footer.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import { loadFragment } from '../fragment/fragment.js';
66
* @param {Element} block The footer block element
77
*/
88
export default async function decorate(block) {
9+
// load footer as fragment
910
const footerMeta = getMetadata('footer');
10-
block.textContent = '';
11-
12-
// load footer fragment
13-
const footerPath = footerMeta.footer || '/footer';
11+
const footerPath = footerMeta ? new URL(footerMeta, window.location).pathname : '/footer';
1412
const fragment = await loadFragment(footerPath);
1513

1614
// decorate footer DOM
15+
block.textContent = '';
1716
const footer = document.createElement('div');
1817
while (fragment.firstElementChild) footer.append(fragment.firstElementChild);
1918

blocks/header/header.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,17 @@ function toggleMenu(nav, navSections, forceExpanded = null) {
8787
}
8888

8989
/**
90-
* decorates the header, mainly the nav
90+
* loads and decorates the header, mainly the nav
9191
* @param {Element} block The header block element
9292
*/
9393
export default async function decorate(block) {
9494
// load nav as fragment
9595
const navMeta = getMetadata('nav');
96-
const navPath = navMeta ? new URL(navMeta).pathname : '/nav';
96+
const navPath = navMeta ? new URL(navMeta, window.location).pathname : '/nav';
9797
const fragment = await loadFragment(navPath);
9898

9999
// decorate nav DOM
100+
block.textContent = '';
100101
const nav = document.createElement('nav');
101102
nav.id = 'nav';
102103
while (fragment.firstElementChild) nav.append(fragment.firstElementChild);

0 commit comments

Comments
 (0)