Skip to content

Commit

Permalink
Merge pull request #1470 from CuBoulder/issue/1429
Browse files Browse the repository at this point in the history
Article Lists: Hides Dates, Decodes Special Characters in Titles of Taxonomy Term Pages
  • Loading branch information
jcsparks authored and web-flow committed Dec 10, 2024
2 parents 7d12327 + 61ecdb7 commit d41f817
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 27 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- ### Article Lists: Hides Dates, Decodes Special Characters in Titles of Taxonomy Term Pages
If an Article has it's date set to 'Hide' this update will hide the date on `Category` and `Tag` Taxonomy pages as well as on the `Article List Page` and `Article List Block` displays that show the date (Teaser, Feature)

Additionally fixes the display of special characters on Taxonomy term pages from not decoding correctly.

Resolves https://github.com/CuBoulder/tiamat-theme/issues/1465
Resolves https://github.com/CuBoulder/tiamat-theme/issues/1429
Resolves https://github.com/CuBoulder/tiamat-theme/issues/1509

Profile -> https://github.com/CuBoulder/tiamat10-profile/pull/239
---

- ### Mega menu Link color changes
Resolves #1530.
Forces the color of links in the mega menu to be blue to resolve issues of links not showing up.
Expand Down
20 changes: 20 additions & 0 deletions boulder_base.theme
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,26 @@ function boulder_base_form_system_theme_settings_alter(&$form, FormStateInterfac
}
}

/**
* Implements hook_preprocess_views_view().
*/
function boulder_base_preprocess_views_view(&$variables) {
// Adjust header content for the taxonomy_term view.
// Needed because the Full HTML text filter doesn't escape special HTML entities like &amp
if ($variables['view']->id() === 'taxonomy_term') {
if (isset($variables['header']['area']['#text'])) {
// Decode HTML entities in the header text.
$variables['header']['area']['#text'] = html_entity_decode($variables['header']['area']['#text']);
}
}
}







/**
* This is for list styles during migration.
*/
Expand Down
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
5 changes: 3 additions & 2 deletions css/ucb-taxonomy-page.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@
font-size: 85%;
line-height: 85%;
margin-bottom: 10px;
margin-top: 5px;
}

.ucb-taxonomy-title {
font-size: 120%;
font-weight: normal;
padding-bottom: 10px;
margin-bottom: 10px;
line-height: 1.3;
margin: 0 0 10px 0;
margin: 0;
}

.ucb-taxonomy-thumbnail {
Expand All @@ -71,7 +73,6 @@

.ucb-newsletter-row{
margin-bottom: 20px;
border-bottom: 1px solid rgba(128, 128, 128, 0.333);
padding-bottom: 20px;
}

Expand Down
53 changes: 36 additions & 17 deletions js/ucb-article-list-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ArticleListBlockElement extends HTMLElement {
var display = this.getAttribute("display");
var API = this.getAttribute("jsonapi");
this._baseURI = this.getAttribute("base-uri");

this.globalDateSetting = this.getAttribute('global-date-format');
// Exclusions are done on the JS side, get into arrays. Blank if no exclusions
var excludeCatArray = this.getAttribute("exCats").split(",").map(Number);
var excludeTagArray = this.getAttribute("exTags").split(",").map(Number);
Expand Down Expand Up @@ -119,10 +119,14 @@ class ArticleListBlockElement extends HTMLElement {
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" &&
(this.globalDateSetting != 6 || item.attributes.field_ucb_article_date_override != "0"))
? new Date(item.attributes.created).toLocaleDateString('en-us', {
year: 'numeric',
month: 'short',
day: 'numeric',
})
: null,
body: body.trim(),
};
}
Expand Down Expand Up @@ -288,13 +292,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 +316,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 +368,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 +392,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 +528,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 +553,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
18 changes: 11 additions & 7 deletions js/ucb-article-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
this.pageCount = pageCount;
this._categoryTerms = null;
this._tagTerms = null;

// Build the endpoint path, now in JS
this.endpoint = this.buildEndpointPath();
}
Expand Down Expand Up @@ -189,6 +188,8 @@
this._filterFormElement.style.alignItems = 'center';
this._contentElement.setAttribute('aria-live', 'polite');
}
// Date format
this.globalDateSetting = this.getAttribute('global-date-format');
this.appendChild(this._contentElement);
// Loader
this._loadingElement = document.createElement('div');
Expand Down Expand Up @@ -530,12 +531,15 @@
imageSrc = altObj[idObj[thumbId]];
}

// Format date
const date = new Date(item.attributes.created).toLocaleDateString('en-us', {
year: 'numeric',
month: 'short',
day: 'numeric',
});
// Format
const date = (item.attributes.field_ucb_article_date_override != "7" &&
(this.globalDateSetting != 6 || item.attributes.field_ucb_article_date_override != "0"))
? new Date(item.attributes.created).toLocaleDateString('en-us', {
year: 'numeric',
month: 'short',
day: 'numeric',
})
: null;
const title = item.attributes.title;
// If no path alias set, use defaults
const path = item.attributes.path.alias ? item.attributes.path.alias : `/node/${item.attributes.drupal_internal__nid}`;
Expand Down
7 changes: 6 additions & 1 deletion templates/block/block--article-list-block.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
{# Base Url #}
{% set baseurlJSON = url('<front>')|render|trim('/') %}

{# Show/Hide Date #}
{% set global_date_format = drupal_config('ucb_site_configuration.settings', 'article_date_format') %}

{# This block mirrors the Article List Node - constructs a JSON endpoint in TWIG using include filters #}
{# JSON API Endpoint information #}
{% set articlesJSON = (url('<front>')|render|trim('/'))
Expand Down Expand Up @@ -179,7 +182,9 @@
exCats="{{ excludeCategories }}"
exTags="{{ excludeTags }}"
display="{{ content.field_art_list_block_display|render|striptags|trim }}"
count="{{ content.field_art_list_block_item_count|render|striptags|trim }}">
count="{{ content.field_art_list_block_item_count|render|striptags|trim }}"
global-date-format="{{global_date_format}}"
>
<div id="ucb-al-loading" class="ucb-list-msg ucb-loading-data">
<i class="fa-solid fa-spinner fa-3x fa-spin-pulse"></i>
</div>
Expand Down
4 changes: 4 additions & 0 deletions templates/content/node--ucb-article-list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
{# Base Url #}
{% set baseurlJSON = url('<front>')|render|trim('/') %}

{# Show/Hide Date #}
{% set global_date_format = drupal_config('ucb_site_configuration.settings', 'article_date_format') %}

{# include and exclude options set by the user #}
{% set includeCategories = '' %}
{% set myCategories = content.field_ucb_filter_by_category|render|striptags|trim|split(' ') %}
Expand Down Expand Up @@ -149,6 +152,7 @@
'exclude-tags': excludeTags,
'expose-categories' : exposeCategory,
'expose-tags': exposeTag,
'global-date-format': global_date_format,
}) }}
>
</article-list>
Expand Down

0 comments on commit d41f817

Please sign in to comment.