(section)
| 593 | } |
| 594 | |
| 595 | function decorateHomePage(section) { |
| 596 | var latestArticles = collectHomeUpdateArticles(section).slice(0, 6); |
| 597 | var classes = [ |
| 598 | 'home-reading-grid', |
| 599 | 'home-feature-grid', |
| 600 | 'home-update-list', |
| 601 | 'home-reason-grid' |
| 602 | ]; |
| 603 | var classByHeading = { |
| 604 | '先从这几篇开始': 'home-reading-grid', |
| 605 | 'Start Here': 'home-reading-grid', |
| 606 | '新主线': 'home-feature-grid', |
| 607 | 'Main Sections': 'home-feature-grid', |
| 608 | '最近更新': 'home-update-list', |
| 609 | 'Recent Updates': 'home-update-list', |
| 610 | '为什么值得关注': 'home-reason-grid', |
| 611 | 'Why Follow': 'home-reason-grid' |
| 612 | }; |
| 613 | |
| 614 | Array.from(section.querySelectorAll('h2')).forEach(function (heading) { |
| 615 | var listClass = classByHeading[heading.textContent.trim()]; |
| 616 | var next = heading.nextElementSibling; |
| 617 | |
| 618 | if (!listClass || !next || next.tagName !== 'UL') { |
| 619 | return; |
| 620 | } |
| 621 | |
| 622 | classes.forEach(function (className) { |
| 623 | next.classList.remove(className); |
| 624 | }); |
| 625 | next.classList.add(listClass); |
| 626 | |
| 627 | if (listClass === 'home-reading-grid') { |
| 628 | renderFeaturedCards(next, latestArticles); |
| 629 | } |
| 630 | |
| 631 | if (listClass === 'home-feature-grid') { |
| 632 | renderFeatureCards(next); |
| 633 | } |
| 634 | }); |
| 635 | } |
| 636 | |
| 637 | function collectHomeUpdateArticles(section) { |
| 638 | var updateHeadings = ['最近更新', 'Recent Updates']; |
no test coverage detected