Skip to content

Commit

Permalink
Merge pull request #26 from hlxsites/feature/templates
Browse files Browse the repository at this point in the history
Template boiler plate code
  • Loading branch information
teshukatepalli1 authored Oct 25, 2023
2 parents 2c61250 + 4b6e0df commit 1f33f59
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
waitForLCP,
loadBlocks,
loadCSS,
toClassName,
getMetadata,
} from './aem.js';

const LCP_BLOCKS = []; // add your LCP blocks to the list
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions templates/Default/Default.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Default template css */
1 change: 1 addition & 0 deletions templates/Default/Default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Default template
1 change: 1 addition & 0 deletions templates/Plasmids/Plasmids.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Plasmids */
1 change: 1 addition & 0 deletions templates/Plasmids/Plasmids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Plasmids
1 change: 1 addition & 0 deletions templates/Proteins/Proteins.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Proteins */
1 change: 1 addition & 0 deletions templates/Proteins/Proteins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Proteins
1 change: 1 addition & 0 deletions templates/mRNA/mRNA.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* mRNA */
1 change: 1 addition & 0 deletions templates/mRNA/mRNA.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// mRNA

0 comments on commit 1f33f59

Please sign in to comment.