Skip to content

Commit

Permalink
Article List + Article List Block date hide
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbrown-io committed Nov 18, 2024
1 parent e1dccd5 commit bc8c5e3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
5 changes: 5 additions & 0 deletions css/block/ucb-article-list-block.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
margin: 0;
line-height: 1.3;
}

.ucb-article-card-title-no-date{
margin-bottom: 12px;
}

.ucb-article-card-title-feature {
font-size: 130%;
font-weight: bolder;
Expand Down
59 changes: 43 additions & 16 deletions js/ucb-article-list-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,27 @@ class ArticleListBlockElement extends HTMLElement {
// If no path alias set, use defaults
const path = item.attributes.path.alias ? item.attributes.path.alias : `/node/${item.attributes.drupal_internal__nid}`;


/**
*
*
*
* const date = item.attributes.field_ucb_article_date_override == "7" ? null : new Date(item.attributes.created).toLocaleDateString('en-us', {
year: 'numeric',
month: 'short',
day: 'numeric',
});
*/
return {
title: item.attributes.title,
link: this._baseURI + path,
image: imageSrc,
imageWide: imageSrcWide,
date: new Date(item.attributes.created).toLocaleDateString(
"en-us",
{ year: "numeric", month: "short", day: "numeric" }
),
date: item.attributes.field_ucb_article_date_override == "7" ? null : new Date(item.attributes.created).toLocaleDateString('en-us', {
year: 'numeric',
month: 'short',
day: 'numeric',
}),
body: body.trim(),
};
}
Expand Down Expand Up @@ -288,13 +300,18 @@ class ArticleListBlockElement extends HTMLElement {

var articleHeader = document.createElement("h3");
articleHeader.classList = "ucb-article-card-title-feature";
if(!articleDate){
articleHeader.classList.add("ucb-article-card-title-no-date");
}
articleHeader.innerText = articleTitle;

headerLink.appendChild(articleHeader);

var date = document.createElement("span");
date.classList = "ucb-article-card-date";
date.innerText = articleDate;
if(articleDate){
var date = document.createElement("span");
date.classList = "ucb-article-card-date";
date.innerText = articleDate;
}

var articleSummary = document.createElement("p");
articleSummary.innerText = articleSumm;
Expand All @@ -307,7 +324,7 @@ class ArticleListBlockElement extends HTMLElement {
readMore.setAttribute("aria-hidden", "true");

articleBody.appendChild(headerLink);
articleBody.appendChild(date);
if (articleDate){articleBody.appendChild(date)};
articleBody.appendChild(articleSummary);
articleBody.appendChild(readMore);

Expand Down Expand Up @@ -359,13 +376,18 @@ class ArticleListBlockElement extends HTMLElement {

var articleHeader = document.createElement("h3");
articleHeader.classList = "ucb-article-card-title-feature";
if(!articleDate){
articleHeader.classList.add("ucb-article-card-title-no-date");
}
articleHeader.innerText = articleTitle;

headerLink.appendChild(articleHeader);

var date = document.createElement("span");
date.classList = "ucb-article-card-date";
date.innerText = articleDate;
if(articleDate){
var date = document.createElement("span");
date.classList = "ucb-article-card-date";
date.innerText = articleDate;
}

var articleSummary = document.createElement("p");
articleSummary.innerText = articleSumm;
Expand All @@ -378,7 +400,7 @@ class ArticleListBlockElement extends HTMLElement {
readMore.setAttribute("aria-hidden", "true");

articleBody.appendChild(headerLink);
articleBody.appendChild(date);
if(articleDate){articleBody.appendChild(date)};
articleBody.appendChild(articleSummary);
articleBody.appendChild(readMore);

Expand Down Expand Up @@ -514,14 +536,19 @@ class ArticleListBlockElement extends HTMLElement {

var articleHeader = document.createElement("a");
articleHeader.classList = "ucb-article-card-title-teaser";
if(!articleDate){
articleHeader.classList.add("ucb-article-card-title-no-date");
}
articleHeader.href = articleLink;
articleHeader.innerText = articleTitle;

headerStrong.appendChild(articleHeader);

var date = document.createElement("span");
date.classList = "ucb-article-card-date";
date.innerText = articleDate;
if(articleDate){
var date = document.createElement("span");
date.classList = "ucb-article-card-date";
date.innerText = articleDate;
}

var articleSummary = document.createElement("p");
articleSummary.innerText = articleSumm;
Expand All @@ -534,7 +561,7 @@ class ArticleListBlockElement extends HTMLElement {
readMore.setAttribute("aria-hidden", "true");

articleBody.appendChild(headerStrong);
articleBody.appendChild(date);
if(articleDate){articleBody.appendChild(date)};
articleBody.appendChild(articleSummary);
articleBody.appendChild(readMore);

Expand Down
4 changes: 2 additions & 2 deletions js/ucb-article-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@
imageSrc = altObj[idObj[thumbId]];
}

// Format date
const date = new Date(item.attributes.created).toLocaleDateString('en-us', {
// Format
const date = item.attributes.field_ucb_article_date_override == "7" ? null : new Date(item.attributes.created).toLocaleDateString('en-us', {
year: 'numeric',
month: 'short',
day: 'numeric',
Expand Down

0 comments on commit bc8c5e3

Please sign in to comment.