Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
kailasnadh790 committed Dec 18, 2023
1 parent c003633 commit 9c71b5e
Show file tree
Hide file tree
Showing 4 changed files with 324 additions and 9 deletions.
10 changes: 1 addition & 9 deletions cigaradvisor/blocks/article-teaser/article-teaser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createOptimizedPicture } from '../../scripts/aem.js';
import { fetchData } from '../../scripts/scripts.js';

function formatDate(originalDateString) {
const utcDateString = new Date((originalDateString - 25569) * 86400 * 1000);
Expand All @@ -12,15 +13,6 @@ function formatDate(originalDateString) {
return `${formattedDate}|${dateTimeAttribute}`;
}

async function fetchData(url) {
const resp = await fetch(url);
let jsonDataJson = '';
if (resp.ok) {
jsonDataJson = await resp.json();
}
return jsonDataJson.data;
}

export default async function decorate(block) {
const filterPath = block.querySelector('a').getAttribute('href');
block.classList.add('article-teaser');
Expand Down
235 changes: 235 additions & 0 deletions cigaradvisor/blocks/authorcard/authorcard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
.authorcard-container {
background: url('/cigaradvisor/images/author-card/media_17501a5f7bf5b4aebcf109765ead7cb5956480cbe.png');
margin-top: 50px;
background-position: center;
background-repeat: no-repeat;
background-color: transparent;
padding: 0 40px;
background-size: 900px 500px;
margin-bottom: 40px;
}

.authorcard-wrapper::after {
display: block;
clear: both;
}

.authorcard-wrapper {
display: flex;
padding-left: 0;
padding-right: 0;
width: 100%;
margin-left: auto;
margin-right: auto;
max-width: 1080px;
align-items: stretch;
justify-content: flex-start;
flex-wrap: wrap;
align-content: flex-start;
}

.authorcard.block {
display: flex;
}

.authorcard.block .left-column,
.right-column {
display: flex;
float: none;
width: 50%;
align-items: center;
justify-content: flex-start;
padding: 10px;
}

.authorcard.block .left-column h2 {
font-size: 40px !important;
color: #673841;
margin-top: 0;
padding-bottom: 10px;
border-image-source: url(/cigaradvisor/images/author-card/media_176afb26345b78f372ca811cf0e842c7ff75875a5.png);
border-image-slice: 50;
border-bottom: 30px solid;
}

.authorcard.block .left-column h2:first-child {
font-size: 35px !important;
border-bottom: none;
}


.authorcard.block .left-column p {
font-family: "open sans", sans-serif;
font-weight: 600;
color: #141414;
font-size: 12px;
cursor: default;
margin-top: 30px;
}

.authorcard.block .left-column .button {
background-color: #000;
border: 2px solid;
font-family: montserrat, sans-serif;
font-weight: 700;
color: #fff;
text-transform: uppercase;
border-color: #8e7b5c;
display: inline-block;
line-height: 26px;
height: 50px;
width: 250px;
max-height: 50px;
max-width: 250px;
min-height: 2.85rem;
padding-top: .8em;
padding-bottom: .8em;
cursor: pointer;
text-decoration: none;
text-align: center;
margin: 2px 0;
padding-left: 1em;
border-radius: 0;
font-size: 1em;
outline: none;
vertical-align: middle;
}

.authorcard.block .button:hover {
transition: .5s;
background-color: #b19b5e;
border-color: #b19b5e;
text-decoration: none;
}

.authorcard.block .right-column .author-wrapper {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}

.authorcard.block .author-content {
flex: 0 0 50%;
padding: 3px;
}

.authorcard.block .author-content .overlay-image {
margin-right: -100%;
background-image: none;
width: 100%;
background-position: 50% 50%;
background-repeat: no-repeat;
background-size: contain;
position: relative;
height: auto;
}

.authorcard.block .author-content .overlay-image img {
display: block;
}

.authorcard.block .right-column p {
color: #fff;
text-transform: uppercase;
background-color: transparent;
font-family: montserrat, sans-serif;
text-align: center;
cursor: default;
}

.authorcard.block .right-column p>a {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
color: #fff;
font-weight: 800;
font-size: 20px;
}

.authorcard.block .right-column p>a:hover {
transition: .8s;
text-decoration: none;
}


.authorcard.block .overlay-image:hover::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0 0 0 / 60%);}


.authorcard.block .align-center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity: 0;
transition: opacity 0.3s ease;
color: white;
text-align: center;
}

