-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
19 lines (19 loc) · 5.57 KB
/
Copy pathscript.js
File metadata and controls
19 lines (19 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* Renders shared portfolio data. The HTML contains useful static structure if JavaScript is unavailable. */
document.addEventListener('DOMContentLoaded', () => {
const d=portfolioData, $=s=>document.querySelector(s), esc=s=>String(s||'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
const menu=$('.menu-button'), list=$('.nav-list'); if(menu&&list){menu.addEventListener('click',()=>{let o=list.classList.toggle('open');menu.setAttribute('aria-expanded',o)});document.addEventListener('keydown',e=>{if(e.key==='Escape'){list.classList.remove('open');menu.setAttribute('aria-expanded','false');menu.focus()}})}
document.querySelectorAll('[data-profile="name"]').forEach(e=>e.textContent=d.profile.name);document.querySelectorAll('[data-profile="intro"]').forEach(e=>e.textContent=d.profile.intro);document.querySelectorAll('[data-profile="availability"]').forEach(e=>{e.textContent=d.profile.availability;e.hidden=!d.profile.availability});
document.querySelectorAll('[data-interests]').forEach(el=>el.innerHTML=d.researchInterests.map(x=>`<span class="tag">${esc(x)}</span>`).join(''));
const media=p=>`<div class="project-media"><img src="${esc(p.image)}" alt="${esc(p.title)} project image" onerror="this.parentElement.innerHTML='<span>${esc(p.category)}</span>'"></div>`;
const cards=(arr,full=false)=>arr.filter(x=>x.visible!==false).map(p=>`<article class="card">${media(p)}<div class="card-body"><p class="eyebrow">${esc(p.category)}</p><h3>${esc(p.title)}</h3><p class="meta">${esc(p.status)}${p.institution?' - '+esc(p.institution):''}</p><p>${esc(p.overview)}</p>${full?`<h4>Objective</h4><p>${esc(p.objective)}</p><h4>Methods</h4><div class="tags">${p.methods.map(x=>`<span class="tag">${esc(x)}</span>`).join('')}</div><h4>Tools</h4><p>${esc(p.tools.join(', ')||'To be updated')}</p><p class="meta"><strong>Contribution:</strong> ${esc(p.contribution)}<br><strong>Current outcome:</strong> ${esc(p.outcome)}</p>${p.github?`<p><a href="${esc(p.github)}" target="_blank" rel="noopener noreferrer">View project repository</a></p>`:''}`:''}</div></article>`).join('');
document.querySelectorAll('[data-projects]').forEach(el=>el.innerHTML=cards(el.dataset.projects==='featured'?d.projects.filter(p=>p.featured):d.projects,el.dataset.projects==='all'));
document.querySelectorAll('[data-education]').forEach(el=>el.innerHTML=d.education.map(x=>`<article><h3>${esc(x.degree)}</h3><p class="meta">${esc(x.institution)} - ${esc(x.dates)}</p><p>${esc(x.detail)}</p></article>`).join(''));
document.querySelectorAll('[data-experience]').forEach(el=>el.innerHTML=d.experience.filter(x=>x.visible&&x.position==='Research Intern').map(x=>`<article class="detail-card"><h3>${esc(x.organization)}</h3><p class="meta">${esc(x.position||'Details to be verified before publishing')}${x.dates?' - '+esc(x.dates):''}${x.supervisor?' - Supervisor: '+esc(x.supervisor):''}</p>${x.project?`<p><strong>Project:</strong> ${esc(x.project)}</p>`:''}${x.responsibilities.length?`<ul>${x.responsibilities.map(i=>`<li>${esc(i)}</li>`).join('')}</ul>`:'<p class="meta">Update this entry with verified position, supervisor, dates, responsibilities, methods, and skills.</p>'}${x.methods.length?`<p><strong>Methods:</strong> ${esc(x.methods.join(', '))}</p>`:''}${x.skills.length?`<p><strong>Skills developed:</strong> ${esc(x.skills.join(', '))}</p>`:''}</article>`).join(''));
document.querySelectorAll('[data-skills]').forEach(el=>el.innerHTML=Object.entries(d.skills).map(([k,v])=>`<article class="detail-card"><h3>${esc(k)}</h3><div class="tags">${v.map(x=>`<span class="tag">${esc(x)}</span>`).join('')}</div></article>`).join(''));
document.querySelectorAll('[data-achievements]').forEach(el=>el.innerHTML=d.achievements.map(x=>`<li>${esc(x)}</li>`).join(''));
const pub=d.publications; document.querySelectorAll('[data-publications]').forEach(el=>el.innerHTML=Object.entries(pub).map(([key,items])=>`<section><h2>${({journalArticles:'Journal Articles',underReview:'Manuscripts Under Review',inPreparation:'Manuscripts in Preparation',preprints:'Preprints',presentations:'Conference Presentations',posters:'Posters'})[key]}</h2>${items.length?items.map(i=>`<article class="detail-card"><h3>${esc(i.title)}</h3><p>${esc(i.venue||'')}</p><p class="meta">${esc(i.type||'')} ${i.status?' - '+esc(i.status):''}</p>${i.doi?`<p><a href="https://doi.org/${esc(i.doi)}" target="_blank" rel="noopener noreferrer">DOI: ${esc(i.doi)}</a></p>`:''}</article>`).join(''):'<p class="empty">No entries currently listed in this category.</p>'}</section>`).join(''));
const socials={github:'GitHub',linkedin:'LinkedIn',scholar:'Google Scholar',orcid:'ORCID',researchgate:'ResearchGate'};document.querySelectorAll('[data-socials]').forEach(el=>el.innerHTML=Object.entries(socials).filter(([k])=>d.socialLinks[k]).map(([k,n])=>`<a href="${esc(d.socialLinks[k])}" target="_blank" rel="noopener noreferrer">${n}</a>`).join(' - '));
document.querySelectorAll('[data-email]').forEach(el=>{el.href='mailto:'+d.profile.email;el.textContent=d.profile.email});
const cv=$('[cv-viewer]');if(cv){fetch(d.profile.cvPath,{method:'HEAD'}).then(r=>{if(r.ok){cv.innerHTML=`<object class="cv-viewer" data="${d.profile.cvPath}" type="application/pdf"><p>PDF preview is unavailable. <a href="${d.profile.cvPath}">Download the CV</a>.</p></object>`}else cv.innerHTML='<p class="notice">Add your PDF at assets/documents/Priyabrata_Das_CV.pdf to enable the viewer.</p>'}).catch(()=>cv.innerHTML='<p class="notice">Add your PDF at assets/documents/Priyabrata_Das_CV.pdf to enable the viewer.</p>')}
document.querySelectorAll('[data-year]').forEach(e=>e.textContent=new Date().getFullYear());
});