generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from famous-smoke/35-style-articles
Style articles pages
- Loading branch information
Showing
12 changed files
with
363 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
.item-wrapper { | ||
border-bottom: 1px dashed #ccc; | ||
margin-bottom: 40px; | ||
padding-bottom: 45px; | ||
font-size: 0.75em; | ||
font-weight: 300; | ||
} | ||
|
||
.item-wrapper h3 { | ||
margin-bottom: 25px; | ||
text-align: center; | ||
font-size: var(--heading-font-size-s); | ||
} | ||
|
||
.item-wrapper a { | ||
display: block; | ||
text-align: center; | ||
} | ||
|
||
.item-wrapper img { | ||
max-height: 75px; | ||
width: auto; | ||
margin-bottom: 25px; | ||
text-align: center; | ||
} | ||
|
||
.item-wrapper .item-stats { | ||
display: flex; | ||
justify-content: space-between; | ||
flex-wrap: wrap; | ||
margin: 30px auto; | ||
width: 90%; | ||
} | ||
|
||
.item-wrapper .item-stat { | ||
padding-right: 10px; | ||
} | ||
|
||
.item-wrapper .item-stat .label { | ||
font-weight: bold; | ||
} | ||
|
||
.item-wrapper .item-buy-now a { | ||
font-weight: 600; | ||
text-decoration: none; | ||
display: inline-block; | ||
box-sizing: border-box; | ||
width: auto; | ||
padding: 10px 25px 9px; | ||
background: #177abb; | ||
border-bottom: 1px solid #035890; | ||
color: #fff; | ||
border-radius: 4px; | ||
transition: background-color .15s; | ||
} | ||
|
||
.item-wrapper .item-buy-now a:hover { | ||
background: #0d67a2; | ||
} | ||
|
||
.item-wrapper .item-subinfo { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
width: 280px; | ||
margin: 0 auto; | ||
} | ||
|
||
.item-wrapper .item-star-rating img { | ||
width: 25px; | ||
height: 25px; | ||
margin: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* parse block row data into a js object | ||
* @param block | ||
* @returns {{}} | ||
*/ | ||
function parseData(block) { | ||
const rows = block.children; | ||
const data = {}; | ||
|
||
// eslint-disable-next-line no-plusplus | ||
for (let i = 0; i < rows.length; i++) { | ||
const fieldName = rows[i].firstElementChild.textContent; | ||
|
||
if (fieldName === 'Image') { | ||
data[fieldName] = rows[i].lastElementChild.innerHTML; | ||
} else if (fieldName === 'Rating') { | ||
data[fieldName] = Number(rows[i].lastElementChild.textContent); | ||
} else { | ||
data[fieldName] = rows[i].lastElementChild.textContent; | ||
} | ||
} | ||
|
||
return data; | ||
} | ||
|
||
/** | ||
* render rating stats html | ||
* @param data | ||
*/ | ||
function renderRatingStars(data) { | ||
let output = ''; | ||
|
||
// eslint-disable-next-line no-plusplus | ||
for (let i = 0; i < 5; i++) { | ||
if (i + 0.5 === data.Rating) { | ||
output += '<img src="/best-cigars-guide/icons/star-half.png" alt="">'; | ||
} else if (i < data.Rating) { | ||
output += '<img src="/best-cigars-guide/icons/star.png" alt="">'; | ||
} else { | ||
output += '<img src="/best-cigars-guide/icons/star-empty.png" alt="">'; | ||
} | ||
} | ||
|
||
return output; | ||
} | ||
|
||
/** | ||
* render individual item stats | ||
* @param data | ||
* @returns {string} | ||
*/ | ||
function renderStats(data) { | ||
// list of possible stat fields from block data | ||
const stats = [ | ||
'Country', | ||
'Strength', | ||
'Wrapper', | ||
'Color', | ||
]; | ||
|
||
let output = ''; | ||
// eslint-disable-next-line no-plusplus | ||
for (let i = 0; i < stats.length; i++) { | ||
if (stats[i] in data) { | ||
output += ` | ||
<div class="item-stat"> | ||
<p class="label">${stats[i]}</p> | ||
<p>${data[stats[i]]}</p> | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
return output; | ||
} | ||
|
||
function render(data) { | ||
const ratingLabel = data.Rating ? `Rated ${data.Rating} out of 5 stars.` : 'No ratings yet.'; | ||
|
||
return ` | ||
<h3>${data.Name}</h3> | ||
<a href="${data.Link}"> | ||
${data.Image} | ||
</a> | ||
<div class="item-info"> | ||
<p>${data.Description}</p> | ||
<div class="item-stats"> | ||
${renderStats(data)} | ||
</div> | ||
<div class="item-subinfo"> | ||
<div class="item-star-rating" data-rating="${data.Rating}" title="${ratingLabel}"> | ||
${renderRatingStars(data)} | ||
</div> | ||
<div class="item-buy-now"> | ||
<a href="${data.Link}" target="_blank">Buy Now</a> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
} | ||
|
||
/** | ||
* loads and decorates the item | ||
* @param {Element} block The item element | ||
*/ | ||
export default async function decorate(block) { | ||
const data = parseData(block); | ||
block.innerHTML = render(data); | ||
return block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.article-wrapper { | ||
display: flex; | ||
max-width: var(--content-width); | ||
margin: auto; | ||
justify-content: space-between; | ||
padding: 0 1rem; | ||
} | ||
|
||
.article-wrapper .section { | ||
padding: 0; | ||
width: 64%; | ||
} | ||
|
||
.article-wrapper aside { | ||
width: 30%; | ||
max-width: 315px; | ||
} | ||
|
||
aside h3 { | ||
font-size: 0.9em; | ||
margin: 0 0 1.2em; | ||
font-weight: 700; | ||
} | ||
|
||
aside ul { | ||
list-style: none; | ||
padding: 0; | ||
} | ||
|
||
aside li { | ||
margin: 0 0 12px; | ||
font-weight: 300; | ||
font-size: 0.7em; | ||
} | ||
|
||
@media (max-width: 600px) { | ||
.article-wrapper { | ||
display: block; | ||
} | ||
|
||
.article-wrapper .section { | ||
width: 100%; | ||
} | ||
|
||
.article-wrapper aside { | ||
width: 100%; | ||
max-width: 100%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { fetchCategoryList } from '../../scripts/scripts.js'; | ||
|
||
function getRelatedArticles() { | ||
const wrap = document.createElement('div'); | ||
wrap.className = 'sidebar-related-articles'; | ||
|
||
const heading = document.createElement('h3'); | ||
heading.textContent = 'Related Articles'; | ||
wrap.append(heading); | ||
|
||
const list = document.createElement('ul'); | ||
|
||
// todo: related article magic 🪄 | ||
list.innerHTML = '<li><a href="/best-cigars-guide">Dummy list item</a></li><li><a href="/best-cigars-guide">Dummy list item 2</a></li>'; | ||
|
||
wrap.append(list); | ||
|
||
return wrap; | ||
} | ||
|
||
async function getCategories() { | ||
const wrap = document.createElement('div'); | ||
wrap.className = 'sidebar-categories'; | ||
|
||
const heading = document.createElement('h3'); | ||
heading.textContent = 'CATEGORY'; | ||
wrap.append(heading); | ||
|
||
const currentCategoryPath = window.location.pathname.split('/').slice(0, 3).join('/'); | ||
const categoriesList = await fetchCategoryList(); | ||
// get the current category name | ||
categoriesList.forEach((category) => { | ||
const categoryPath = category.path.split('/') | ||
.slice(0, 3) | ||
.join('/'); | ||
|
||
if (categoryPath === currentCategoryPath) { | ||
heading.innerText = category.path | ||
.split('/') | ||
.pop() | ||
.replace(/-/g, ' ') | ||
.replace(/\b\w/g, (char) => char.toUpperCase()); | ||
} | ||
}); | ||
|
||
const list = document.createElement('ul'); | ||
|
||
// todo: fetch sub-categories from index | ||
list.innerHTML = '<li><a href="/best-cigars-guide">Dummy list item</a></li><li><a href="/best-cigars-guide">Dummy list item 2</a></li>'; | ||
|
||
wrap.append(list); | ||
|
||
return wrap; | ||
} | ||
|
||
export default async function decorate(block) { | ||
const categories = await getCategories(); | ||
block.append(categories); | ||
|
||
const relatedArticles = getRelatedArticles(); | ||
block.append(relatedArticles); | ||
|
||
return block; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.