Skip to content

Commit

Permalink
Feature/author teaser (#98)
Browse files Browse the repository at this point in the history
* Update author-teaser.js

* initial

* author-teaser
  • Loading branch information
kailasnadh790 authored Jan 22, 2024
1 parent 9c2088b commit cbe00f5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 106 deletions.
58 changes: 28 additions & 30 deletions cigaradvisor/blocks/author-teaser/author-teaser.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.author.block {
.author-teaser-wrapper {
display: flex;
padding: 20px 0;
}

.author.block>div {
.author-teaser.block {
display: flex;
flex-direction: column;
justify-content: center;
Expand All @@ -12,21 +12,21 @@
width: 100%;
}

.author.block .image-wrapper {
.author-teaser.block .image-wrapper {
text-align: center;
display: flex;
align-items: center;
justify-content: center;
padding: 0;
}

.author.block .image-wrapper img {
.author-teaser.block .image-wrapper img {
width: 100%;
max-width: 300px;
border: 1px solid var(--tan);
}

.author.block .author-details {
.author-teaser.block .author-details {
display: flex;
flex-direction: column;
align-items: center;
Expand All @@ -38,62 +38,62 @@
padding: 10px 0;
}

.author.block .author-details .author-heading-wrapper {
.author-teaser.block .author-details .author-heading-wrapper {
display: flex;
margin-top: 5px;
margin-top: 15px;
}

.author.block .author-details .author-heading {
.author-teaser.block .author-details .author-heading {
display: flex;
flex-direction: column;
align-items: center;
}

.author.block .author-details .author-heading h2 {
font-size: 24px;
.author-teaser.block .author-details .author-heading h2 {
font-size: var(--body-font-size-xxl);
text-align: center;
font-family: montserrat, sans-serif;
font-weight: 900;
font-weight: var(--font-weight-heavy);
color: var(--clr-dark-gray);
}

.author.block .author-details .author-heading h3 {
.author-teaser.block .author-details .author-heading h3 {
margin: 0 0 0 10px;
position: relative;
bottom: 2px;
font-size: 14px;
font-size: var(--body-font-size-s);
font-family: var(--ff-opensans);
font-weight: 600;
font-weight: var(--font-weight-semibold);
color: var(--clr-dark-gray);
cursor: default;
display: inline-block;
}


.author.block .author-details p {
font-weight: bolder;
.author-teaser.block .author-details p {
font-weight: var(--font-weight-bold);
}

.author.block .author-details a {
color: #1e90ff;
font-weight: bolder;
margin-bottom: 5px;
.author-teaser.block .author-details a {
color: var(--dodger-blue);
font-weight: var(--font-weight-bold);
margin-bottom: 15px;
}

.author.block .author-details ul {
.author-teaser.block .author-details ul {
display: flex;
margin: 10px 0;
margin: 10px 30px;

--icon-size: 20px;
}

.author.block .author-details ul li {
.author-teaser.block .author-details ul li {
margin-right: 20px;
}

/* media queries */
@media screen and (min-width: 900px) {
.author.block>div {
.author-teaser.block {
display: flex;
flex-direction: row;
margin-top: 20px;
Expand All @@ -103,7 +103,7 @@
max-width: 1080px;
}

.author.block .image-wrapper {
.author-teaser.block .image-wrapper {
text-align: center;
display: flex;
align-items: center;
Expand All @@ -113,12 +113,10 @@
float: left;
}

.author.block .author-details {
.author-teaser.block .author-details {
align-items: flex-start;
display: flex;
flex-direction: column;
border-top: 2px solid var(--clr-dark-gray);
border-bottom: 2px solid var(--clr-dark-gray);
text-align: left;
width: 75%;
margin-top: 0;
Expand All @@ -127,9 +125,9 @@
float: left;
}

.author.block .author-details .author-heading {
.author-teaser.block .author-details .author-heading {
display: flex;
flex-direction: row;
align-items: start;
align-items: center;
}
}
114 changes: 38 additions & 76 deletions cigaradvisor/blocks/author-teaser/author-teaser.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,61 @@
import { decorateExternalLink } from '../../scripts/scripts.js';
import { decorateIcons } from '../../scripts/aem.js';

/**
* Loads an author.
* @param {string} path The path to the author
* @returns {HTMLElement} The root element of the author
*/
async function loadAuthor(path) {
if (path && path.startsWith('/')) {
const resp = await fetch(`${path}.plain.html`);
if (resp.ok) {
const div = document.createElement('div');
div.innerHTML = await resp.text();
return div;
}
}
return null;
}
import { fetchAuthorInfo } from '../../scripts/scripts.js';
import { decorateIcons, createOptimizedPicture } from '../../scripts/aem.js';

export default async function decorate(block) {
const link = block.querySelector('a');
const path = link ? link.getAttribute('href') : block.textContent.trim();
block.innerHTML = '';
const author = await loadAuthor(path);
decorateExternalLink(author);
const author = await fetchAuthorInfo(path);
if (author) {
// add updated link to all author articles
const imageWrapper = document.createElement('div');
imageWrapper.classList.add('image-wrapper');
const picture = author.querySelector('picture');
imageWrapper.append(picture);
const authorName = author.querySelector('h2').innerHTML;
imageWrapper.append(createOptimizedPicture(author.image));
const authorDetails = document.createElement('div');
authorDetails.classList.add('author-details');
const authorHeadingWrapper = document.createElement('div');
authorHeadingWrapper.classList.add('author-heading-wrapper');
const authorHeading = document.createElement('div');
authorHeading.classList.add('author-heading');
if (author.querySelector('h2')) {
authorHeading.append(author.querySelector('h2'));
}
if (author.querySelector('h3')) {
authorHeading.append(author.querySelector('h3'));
}
authorHeading.innerHTML = `<h2 class="author-name">${author.name}</h2><h3 class="author-title">${author.title}</h3>`;
authorHeadingWrapper.append(authorHeading);
authorDetails.append(authorHeadingWrapper);
const authorP = author.querySelectorAll('p');
const authorPCount = authorP.length;
const authorPIndex = authorPCount - 1;
const authorPContent = authorP[authorPIndex];
if (authorPContent) {
authorDetails.append(authorPContent);
const authorDescription = document.createElement('p');
authorDescription.append(author.intro);
authorDetails.append(authorDescription);
const socialLinks = document.createElement('ul');
if (author.twitter) {
const twitterLink = document.createElement('li');
twitterLink.innerHTML = `<a href="https://twitter.com/${author.twitter}" target="_blank" rel="noopener noreferrer"><span class="icon icon-x-twitter"></span></a>`;
socialLinks.append(twitterLink);
}
const socialLinks = author.querySelector('ul');
if (socialLinks) {
const socialItems = socialLinks.querySelectorAll('li > a');
socialItems.forEach((item) => {
const innerText = item.innerText.trim();
if (innerText && innerText !== '') {
let icon;
switch (innerText) {
case 'twitter':
icon = 'twitter';
break;
case 'facebook':
icon = 'facebook-f';
break;
case 'instagram':
icon = 'instagram';
break;
case 'youtube':
icon = 'youtube';
break;
case 'pintrest':
icon = 'pintrest-p';
break;
default:
icon = 'unknown';
}
item.innerHTML = `<span class="icon icon-${icon}"></span>`;
}
});

decorateIcons(socialLinks);
authorDetails.append(socialLinks);
} else {
const emptySocialLinks = document.createElement('ul');
authorDetails.append(emptySocialLinks);
if (author.facebook) {
const facebookLink = document.createElement('li');
facebookLink.innerHTML = `<a href="https://facebook.com/${author.facebook}" target="_blank" rel="noopener noreferrer"><span class="icon icon-facebook-f"></span></a>`;
socialLinks.append(facebookLink);
}
if (author.instagram) {
const instagramLink = document.createElement('li');
instagramLink.innerHTML = `<a href="https://instagram.com/${author.instagram}" target="_blank" rel="noopener noreferrer"><span class="icon icon-instagram"></span></a>`;
socialLinks.append(instagramLink);
}
if (author.youtube) {
const youtubeLink = document.createElement('li');
youtubeLink.innerHTML = `<a href="https://youtube.com/${author.youtube}" target="_blank" rel="noopener noreferrer"><span class="icon icon-youtube"></span></a>`;
socialLinks.append(youtubeLink);
}
if (author.pintrest) {
const pintrestLink = document.createElement('li');
pintrestLink.innerHTML = `<a href="https://pintrest.com/${author.pintrest}" target="_blank" rel="noopener noreferrer"><span class="icon icon-pintrest-p"></span></a>`;
socialLinks.append(pintrestLink);
}
if (authorName) {
link.textContent = `Show all ${authorName}'s Articles`;
decorateIcons(socialLinks);
authorDetails.append(socialLinks);
if (author.name) {
link.textContent = `Show all ${author.name}'s Articles`;
authorDetails.append(link);
}
author.replaceChildren(imageWrapper);
author.append(authorDetails);
block.append(author);
block.replaceChildren(imageWrapper);
block.append(authorDetails);
}
}
1 change: 1 addition & 0 deletions cigaradvisor/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
--off-white: #f7f7f7;
--grey-background: #eaeaea;
--charcoal: #1c1c1c;
--dodger-blue: #1e90ff;

/* functional-colors */
--clr-text: var(--clr-dark-gray);
Expand Down

0 comments on commit cbe00f5

Please sign in to comment.