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/article teaser #34

Merged
merged 42 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
11ec35e
image-cta
kailasnadh790 Nov 30, 2023
a997d51
Update imagecta.js
kailasnadh790 Nov 30, 2023
949c494
Update imagecta.js
kailasnadh790 Nov 30, 2023
e046696
Update imagecta.js
kailasnadh790 Nov 30, 2023
1dc0bd5
article-teaser
kailasnadh790 Nov 30, 2023
e7655bd
optimized code
kailasnadh790 Nov 30, 2023
1913a44
Update imagecta.js
kailasnadh790 Nov 30, 2023
59ad3b7
Update imagecta.js
kailasnadh790 Nov 30, 2023
eaa9e0b
Update article-teaser.js
kailasnadh790 Nov 30, 2023
ec30578
refactored code
kailasnadh790 Dec 1, 2023
533f1ff
initial commit
kailasnadh790 Dec 1, 2023
4c1e41f
css changes
kailasnadh790 Dec 2, 2023
8825d90
css changes
kailasnadh790 Dec 2, 2023
c52b45e
alignment fixes
kailasnadh790 Dec 2, 2023
63c8ac8
moving foundation styling to style.css
kailasnadh790 Dec 3, 2023
e503e9d
date fix
kailasnadh790 Dec 3, 2023
731781e
Update article-teaser.css
kailasnadh790 Dec 3, 2023
8d36258
Update article-teaser.js
kailasnadh790 Dec 4, 2023
f45a693
Update article-teaser.js
kailasnadh790 Dec 4, 2023
cd773a0
Save space for the image.
bstopp Dec 4, 2023
5a36cea
Fix lint.
bstopp Dec 4, 2023
707244f
Update article-teaser.js
kailasnadh790 Dec 4, 2023
13093f3
Update imagecta.css
kailasnadh790 Dec 4, 2023
da38d22
Merge branch 'feature/image-cta' of https://github.com/hlxsites/famou…
kailasnadh790 Dec 4, 2023
de2f8d6
Fix image hegiht on small screens.
bstopp Dec 4, 2023
25a4c62
Merge branch 'feature/image-cta' of https://github.com/hlxsites/famou…
kailasnadh790 Dec 4, 2023
f6f8157
refactoring to remove ffetch
kailasnadh790 Dec 4, 2023
9b7a91d
Update article-teaser.js
kailasnadh790 Dec 5, 2023
1b70427
link fixes
kailasnadh790 Dec 5, 2023
1171485
Update article-teaser.css
kailasnadh790 Dec 5, 2023
84eec51
Merge branch 'main' of https://github.com/hlxsites/famous-smoke-cigar…
kailasnadh790 Dec 5, 2023
cd44030
lint fixes
kailasnadh790 Dec 5, 2023
d9aa740
code cleanup
kailasnadh790 Dec 5, 2023
a5adb7f
no message
kailasnadh790 Dec 5, 2023
8b202b2
teaser refactoring
kailasnadh790 Dec 5, 2023
d5b3c02
Update article-teaser.js
kailasnadh790 Dec 5, 2023
8c4ebed
Update article-teaser.js
kailasnadh790 Dec 5, 2023
cc70e97
Update article-teaser.js
kailasnadh790 Dec 5, 2023
3489899
Update article-teaser.js
kailasnadh790 Dec 5, 2023
03e8428
code review fixes
kailasnadh790 Dec 6, 2023
1a02181
Update article-teaser.css
kailasnadh790 Dec 6, 2023
f135093
Update cigaradvisor/blocks/article-teaser/article-teaser.js
kailasnadh790 Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
287 changes: 287 additions & 0 deletions cigaradvisor/blocks/article-teaser/article-teaser.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
.article-teaser.block .article-thumbnail:hover::before {
visibility: hidden;
}

.article-teaser.block .article.article-thumbnail::before {
content: '';
height: 100%;
width: 100%;
position: relative;
top: 0;
left: 0;
z-index: 3;
transition: visibility .2s linear;
}

.article-teaser.block .article {
position: relative;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: flex;
flex-direction: column;
align-items: stretch;
justify-content: flex-end;
text-align: center;
overflow: hidden;
flex: 1 1 100%;
min-height: 20rem;
padding-bottom: 20px;
}

@media screen and (min-width: 60em) {
.article-teaser.block .article.article-thumbnail {
min-height: 26.25rem;
}
}

