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

remove table of contents based on audience #245

Closed
wants to merge 1 commit into from
Closed
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
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
Loading