generated from adobecom/milo-college
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move fetchBlockFagDecoreated to utils/loadBlock
- Loading branch information
Showing
3 changed files
with
33 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getLibs } from '../utils.js'; | ||
|
||
const { createTag, getConfig } = await import(`${getLibs()}/utils/utils.js`); | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export async function fetchBlockFragDeprecated(url, blockName) { | ||
const location = new URL(window.location); | ||
const { prefix } = getConfig().locale; | ||
const fragmentUrl = `${location.origin}${prefix}${url}`; | ||
|
||
const path = new URL(fragmentUrl).pathname.split('.')[0]; | ||
const resp = await fetch(`${path}.plain.html`); | ||
if (resp.status === 404) { | ||
return null; | ||
} | ||
|
||
const html = await resp.text(); | ||
const section = createTag('div'); | ||
section.innerHTML = html; | ||
section.className = `section section-wrapper ${blockName}-container`; | ||
const block = section.querySelector(`.${blockName}`); | ||
block.dataset.blockName = blockName; | ||
block.parentElement.className = `${blockName}-wrapper`; | ||
block.classList.add('block'); | ||
const img = section.querySelector('img'); | ||
if (img) { | ||
img.setAttribute('loading', 'lazy'); | ||
} | ||
return section; | ||
} |