.article-teaser.block .article-category {
position: absolute;
top: 20px;
left: 0;
padding: 7px 24px;
margin: 0 auto;
text-transform: capitalize;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
font-family: montserrat, sans-serif;
font-weight: 600;
background-color: #3c3a3b;
font-size: 12px;
z-index: 9999;
text-decoration: none;
}

.article-teaser.block .article-category.featured {
background-color: #1f1e1e
}

.article-teaser.block .article-category[data-category="Cigars 101"] {
background-color: #5f5d59
}

.article-teaser.block .article-category[data-category="Cigar Makers"] {
background-color: #8e7b5c
}

.article-teaser.block .article-category[data-category="Cigar News"] {
background-color: #916e35
}

.article-teaser.block .article-category[data-category="Cigar Buying Guides"] {
background-color: #7e4a3a
}

.article-teaser.block .article-category[data-category="Cigar Lifestyle"] .article-category {
background-color: #673841
}

.article-teaser.block .article-category[data-category="Food & Drink"] .article-category {
background-color: #3c5351
}

.article-teaser.block .article-category[data-category="Cigar Ratings & Reviews"] {
background-color: #24445d
}

.article-teaser.block .article-category[data-category="Cigar Humidification"] {
background-color: #5d8371
}

.article-teaser.block .article.article-thumbnail .article-image {
display: flex;
align-items: flex-start;
flex: 1 0 13rem;
width: 100%;
}

.article-teaser.block .article.article-thumbnail .article-image>img {
display: block;
width: 100%;
max-height: 321px;
}

.article-teaser.block .article.article-thumbnail .article-content::before {
content: '';
display: block;
flex: 1 0 72px;
min-height: 72px;
transition: flex-grow .55s ease-in-out;
}

.article-teaser.block .article.article-thumbnail:hover .article-content::before {
flex-grow: 0;
}

.article-teaser.block .article.article-thumbnail .article-content {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
flex: none;
display: flex;
flex-direction: column;
align-items: stretch;
justify-content: flex-end;
text-align: center;
overflow: hidden;
overflow-x: hidden;
overflow-y: hidden;
}

.article-teaser.block .article.article-thumbnail .article-header {
flex: 0 0 auto;
width: 100%;
min-height: 7rem;
padding: 40px 30px 20px;
background-color: #eaeaea;
display: block;
}

@media screen and (min-width: 60em) {
.article-teaser.block .article.article-thumbnail .article-header {
min-height: 140px
}
}

.article-teaser.block .article.article-thumbnail .article-title {
margin: 0 14px 16px;
font-size: 18px;
font-weight: 800;
}

.article-teaser.block .article.article-thumbnail .article-title-link {
display: block;
font-size: 1em;
font-weight: inherit;
color: inherit;
}

.article-teaser.block .article-thumbnail .article-meta {
font-size: 0;
color: #141414;
}

.article-teaser.block .article-thumbnail .article-meta a {
position: relative;
z-index: 2;
text-decoration: none;
color: #141414;
}

.article-teaser.block .article-thumbnail .article-meta>* {
display: inline-block;
font-family: montserrat, sans-serif;
font-weight: 600;
font-size: 16px;
}

.article-teaser.block .article.article-thumbnail .article-pubdate:not(:only-child)::before {
content: '|';
display: inline-block;
margin: 0 .5em;
}

.article-teaser.block .article.article-thumbnail .article-preview {
flex: 0 0 0;
display: flex;
flex-direction: column;
align-items: stretch;
justify-content: flex-start;
overflow: hidden;
padding: 0 30px;
font-family: "Open Sans", sans-serif;
background-color: #eaeaea;
transition: flex-grow .55s ease-in-out;
}

.article-teaser.block .article.article-thumbnail:hover .article-preview {
flex-grow: 1;
}

