|
23 | 23 | </Section>
|
24 | 24 | <Section align="end" toolbar style="color: var(--mdc-on-surface, #000);">
|
25 | 25 | {#if activeSection}
|
26 |
| - {#each repos as repo} |
| 26 | + {#each activeSection.repos || [] as repo} |
27 | 27 | <Wrapper>
|
28 | 28 | <IconButton href={repo} target="_blank">
|
29 | 29 | <Icon component={Svg} viewBox="0 0 24 24">
|
|
111 | 111 | : 'shortcut' in section
|
112 | 112 | ? section.shortcut
|
113 | 113 | : null}
|
114 |
| - on:click={() => pickSection(section)} |
115 |
| - activated={'route' in section && section.route === $page.path} |
| 114 | + activated={section === activeSection} |
116 | 115 | style={section.indent
|
117 | 116 | ? 'margin-left: ' + section.indent * 25 + 'px;'
|
118 | 117 | : ''}
|
|
494 | 493 | },
|
495 | 494 | ];
|
496 | 495 |
|
497 |
| - let activeSection = sections.find( |
498 |
| - (section) => 'route' in section && section.route === $page.path |
| 496 | + $: activeSection = sections.find( |
| 497 | + (section) => 'route' in section && routesEqual(section.route, $page.path) |
499 | 498 | );
|
500 |
| - $: repos = |
501 |
| - activeSection && 'repos' in activeSection ? activeSection.repos : []; |
502 |
| -
|
503 |
| - onMount(setMiniWindow); |
504 |
| -
|
505 |
| - function pickSection(section) { |
506 |
| - if (!('shortcut' in section) && !('route' in section)) { |
507 |
| - return; |
508 |
| - } |
509 |
| -
|
| 499 | + let previousPagePath = null; |
| 500 | + $: if (mainContent && previousPagePath !== $page.path) { |
510 | 501 | drawerOpen = false;
|
511 |
| - mainContent.scrollTop = 0; |
| 502 | + const top = window.location.hash |
| 503 | + ? document.querySelector(window.location.hash)?.offsetTop || 0 |
| 504 | + : 0; |
| 505 | + mainContent.scrollTop = top; |
| 506 | + previousPagePath = $page.path; |
| 507 | + } |
512 | 508 |
|
513 |
| - // Svelte/Sapper is not updated the components correctly, so I need this. |
514 |
| - sections.forEach((section) => { |
515 |
| - if (!section.separator) { |
516 |
| - section.component.$set({ activated: false }); |
517 |
| - } |
518 |
| - }); |
519 |
| - section.component.$set({ activated: true }); |
| 509 | + onMount(setMiniWindow); |
520 | 510 |
|
521 |
| - activeSection = |
522 |
| - 'shortcut' in section |
523 |
| - ? sections.find((sec) => sec.route === section.shortcut) |
524 |
| - : section; |
| 511 | + function routesEqual(a, b) { |
| 512 | + return ( |
| 513 | + (a.endsWith('/') ? a.slice(0, -1) : a) === |
| 514 | + (b.endsWith('/') ? b.slice(0, -1) : b) |
| 515 | + ); |
525 | 516 | }
|
526 | 517 |
|
527 | 518 | function setMiniWindow() {
|
|
0 commit comments