Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/authorcard #45

Closed
wants to merge 10 commits into from
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
224 changes: 224 additions & 0 deletions cigaradvisor/blocks/authorcard/authorcard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
.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-family: "alfa slab one", cursive;
kailasnadh790 marked this conversation as resolved.
Show resolved Hide resolved
font-size: 40px !important;
kailasnadh790 marked this conversation as resolved.
Show resolved Hide resolved
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;
kailasnadh790 marked this conversation as resolved.
Show resolved Hide resolved
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-container {
padding: 60px 10px;
background: none #ece8e3;
background-size: auto 150%;
}

.author-wrapper {
display: flex;
width: 100%;
}

.authorcard.block {
flex-flow: column wrap;
width: 100%;
}

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

.authorcard.block .left-column,
.right-column {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
padding: 0;
}

.authorcard.block .overlay-image {
flex: 0 0 100%;
width: 100%;
}

.authorcard.block .author-content .overlay-image img {
display: block;
width: 100%;
}
}
71 changes: 71 additions & 0 deletions cigaradvisor/blocks/authorcard/authorcard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { readBlockConfig, createOptimizedPicture } from '../../scripts/aem.js';
import { isExternal, fetchData } from '../../scripts/scripts.js';

export default async function decorate(block) {
const configs = readBlockConfig(block);
const { title } = configs;
const buttonLabel = configs['button-label'];
const buttonLink = configs['button-link'];
const { authors } = configs;
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');
// TODO: fetch author details from query-index.xlsx
const fetchUrl = `${window.hlx.codeBasePath}/drafts/Kailas/pagemeta.json`;
const authorContent = await fetchData(fetchUrl);
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);
}
});
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.page}">${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
1 change: 1 addition & 0 deletions head.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
<script src="/cigaradvisor/scripts/aem.js" type="module"></script>
<script src="/cigaradvisor/scripts/scripts.js" type="module"></script>
<link rel="stylesheet" href="/cigaradvisor/styles/styles.css"/>
<link crossorigin="anonymous" rel="stylesheet" id="ca-alfaslabmonterrat-font-css" href="//fonts.googleapis.com/css?family=Alfa+Slab+One%7CMontserrat%3A300%2C400%2C500%2C600%2C700%2C800%2C900%7COpen+Sans%3A400%2C600%2C700&#038;ver=5.5.1" type="text/css" media="all" />
kailasnadh790 marked this conversation as resolved.
Show resolved Hide resolved