From fd3189bb612712cd908dca9f19af87e706123b33 Mon Sep 17 00:00:00 2001 From: Pardeep Gera Date: Thu, 16 Nov 2023 19:09:16 +0530 Subject: [PATCH] audio embed --- blocks/audio-embed/audio-embed.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 blocks/audio-embed/audio-embed.js diff --git a/blocks/audio-embed/audio-embed.js b/blocks/audio-embed/audio-embed.js new file mode 100644 index 00000000..b3bf2c70 --- /dev/null +++ b/blocks/audio-embed/audio-embed.js @@ -0,0 +1,17 @@ +function extractContainerId(url) { + const urlObj = new URL(url); + const params = new URLSearchParams(urlObj.search); + return params.get('container_id'); +} + +export default function decorate(block) { + const anchorLink = block.querySelector('a').href; + const containerId = extractContainerId(anchorLink); + const divElement = document.createElement('div'); + divElement.setAttribute('id', containerId); + const scriptTag = document.createElement('script'); + scriptTag.src = anchorLink; + divElement.appendChild(scriptTag); + block.innerHTML = ''; + block.append(divElement); +}