.article-teaser.block .article.article-thumbnail .article-excerpt::after {
content: '';
display: block;
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 20px;
background: linear-gradient(to top, #eaeaea, rgba(234 234 234 80%) 6px, rgba(234 234 234 0%));
}

.article-teaser.block .article.article-thumbnail .article-excerpt {
position: relative;
flex: 0 0 auto;
overflow: hidden;
padding-bottom: 20px;
font-weight: 600;
opacity: 0;
transition: flex-shrink .55s ease-in-out, opacity .55s ease-in-out;
}

.article-teaser.block .article.article-thumbnail:hover .article-excerpt {
flex-shrink: 1;
opacity: 1;
}

.article-teaser.block .article-thumbnail .article-excerpt p {
font-size: 1em;
font-family: inherit;
font-weight: inherit;
color: inherit;
cursor: default;
}

.article-teaser.block .article.article-thumbnail .article-excerpt p:last-child,
.article-teaser.block .article.article-thumbnail .article-excerpt ul:last-child,
.article-teaser.block .article.article-thumbnail .article-excerpt ol:last-child {
margin-bottom: 0;
}

.article-teaser.block .article.article-thumbnail .article-excerpt p:first-child,
.article-teaser.block .article.article-thumbnail .article-excerpt ul:first-child,
.article-teaser.block .article.article-thumbnail .article-excerpt ol:first-child {
margin-top: 0;
}

.article-teaser.block .read-more::after {
content: '\f054';
font-family: FontAwesome, sans-serif;
margin-left: 8px;
line-height: 1.5;
color: #b19b5e;
font-size: 18px;
}

.article-teaser.block .article-thumbnail .article-read-more {
display: block;
flex: 0 0 auto;
position: relative;
z-index: 2;
margin-bottom: 16px;
font-size: 16px;
font-weight: 700;
text-transform: uppercase;
opacity: 1;
transition: opacity .55s ease-in-out;
}


.article-teaser.block .article.article-thumbnail:hover .article-read-more {
opacity: 1;
}

.article-teaser.block .read-more {
text-transform: uppercase;
font-weight: 700;
text-align: center;
display: flex;
justify-content: center;
color: #b19b5e;
font-size: 18px;
}
63 changes: 63 additions & 0 deletions cigaradvisor/blocks/article-teaser/article-teaser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { createOptimizedPicture } from '../../scripts/aem.js';

function formatDate(originalDateString) {
const utcDateString = new Date((originalDateString - 25569) * 86400 * 1000);
const utcDate = new Date(utcDateString);
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const day = utcDate.getUTCDate();
const month = months[utcDate.getUTCMonth()];
const year = utcDate.getUTCFullYear().toString().slice(-2); // Get last two digits of the year
const formattedDate = `${day} ${month} ${year}`;
const dateTimeAttribute = `${utcDate.getUTCFullYear()}-${String(utcDate.getUTCMonth() + 1).padStart(2, '0')}-${String(utcDate.getUTCDate()).padStart(2, '0')}`;
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');
const fetchUrl = `${window.hlx.codeBasePath}/drafts/Kailas/pagemeta.json`;
const teaserContent = await fetchData(fetchUrl);
const articleInfo = teaserContent.find((obj) => obj.path === filterPath);
const categoryListUrl = `${window.hlx.codeBasePath}/drafts/Kailas/category/category-list.json`;
const categoryListData = await fetchData(categoryListUrl);
const articleCategory = articleInfo.category;
const articleCategoryInfo = categoryListData.find((obj) => obj.category === articleCategory);
const articleCategoryLink = articleCategoryInfo.categoryLink;
const [formattedDate, datetimeAttr] = formatDate(articleInfo.publishedDate).split('|');
const authorNameHyphenSeparated = articleInfo.author.split(' ').join('-');
const authorLink = `${window.hlx.codeBasePath}/author/drafts/${authorNameHyphenSeparated.toLowerCase()}`;
block.innerHTML = `
<article class="article article-thumbnail">
<a class="article-category" href="${articleCategoryLink}" data-category="${articleCategory}" title="${articleCategory}">${articleCategory}</a>
<div class="article-image">
${createOptimizedPicture(articleInfo.image).outerHTML}
</div>
<div class="article-content">
<articleheader class="article-header">
<h2 class="article-title">
<a class="article-title-link" href="${articleInfo.path}" title="${articleInfo.title}">${articleInfo.title}</a>
</h2>
<div class="article-meta">
<a class="article-authorLink" href="${authorLink}" title="By ${articleInfo.author}">By ${articleInfo.author}</a>
<time class="article-pubdate" datetime="${datetimeAttr}">${formattedDate}</time>
</div>
</articleheader>
<div class="article-preview">
<div class="article-excerpt">
<p><span class="rt-reading-time" style="display: block;"><span class="rt-label rt-prefix">Reading Time: </span> <span class="rt-time">${articleInfo.readingTime}</span></span> ${articleInfo.articleBlurb}</p>
</div>
<a class="article-read-more read-more" href="${articleInfo.path}" title="Read More">Read More</a>
</div>
</div>
</article>
`;
}
Loading