79 lines
3.7 KiB
JavaScript
79 lines
3.7 KiB
JavaScript
import { sidebar } from './sidebar.mjs';
|
|
|
|
const shared = {
|
|
'period-1/discrete-mathematics': 'block-1/discrete-mathematics',
|
|
'period-1/procedural-programming': 'block-1/procedural-programming',
|
|
'period-2/calculus': 'block-2/calculus',
|
|
'period-2/logic': 'block-2/logic',
|
|
'period-2/objects-in-programming': 'block-2/objects-in-programming',
|
|
'period-4/data-structures-and-algorithms': 'block-4/data-structures-and-algorithms',
|
|
'period-4/linear-algebra': 'block-4/linear-algebra',
|
|
};
|
|
|
|
const computerScience = {
|
|
label: 'Computer Science',
|
|
items: [
|
|
{ slug: 'computer-science' },
|
|
{ label: 'Year 1', items: [
|
|
{ slug: 'computer-science/year-1' },
|
|
{ label: 'Period 1', items: ['discrete-mathematics', 'introduction-to-computer-science', 'procedural-programming'].map((slug) => ({ slug: `computer-science/year-1/period-1/${slug}` })) },
|
|
{ label: 'Period 2', items: ['calculus', 'logic', 'objects-in-programming'].map((slug) => ({ slug: `computer-science/year-1/period-2/${slug}` })) },
|
|
{ label: 'Period 4', items: ['computer-architecture', 'data-structures-and-algorithms', 'linear-algebra'].map((slug) => ({ slug: `computer-science/year-1/period-4/${slug}` })) },
|
|
{ label: 'Period 5', items: ['algorithmic-design', 'databases', 'statistics'].map((slug) => ({ slug: `computer-science/year-1/period-5/${slug}` })) },
|
|
] },
|
|
],
|
|
};
|
|
|
|
const compact = { label: 'Bachelor programmes', items: [{ slug: 'computer-science' }, { slug: 'data-science-and-ai' }] };
|
|
const programmeSharedLabels = new Set(['Home', 'Previous exams and documents', 'Useful Information']);
|
|
|
|
export function programmeForPathname(pathname) {
|
|
if (pathname.startsWith('/computer-science')) return 'computer-science';
|
|
if (pathname.startsWith('/data-science-and-ai') || pathname.startsWith('/bachelor')) return 'data-science-and-ai';
|
|
return null;
|
|
}
|
|
|
|
export function programmeSwitchTargets(pathname) {
|
|
let computerScience = '/computer-science/';
|
|
let dataScience = '/data-science-and-ai/';
|
|
for (const [cs, ds] of Object.entries(shared)) {
|
|
if (pathname.includes(`/computer-science/year-1/${cs}`) || pathname.includes(`/data-science-and-ai/year-1/${ds}`)) {
|
|
computerScience = `/computer-science/year-1/${cs}/`;
|
|
dataScience = `/data-science-and-ai/year-1/${ds}/`;
|
|
break;
|
|
}
|
|
}
|
|
return { computerScience, dataScience };
|
|
}
|
|
|
|
export function sidebarForPathname(pathname) {
|
|
const programme = programmeForPathname(pathname);
|
|
const dataScience = sidebar.find(({ label }) => label === 'Data Science & AI');
|
|
|
|
if (programme) {
|
|
const undergraduate = programme === 'computer-science' ? computerScience : dataScience;
|
|
const home = sidebar.find(({ label }) => label === 'Home');
|
|
const previousExams = sidebar.find(({ slug }) => slug === 'previous-exams-and-documents');
|
|
const usefulInformation = sidebar.find(({ label }) => label === 'Useful Information');
|
|
return [home, previousExams, undergraduate, usefulInformation];
|
|
}
|
|
|
|
const withoutProgrammes = sidebar.filter(({ label }) => label !== 'Computer Science' && label !== 'Data Science & AI');
|
|
return [...withoutProgrammes.slice(0, 3), compact, ...withoutProgrammes.slice(3)];
|
|
}
|
|
|
|
export function filterResolvedSidebar(entries, pathname) {
|
|
const programme = programmeForPathname(pathname);
|
|
|
|
if (programme) {
|
|
const activeLabel = programme === 'computer-science' ? 'Computer Science' : 'Data Science & AI';
|
|
return entries.filter(({ label }) => programmeSharedLabels.has(label) || label === activeLabel);
|
|
}
|
|
|
|
return entries.map((entry) => {
|
|
if ((entry.label === 'Computer Science' || entry.label === 'Data Science & AI') && 'entries' in entry) {
|
|
return { ...entry, entries: entry.entries.slice(0, 1) };
|
|
}
|
|
return entry;
|
|
});
|
|
}
|