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

Related Articles: Fix base path #1378

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions js/ucb-related-articles.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const relatedArticlesBlock = document.querySelector(".ucb-related-articles-block");
const baseURL = relatedArticlesBlock ? relatedArticlesBlock.getAttribute('data-baseurl') : '';

(function(relatedArticlesBlock) {
if (!relatedArticlesBlock) return;
const loggedIn = relatedArticlesBlock.getAttribute('data-loggedin') == 'true' ? true : false;
let childCount = 0;
const baseURL = relatedArticlesBlock.getAttribute('data-baseurl');

const excludeCatArr = JSON.parse(relatedArticlesBlock.getAttribute('data-catexclude'))
const excludeTagArr = JSON.parse(relatedArticlesBlock.getAttribute('data-tagexclude'))
Expand Down Expand Up @@ -242,7 +246,7 @@
var myCats = myCatsID.map((id)=> id.replace(/\D/g,''))// remove blanks, get only the cat ID#s

// Using tags and categories, construct an API call
var rootURL = `/jsonapi/node/ucb_article?include[node--ucb_article]=uid,title,ucb_article_content,created,field_ucb_article_summary,field_ucb_article_categories,field_ucb_article_tags,field_ucb_article_thumbnail&include=field_ucb_article_thumbnail.field_media_image&fields[file--file]=uri,url%20&filter[published][group][conjunction]=AND&filter[publish-check][condition][path]=status&filter[publish-check][condition][value]=1&filter[publish-check][condition][memberOf]=published`;
var rootURL = `${baseURL}/jsonapi/node/ucb_article?include[node--ucb_article]=uid,title,ucb_article_content,created,field_ucb_article_summary,field_ucb_article_categories,field_ucb_article_tags,field_ucb_article_thumbnail&include=field_ucb_article_thumbnail.field_media_image&fields[file--file]=uri,url%20&filter[published][group][conjunction]=AND&filter[publish-check][condition][path]=status&filter[publish-check][condition][value]=1&filter[publish-check][condition][memberOf]=published`;

var tagQuery = buildTagFilter(myTags)
var catQuery = buildCatFilter(myCats)
Expand Down Expand Up @@ -506,7 +510,7 @@
// These functions get the privated Categories and tags to not include them on the match count for their respective taxonomies
function getPrivateCategories(){
let privateCats = []
fetch('/jsonapi/taxonomy_term/category?filter[field_ucb_category_display]=false')
fetch(`${baseURL}/jsonapi/taxonomy_term/category?filter[field_ucb_category_display]=false`)
.then(response => response.json())
.then(data=>{
data.data.forEach(cat=>{
Expand All @@ -518,7 +522,7 @@ function getPrivateCategories(){

function getPrivateTags(){
let privateTags = []
fetch('/jsonapi/taxonomy_term/tags?filter[field_ucb_tag_display]=false')
fetch(`${baseURL}/jsonapi/taxonomy_term/tags?filter[field_ucb_tag_display]=false`)
.then(response => response.json())
.then(data=>{
data.data.forEach(tag=>{
Expand Down
4 changes: 4 additions & 0 deletions templates/content/node--ucb-article.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
{{ attach_library('boulder_base/ucb-related-articles') }}
{# Added class to article class 'pageStyleCSS' to control page style #}

{# Base Url #}
{% set baseURL = url('<front>')|render|trim('/') %}

{% set excludeCats = related_articles_exclude_categories %}
{% set excludeTags = related_articles_exclude_tags %}

Expand Down Expand Up @@ -183,6 +186,7 @@
{# Related Articles Block #}
<div{{ create_attribute({
class: ['container', 'ucb-related-articles-block'],
'data-baseurl' : baseURL,
'data-loggedin': logged_in ? 'true' : 'false',
'data-catsjson': content.field_ucb_article_categories|json_encode(constant('JSON_PRETTY_PRINT')),
'data-tagsjson': content.field_ucb_article_tags|json_encode(constant('JSON_PRETTY_PRINT')),
Expand Down
Loading