Skip to content

Commit

Permalink
remove table of contents based on audience
Browse files Browse the repository at this point in the history
  • Loading branch information
renz-maban committed Aug 22, 2024
1 parent 635c4ab commit 136ef63
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion lib/kits/core-ui/components/incito-publication/section-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,53 @@ const defaultTemplate = `\

const SectionList = ({sgnData, template, scriptEls}) => {
let container: HTMLDivElement | null = null;
const regex = new RegExp(/tjek_audience=[^#&;+]+/);
const match = regex.exec(location.href) || [];
let sectionList: {title: string; view_id: string}[] = [];
let feature;

if (match.length > 0) {
feature =
match[0] !== undefined
? match[0].replace('tjek_audience=', '').split(',')
: ['none'];
} else if (localStorage.getItem('tjek_audience') !== null) {
feature = localStorage.getItem('tjek_audience')?.split(',') || ['none'];
} else {
const cookie = regex.exec(document.cookie) || [];
feature =
cookie[0] !== undefined
? cookie[0].replace('tjek_audience=', '').split(',')
: ['none'];
}

if (feature.includes('all'))
sectionList = sgnData?.incito?.table_of_contents;
else
sgnData?.incito?.table_of_contents.forEach((section) => {
if (feature.includes('none')) {
if (
!section.feature_labels.includes(feature) &&
section.feature_labels.length === 0
)
sectionList.push(section);
} else if (
feature.some(
(element) =>
section.feature_labels.includes(element) ||
section.feature_labels.length === 0
)
)
sectionList.push(section);
});

template = template?.innerHTML || defaultTemplate;

const render = async () => {
container = document.createElement('div');
container.className = 'sgn-sections-container';
container.innerHTML = Mustache.render(template, {
sections: sgnData?.incito?.table_of_contents
sections: sectionList
});

addSectionClickListener();
Expand Down

0 comments on commit 136ef63

Please sign in to comment.