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

Default scheme colors not used for Social cards when automatic/light dark mode is set #6929

Closed
4 tasks done
mitches-got-glitches opened this issue Mar 18, 2024 · 3 comments
Closed
4 tasks done
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@mitches-got-glitches
Copy link

mitches-got-glitches commented Mar 18, 2024

Context

I'm creating a personal blog with mkdocs-material==9.5.14 and the built-in Blog plugin.

Bug description

If I set my palette as the following with a non-default primary color set in the default scheme, then this color isn't used by the social plugin when creating the social cards, it just uses the default.

theme:
  palette:
    - media: "(prefers-color-scheme)"
      toggle:
        icon: material/brightness-auto
        name: Switch to light mode
    - media: "(prefers-color-scheme: light)"
      scheme: default
      primary: black
      accent: orange
      toggle:
        icon: material/brightness-5
        name: Switch to dark mode
    - media: "(prefers-color-scheme: dark)"
      scheme: slate
      toggle:
        icon: material/brightness-4
        name: Switch to system preference

image

If I repeat the palette colors in the top item under palette, then these are used by the social plugin when creating a card.

theme:
  palette:
    - media: "(prefers-color-scheme)"
      primary: black
      accent: orange
      toggle:
        icon: material/brightness-auto
        name: Switch to light mode
    - media: "(prefers-color-scheme: light)"
      scheme: default
      primary: black
      accent: orange
      toggle:
        icon: material/brightness-5
        name: Switch to dark mode
    - media: "(prefers-color-scheme: dark)"
      scheme: slate
      toggle:
        icon: material/brightness-4
        name: Switch to system preference

image

If I move the media: "(prefers-color-scheme: light)" item to the top item, then the colors also will be used properly by the social plugin, without the need for repetition.

theme:
  palette:
    - media: "(prefers-color-scheme: light)"
      scheme: default
      primary: black
      accent: orange
      toggle:
        icon: material/brightness-5
        name: Switch to dark mode
    - media: "(prefers-color-scheme)"
      toggle:
        icon: material/brightness-auto
        name: Switch to light mode
    - media: "(prefers-color-scheme: dark)"
      scheme: slate
      toggle:
        icon: material/brightness-4
        name: Switch to system preference

Suggested solutions

  • When selecting the color scheme to socials, search for the media item with schema: default and use those colors. The order of the list in the YAML won't matter with this solution.
  • Document the above behaviour in the docs - suggesting either repetition or making sure default scheme is the first item.

Related links

Reproduction

9.5.14-media-palette-unused-socials.zip

I've put in some commented sections so that anyone checking can try all of the light/dark mode suggestions in the docs and confirm this bug.

Steps to reproduce

Using the makefile on Linux...

  1. make all (installs imaging dependencies and requirements into a virtual environment
  2. Remove - info from the plugins in mkdocs.yml
  3. Activate venv with source .venv/bin/activate
  4. make docs

Browser

No response

Before submitting

@squidfunk squidfunk added the needs investigation Issue must be investigated by the maintainers label Mar 19, 2024
@squidfunk
Copy link
Owner

squidfunk commented Mar 19, 2024

Thanks for reporting, and again, thanks for the excellent reproduction and the report + documenting your attempts. Fixed in 66d4500. Now, the social plugin will look for the first palette item that defines a primary color. Your proposed fix to look for the item with the default color would not work for authors that only use slate (dark mode only).

Note that the social plugin has to employ a heuristic to decide what colors to use, and this might not what is expected. For this reason, the social plugin also allows to explicitly set the background_color of the social card:

plugins:
  - social:
      cards_layout_options:
        background_color: black

If you're using Insiders, you can even use CSS colors, including HEX codes or RGB, as mentioned in our documentation:

plugins:
  - social:
      cards_layout_options:
        background_color: "#ffcc00"

@squidfunk squidfunk added bug Issue reports a bug resolved Issue is resolved, yet unreleased if open and removed needs investigation Issue must be investigated by the maintainers labels Mar 19, 2024
@squidfunk
Copy link
Owner

cae9c18 also ports the fix to new social plugin implementation in Insiders.

@squidfunk
Copy link
Owner

Released as part of 9.5.15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

2 participants