.authorcard.block .overlay-image:hover .align-center {
opacity: 1;
}

@media (max-width: 768px) {
.authorcard.block{
flex-direction: column;
}

.authorcard-wrapper {
width: auto;
}

.authorcard.block .left-column,
.right-column {
width: auto;
}

.authorcard.block .author-content {
flex: 0 0 100%;
}

/* align left-column content center and also all the text inside it center aligned */
.authorcard.block .left-column,
.right-column {
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}

/* background image should span the entire width of the container */
.authorcard.block .overlay-image {
flex: 0 0 100%;
width: 100%;
}

/* make authorcard-container background image span across authorcard block
and add 5% margin on top and bottom */
.authorcard-container {
background-size: auto 150%;
padding: 0 10px;
}

/* remove all left and right paddings applied on all the elements inside authorcard-container */
.authorcard.block .left-column,
.right-column,
.authorcard.block .left-column h2,
.authorcard.block .left-column p,
.authorcard.block .left-column .button,
.authorcard.block .right-column p,
.authorcard.block .right-column p>a {
padding: 0;
}



}
74 changes: 74 additions & 0 deletions cigaradvisor/blocks/authorcard/authorcard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { readBlockConfig, createOptimizedPicture } from '../../scripts/aem.js';
import { isExternal, fetchData } from '../../scripts/scripts.js';

export default async function decorate(block) {
const configs = readBlockConfig(block);
console.log(configs);
const { title } = configs;
const buttonLabel = configs['button-label'];
const buttonLink = configs['button-link'];
const { authors } = configs;
console.log(buttonLabel);
const leftDiv = document.createElement('div');
leftDiv.classList.add('left-column');
const authorLeftContentWrapper = document.createElement('div');
authorLeftContentWrapper.classList.add('author-left-content-wrapper');
title.forEach((titleLine) => {
const h2Tag = document.createElement('h2');
h2Tag.innerHTML = titleLine;
authorLeftContentWrapper.append(h2Tag);
});
const anchorWrapper = document.createElement('p');
const buttonAnchor = document.createElement('a');
buttonAnchor.innerHTML = buttonLabel;
buttonAnchor.setAttribute('href', buttonLink);
buttonAnchor.setAttribute('target', isExternal(buttonLink) ? '_blank' : '_self');
buttonAnchor.setAttribute('title', buttonLabel);
buttonAnchor.classList.add('button');
anchorWrapper.append(buttonAnchor);
authorLeftContentWrapper.append(anchorWrapper);
leftDiv.append(authorLeftContentWrapper);
block.replaceChildren(leftDiv);

const rightDiv = document.createElement('div');
rightDiv.classList.add('right-column');
const fetchUrl = `${window.hlx.codeBasePath}/drafts/Kailas/pagemeta.json`;
const authorContent = await fetchData(fetchUrl);
console.log(authorContent);
const authorsObj = [];
[...authors].forEach((authorPage) => {
let authorPath;
try {
const url = new URL(authorPage);
authorPath = url.pathname;
} catch (error) {
authorPath = authorPage;
}
const authorInfo = authorContent.find((obj) => obj.path === authorPath);
if (authorInfo) {
const authorDetails = {
page: authorInfo.path,
name: authorInfo.authorName,
image: authorInfo.authorImage,
};
authorsObj.push(authorDetails);
}
});
console.log(authorsObj);
const authorWrapperSection = document.createElement('section');
authorWrapperSection.classList.add('author-wrapper');
authorWrapperSection.innerHTML = '';
[...authorsObj].forEach((author) => {
authorWrapperSection.innerHTML
+= `<div class="author-content">
<div class="overlay-image">
${createOptimizedPicture(author.image).outerHTML}
<div class="overlay-content">
<p class="align-center"><a href="${author.path}">${author.name}</a></p>
</div>
</div>
</div>`;
});
rightDiv.replaceChildren(authorWrapperSection);
block.append(rightDiv);
}
14 changes: 14 additions & 0 deletions cigaradvisor/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ export function isExternal(path) {
}
}

/**
* Simple funtion to fetch json data from a spreadsheet
* @param {*} url
* @returns jsonData
*/
export async function fetchData(url) {
const resp = await fetch(url);
let jsonData = '';
if (resp.ok) {
jsonData = await resp.json();
}
return jsonData.data;
}

/**
* Loads everything needed to get to LCP.
* @param {Element} doc The container element
Expand Down

0 comments on commit 9c71b5e

Please sign in to comment.