From bf0871195b5974144977666fcfce75e465f08be8 Mon Sep 17 00:00:00 2001 From: iansk Date: Wed, 3 Apr 2024 09:15:46 -0500 Subject: [PATCH] Revert "lighthouse improvements for article pages" --- blocks/article/article.css | 14 +++----- blocks/article/article.js | 56 ++++------------------------- blocks/search-bar/search-bar.js | 4 +-- blocks/sidenav/sidenav.js | 4 +-- blocks/theme-toggle/theme-toggle.js | 5 ++- scripts/scripts.js | 28 --------------- 6 files changed, 17 insertions(+), 94 deletions(-) diff --git a/blocks/article/article.css b/blocks/article/article.css index 0eaa86f..fd388d2 100644 --- a/blocks/article/article.css +++ b/blocks/article/article.css @@ -363,20 +363,20 @@ article [data-docs-heading] span { letter-spacing: var(--letter-spacing-neg--s); } -.book-content h1, .book-content .h1 { +.book-content h1 { font-size: 28px; line-height: 28px; } -.book-content h2, .book-content .h2 { +.book-content h2 { font-size: 24px; line-height: 24px; } -.book-content h3, .book-content .h3 { +.book-content h3 { font-size: 20px; line-height: 20px; } -.book-content h4, .book-content .h4, -.book-content h5, .book-content .h5 { +.book-content h4, +.book-content h5 { font-size: 18px; line-height: 18px; } @@ -426,10 +426,6 @@ article [data-docs-heading] span { word-break: break-word; } -.pan-article .book-content a.inline-link { - text-decoration: underline; -} - .pan-article .book-content pre { display: block; margin: var(--spacing--6) 0; diff --git a/blocks/article/article.js b/blocks/article/article.js index 56925ad..f8c9d85 100644 --- a/blocks/article/article.js +++ b/blocks/article/article.js @@ -4,9 +4,7 @@ import { SPA_NAVIGATION, decorateMain, getPlaceholders, - isMobile, loadBook, - makeHeadersSequential, parseFragment, render, renderSidenav, @@ -237,22 +235,6 @@ async function redirectToFirstChapter() { window.location.href = redirect; } -/** - * @param {HTMLElement} block - */ -function decorateInlineLinks(block) { - block.querySelectorAll('p:not(.button-container) > a').forEach((a) => { - const isInline = [ - a.previousSibling ? a.previousSibling.nodeType : -1, - a.nextSibling ? a.nextSibling.nodeType : -1, - ].includes(Node.TEXT_NODE); - - if (isInline) { - a.classList.add('inline-link'); - } - }); -} - const decorateCodeBlocks = (block) => { // Add copy code button for (const pre of block.querySelectorAll('pre')) { @@ -474,18 +456,6 @@ async function renderContent(block, res, rerender = false) { span.textContent = info.title; articleTitle.remove(); fragment.append(span); - - // add meta description - const meta = document.createElement('meta'); - meta.setAttribute('name', 'description'); - meta.setAttribute('content', document.title); - - const existing = document.head.querySelector('meta[name="description"]'); - if (existing) { - existing.replaceWith(meta); - } else { - document.head.appendChild(meta); - } } const content = document.createElement('div'); @@ -556,12 +526,17 @@ async function renderContent(block, res, rerender = false) { }); } + // Load sidenav, once + if (!rerender) { + renderSidenav(block); + import('../theme-toggle/theme-toggle.js'); + import('../../scripts/scroll-spy.js'); + } + if (articleFound) { const bookContent = block.querySelector('.book-content div[slot="content"]'); if (bookContent) { await decorateMain(bookContent); - makeHeadersSequential(bookContent); - decorateInlineLinks(bookContent); await loadBlocks(bookContent); updateSectionsStatus(bookContent); @@ -571,11 +546,6 @@ async function renderContent(block, res, rerender = false) { decorateCodeBlocks(block); } } - - // Load sidenav, once - if (!rerender) { - renderSidenav(block); - } } const renderCurrentVersion = (block) => { @@ -599,16 +569,4 @@ export default async function decorate(block) { initVersionDropdown(block); }); } - - // load theme toggle - - import('../theme-toggle/theme-toggle.js'); - - // scroll spy only works on desktop - // still load it on mobile, incase of tablet portrait/landscape change, but delay it - if (isMobile()) { - store.once('delayed:loaded', () => import('../../scripts/scroll-spy.js')); - } else { - import('../../scripts/scroll-spy.js'); - } } diff --git a/blocks/search-bar/search-bar.js b/blocks/search-bar/search-bar.js index 9e2da0d..ad2aecd 100644 --- a/blocks/search-bar/search-bar.js +++ b/blocks/search-bar/search-bar.js @@ -124,7 +124,7 @@ export class SearchBar extends HTMLElement { let html = ''; const options = JSON.parse(defaultOptions); options.forEach((option, i) => { - html += `