diff --git a/scripts/scripts.js b/scripts/scripts.js index ae5daf9b..d51331f2 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -11,6 +11,8 @@ import { waitForLCP, loadBlocks, loadCSS, + toClassName, + getMetadata, } from './aem.js'; const LCP_BLOCKS = []; // add your LCP blocks to the list @@ -42,6 +44,34 @@ async function loadFonts() { } } +const TEMPLATE_LIST = [ + 'Default', + 'Plasmids', + 'Proteins', + 'mRNA', +]; + +/** + * Run template specific decoration code. + * @param {Element} main The container element + */ +async function decorateTemplates(main) { + try { + const template = toClassName(getMetadata('template')); + const templates = TEMPLATE_LIST; + if (templates.includes(template)) { + const mod = await import(`../templates/${template}/${template}.js`); + loadCSS(`${window.hlx.codeBasePath}/templates/${template}/${template}.css`); + if (mod.default) { + await mod.default(main); + } + } + } catch (error) { + // eslint-disable-next-line no-console + console.error('Auto Blocking failed', error); + } +} + /** * Builds all synthetic blocks in a container element. * @param {Element} main The container element @@ -79,6 +109,7 @@ async function loadEager(doc) { const main = doc.querySelector('main'); if (main) { decorateMain(main); + await decorateTemplates(main); document.body.classList.add('appear'); await waitForLCP(LCP_BLOCKS); } diff --git a/templates/Default/Default.css b/templates/Default/Default.css new file mode 100644 index 00000000..ffc13a95 --- /dev/null +++ b/templates/Default/Default.css @@ -0,0 +1 @@ +/* Default template css */ diff --git a/templates/Default/Default.js b/templates/Default/Default.js new file mode 100644 index 00000000..c2b02792 --- /dev/null +++ b/templates/Default/Default.js @@ -0,0 +1 @@ +// Default template diff --git a/templates/Plasmids/Plasmids.css b/templates/Plasmids/Plasmids.css new file mode 100644 index 00000000..300c7028 --- /dev/null +++ b/templates/Plasmids/Plasmids.css @@ -0,0 +1 @@ +/* Plasmids */ diff --git a/templates/Plasmids/Plasmids.js b/templates/Plasmids/Plasmids.js new file mode 100644 index 00000000..78a7e55a --- /dev/null +++ b/templates/Plasmids/Plasmids.js @@ -0,0 +1 @@ +// Plasmids diff --git a/templates/Proteins/Proteins.css b/templates/Proteins/Proteins.css new file mode 100644 index 00000000..4d0c4551 --- /dev/null +++ b/templates/Proteins/Proteins.css @@ -0,0 +1 @@ +/* Proteins */ \ No newline at end of file diff --git a/templates/Proteins/Proteins.js b/templates/Proteins/Proteins.js new file mode 100644 index 00000000..11afc19d --- /dev/null +++ b/templates/Proteins/Proteins.js @@ -0,0 +1 @@ +// Proteins diff --git a/templates/mRNA/mRNA.css b/templates/mRNA/mRNA.css new file mode 100644 index 00000000..8446fca4 --- /dev/null +++ b/templates/mRNA/mRNA.css @@ -0,0 +1 @@ +/* mRNA */ diff --git a/templates/mRNA/mRNA.js b/templates/mRNA/mRNA.js new file mode 100644 index 00000000..f63386c7 --- /dev/null +++ b/templates/mRNA/mRNA.js @@ -0,0 +1 @@ +// mRNA