@@ -803,9 +803,21 @@ function renderTopicDetails(topic) {
803803 <h3 class="section-title"><i class="fa-solid fa-list-check"></i> Table of Contents (TOC)</h3>
804804 <div class="timeline">
805805 ${ topic . syllabus . map ( ( item , idx ) => `
806- <div class="timeline-item">
807- <h4 class="timeline-title">${ idx + 1 } . ${ item . title } </h4>
808- <p class="timeline-desc">${ item . desc } </p>
806+ <div class="timeline-item" id="chapter-${ idx } ">
807+ <div class="timeline-content-wrapper">
808+ <h4 class="timeline-title">${ idx + 1 } . ${ item . title } </h4>
809+ <p class="timeline-desc">${ item . desc } </p>
810+ <button class="load-notes-btn" onclick="toggleChapterNotes('${ topic . id } ', ${ idx } )">
811+ <i class="fa-solid fa-book-open"></i> Read Study Notes
812+ </button>
813+ </div>
814+ <div class="chapter-accordion" id="accordion-${ idx } ">
815+ <div class="markdown-body" id="notes-content-${ idx } ">
816+ <div style="display:flex; align-items:center; gap:8px; color:var(--text-muted);">
817+ <i class="fa-solid fa-spinner fa-spin"></i> Loading notes...
818+ </div>
819+ </div>
820+ </div>
809821 </div>
810822 ` ) . join ( '' ) }
811823 </div>
@@ -848,6 +860,91 @@ function renderTopicDetails(topic) {
848860 ` ;
849861}
850862
863+ // Cache for storing fetched and parsed chapter notes
864+ const loadedNotesCache = { } ;
865+
866+ async function toggleChapterNotes ( topicId , index ) {
867+ const accordion = document . getElementById ( `accordion-${ index } ` ) ;
868+ const notesContent = document . getElementById ( `notes-content-${ index } ` ) ;
869+ const itemContainer = document . getElementById ( `chapter-${ index } ` ) ;
870+ const button = itemContainer . querySelector ( '.load-notes-btn' ) ;
871+
872+ // Toggle accordion state
873+ if ( accordion . classList . contains ( 'open' ) ) {
874+ accordion . classList . remove ( 'open' ) ;
875+ button . innerHTML = `<i class="fa-solid fa-book-open"></i> Read Study Notes` ;
876+ return ;
877+ }
878+
879+ // Open accordion
880+ accordion . classList . add ( 'open' ) ;
881+ button . innerHTML = `<i class="fa-solid fa-chevron-up"></i> Hide Notes` ;
882+
883+ const cacheKey = `${ topicId } -${ index } ` ;
884+ if ( loadedNotesCache [ cacheKey ] ) {
885+ notesContent . innerHTML = loadedNotesCache [ cacheKey ] ;
886+ return ;
887+ }
888+
889+ const topic = topicsData . find ( t => t . id === topicId ) ;
890+ const chapter = topic . syllabus [ index ] ;
891+
892+ // Dynamic Path Derivation
893+ let chapterPath = chapter . path ;
894+ if ( ! chapterPath ) {
895+ const titleClean = chapter . title . toLowerCase ( ) ;
896+ if ( titleClean . includes ( 'basics' ) || titleClean . includes ( 'fundamental' ) || titleClean . includes ( 'setup' ) || titleClean . includes ( 'syntax' ) || titleClean . includes ( 'first' ) ) {
897+ chapterPath = `${ topic . githubPath } /Basics/README.md` ;
898+ } else if ( titleClean . includes ( 'advanced' ) || titleClean . includes ( 'oop' ) || titleClean . includes ( 'class' ) ) {
899+ chapterPath = `${ topic . githubPath } /Advanced/README.md` ;
900+ } else if ( titleClean . includes ( 'intermediate' ) ) {
901+ chapterPath = `${ topic . githubPath } /Intermediate/README.md` ;
902+ } else {
903+ chapterPath = `${ topic . githubPath } /README.md` ;
904+ }
905+ }
906+
907+ try {
908+ // Fetch target file
909+ let response = await fetch ( chapterPath ) ;
910+ if ( ! response . ok ) {
911+ // Fallback to parent directory README
912+ response = await fetch ( `${ topic . githubPath } /README.md` ) ;
913+ }
914+
915+ if ( ! response . ok ) {
916+ throw new Error ( "Notes file not found" ) ;
917+ }
918+
919+ const markdown = await response . text ( ) ;
920+ const htmlContent = marked . parse ( markdown ) ;
921+ loadedNotesCache [ cacheKey ] = htmlContent ;
922+ notesContent . innerHTML = htmlContent ;
923+ } catch ( err ) {
924+ // Ultimate fallback layout
925+ const placeholderHTML = `
926+ <div style="border-left: 4px solid var(--primary); padding-left:14px; margin: 4px 0;">
927+ <h4 style="margin: 0 0 8px 0; color:var(--primary); font-weight:700;"><i class="fa-solid fa-graduation-cap"></i> ${ chapter . title } Notes</h4>
928+ <p style="margin-bottom:12px;">${ chapter . desc } </p>
929+ <h5 style="margin:12px 0 6px 0; font-weight:700; color:var(--text-primary);">🎯 Core Study Areas</h5>
930+ <ul style="padding-left:20px; margin-bottom:12px;">
931+ <li><strong>Fundamentals & Setup</strong>: Explore runtime configuration, compiler paths, package variables, and core execution layers.</li>
932+ <li><strong>Syntax Patterns</strong>: Practice variables declaration, logic flows, iterations, and control branches.</li>
933+ <li><strong>Standard Execution</strong>: Compile and debug first programs logging parameters.</li>
934+ </ul>
935+ <div class="code-panel" style="margin-top:14px; background:#06070d; border:1px solid var(--card-border);">
936+ <div class="code-header" style="background: rgba(255,255,255,0.02); padding: 8px 12px; border-bottom:1px solid var(--card-border);">
937+ <span style="font-size:12px; color:var(--text-muted);"><i class="fa-solid fa-code"></i> Reference Snippet</span>
938+ </div>
939+ <pre style="margin:0; padding:12px; font-family:var(--font-mono); font-size:13px; color:#e2e8f0; overflow-x:auto;">${ topic . codeSnippet || '// Execute program and test configurations' } </pre>
940+ </div>
941+ </div>
942+ ` ;
943+ loadedNotesCache [ cacheKey ] = placeholderHTML ;
944+ notesContent . innerHTML = placeholderHTML ;
945+ }
946+ }
947+
851948// 7. Render Landing View
852949function renderLanding ( ) {
853950 activeBreadcrumb . textContent = "Overview" ;
0 commit comments