Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(theme-{classic,common}): refactor site/page/search metadata + apply className on html element #6925

Merged
merged 15 commits into from
Mar 18, 2022

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Mar 16, 2022

Breaking change:

Some CSS classes were previously applied to the Layout wrapper. For maximum flexibility, they are now applied on the top-level HTML element, so your custom CSS selectors might have to be updated accordingly.

Why do we do this change? Because now you have the ability to target the site layout elements too (ie customize the navbar/sidebar/footer based on classes added to the top-level HTML element

The existing .main-wrapper class remains applied as before around Layout children prop: <div className="main-wrapper">{children}</div>

Example CSS selectors to update:

  • div.main-wrapper.blog-wrapper.blog-post-page { } => html.blog-wrapper.blog-post-page .main-wrapper {}
  • .main-wrapper.docs-wrapper { } => .docs-wrapper .main-wrapper {}

Note that html.{docs,blog,pages}-wrapper now looks like a weird className on the HTML element, so we'll likely remove this class later.

Now each plugin routes already provide a top-level HTML className: plugin-{docs,blog,pages},

For example a md doc page now has this HTML element:

<html class="plugin-docs plugin-id-default docs-wrapper docs-doc-page docs-version-current docs-doc-id-introduction ">
  ...
</html>

The most future-proof way to target the "inner" content of a docs-route is:

.plugin-docs .main-wrapper {
  color: red;
}

The most future-proof way to target the "inner" content of a doc page (rendering a md doc) is:

.docs-doc-page .main-wrapper {
  color: red;
}

Motivation

Docusaurus core should apply some basic default metadata

It should be possible for a theme or site to provide global site metadata, overriding Docusaurus defaults

It should be possible for a page to override global site metadata, overriding global site metadata.

It should not be the responsibility of the Layout to apply page metadata.

Site metadata should be applied consistently even if the user decides to use a different layout.

Wrapper/page class names should be applied at the very top for maximum flexibility, see also #4280

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

Preview: metadata should be exactly as before (apart page classNames moved upper to the html element)

@slorber slorber added pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. pr: polish This PR adds a very minor behavior improvement that users will enjoy. labels Mar 16, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 16, 2022
@netlify
Copy link

netlify bot commented Mar 17, 2022

✔️ [V2]

🔨 Explore the source changes: 8d04740

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/6234c353bdb141000950bd71

😎 Browse the preview: https://deploy-preview-6925--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Mar 17, 2022

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 46
🟢 Accessibility 100
🟢 Best practices 92
🟢 SEO 100
🟢 PWA 90

Lighthouse ran on https://deploy-preview-6925--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Mar 17, 2022

Size Change: +108 B (0%)

Total Size: 804 kB

Filename Size Change
website/build/assets/css/styles.********.css 105 kB +254 B (0%)
website/build/assets/js/main.********.js 610 kB -145 B (0%)
ℹ️ View Unchanged
Filename Size Change
website/.docusaurus/globalData.json 49.9 kB 0 B
website/build/index.html 38.8 kB -1 B (0%)

compressed-size-action

# Conflicts:
#	packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx
#	packages/docusaurus-theme-classic/src/theme/DocPage/index.tsx
#	packages/docusaurus-theme-common/src/index.ts
@slorber slorber changed the title refactor: change how site/page/search metadata is handled refactor(theme-{classic,common}): change how site/page/search metadata is handled Mar 18, 2022
@slorber slorber marked this pull request as ready for review March 18, 2022 16:46
@slorber
Copy link
Collaborator Author

slorber commented Mar 18, 2022

👍 looks like it's working fine

metadatas are good too, used an HTML diff tool to check a few pages

@slorber slorber merged commit 74f653d into main Mar 18, 2022
@slorber slorber deleted the slorber/refactor-page-className branch March 18, 2022 17:53
@slorber slorber changed the title refactor(theme-{classic,common}): change how site/page/search metadata is handled refactor(theme-{classic,common}): refactor site/page/search metadata + apply className on html element Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. pr: polish This PR adds a very minor behavior improvement that users will enjoy.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants