Skip to content

Commit

Permalink
Merge pull request #1144 from CuBoulder/issue/1116
Browse files Browse the repository at this point in the history
Articles by Person: Fixes API Error and Multisite lniks issue
  • Loading branch information
jcsparks authored and web-flow committed Jul 25, 2024
2 parents f161d62 + 4f9278a commit 9b9e481
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- ### Articles by Person: Fixes API Error and Multisite lniks issue
### Person Page: Article by Person block

- Previously this block would throw an API error on multisites due to an error in the API endpoint not being adjusted for a multisite config and it would attempt to fetch a relative API path. This has been corrected.

- Fixes the links to add the base URL as well for correct Article linking and linking to the correct authors Articles List page for 5+ Articles.

Resolves #1116
---

- ### Intro Wide region implementation
Closes #1126.
This adds the intro wide region to the block layout. This will primarily be used by images and hero units for a top banner.
Expand Down
17 changes: 9 additions & 8 deletions js/ucb-person-article-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ class PersonArticleList extends HTMLElement {
super();
// Article Endpoint
const nodeID = this.getAttribute('nodeId');
const API = `/jsonapi/node/ucb_article?include=field_ucb_article_byline.field_author_person_page&filter[field_ucb_article_byline.field_author_person_page.meta.drupal_internal__target_id]=${nodeID}&filter[status][value]=1&page[limit]=10&sort=-created`;
this._baseURI = this.getAttribute("base-uri");
const API = `${this._baseURI}/jsonapi/node/ucb_article?include=field_ucb_article_byline.field_author_person_page&filter[field_ucb_article_byline.field_author_person_page.meta.drupal_internal__target_id]=${nodeID}&filter[status][value]=1&page[limit]=10&sort=-created`;
fetch(API)
.then(this.handleError)
.then((data) => this.build(data, 5))
Expand All @@ -20,7 +21,7 @@ class PersonArticleList extends HTMLElement {
let NEXTJSONURL = "";
if(data.links.next) {
let nextURL = data.links.next.href.split("/jsonapi/");
NEXTJSONURL = `/jsonapi/${nextURL[1]}`;
NEXTJSONURL = `${this._baseURI}/jsonapi/${nextURL[1]}`;
} else {
NEXTJSONURL = "";
}
Expand Down Expand Up @@ -62,7 +63,7 @@ class PersonArticleList extends HTMLElement {
}

// Have articles and want to proceed
if(finalArticles.length > 0 && !NEXTJSONURL){
if(finalArticles.length > 0 && !NEXTJSONURL ){
this.renderDisplay(finalArticles, bylineTerm);
}
}
Expand All @@ -74,13 +75,13 @@ class PersonArticleList extends HTMLElement {

articleArray.forEach(article=>{
// Article Data
var articleLink = article.link;
var articleLink = `${this._baseURI}${article.link}`;
var articleTitle = article.title;

// Create and Append Elements
var article = document.createElement('article');
article.classList = 'ucb-article-card-title-only col-sm-12 col-md-6';

var articleBody = document.createElement('div');
articleBody.classList = 'ucb-article-card-data';

Expand All @@ -105,7 +106,7 @@ class PersonArticleList extends HTMLElement {
var readMoreDiv = document.createElement('div');
readMoreDiv.classList.add('ucb-article-read-more-container', 'col-sm-12', 'col-md-6');
var readMoreLink = document.createElement('a');
readMoreLink.href = `/taxonomy/term/${bylineTerm.id}`;
readMoreLink.href = `${this._baseURI}/taxonomy/term/${bylineTerm.id}`;
readMoreLink.classList.add('ucb-article-read-more');
readMoreLink.innerText = `More Articles by ${bylineTerm.name}`;
readMoreDiv.appendChild(readMoreLink);
Expand All @@ -130,7 +131,7 @@ class PersonArticleList extends HTMLElement {

// Used for error handling within the API response
handleError = response => {
if (!response.ok) {
if (!response.ok) {
throw new Error;
} else {
return response.json();
Expand All @@ -147,4 +148,4 @@ class PersonArticleList extends HTMLElement {
}
}

customElements.define('person-article-list', PersonArticleList);
customElements.define('person-article-list', PersonArticleList);
4 changes: 3 additions & 1 deletion templates/content/node--ucb-person.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
'ucb-content-wrapper'
] %}

{% set baseurlJSON = url('<front>')|render|trim('/') %}

<article{{attributes.addClass(classes)}} itemscope itemtype="https://schema.org/Person">
<div class="container ucb-person-header">
<h1 class="ucb-person-name">
Expand Down Expand Up @@ -72,7 +74,7 @@
</div>
</div>
<div class="ucb-articles-by-person-block">
<person-article-list nodeid="{{ node.id }}">
<person-article-list base-uri="{{baseurlJSON}}" nodeid="{{ node.id }}">
<div id="ucb-person-article-block-title" style="display:none">
<h2>Articles by
{{ content.field_ucb_person_first_name }}
Expand Down

0 comments on commit 9b9e481

Please sign in to comment.