Skip to content

Issue with Open Sans font in social plugin #5517

@croesus

Description

@croesus

Context

No response

Bug description

Google's Open Sans font package contains several font variations in subdirectories. The code picks the last one that ends in "-Regular.ttf" which returns an arbitrary variation based on the order the OS returns files.

Open_Sans
├── OFL.txt
├── OpenSans-Italic-VariableFont_wdth,wght.ttf
├── OpenSans-VariableFont_wdth,wght.ttf
├── README.txt
└── static
    ├── OpenSans
    │   ├── OpenSans-Bold.ttf
    │   ├── OpenSans-BoldItalic.ttf
    │   ├── OpenSans-ExtraBold.ttf
    │   ├── OpenSans-ExtraBoldItalic.ttf
    │   ├── OpenSans-Italic.ttf
    │   ├── OpenSans-Light.ttf
    │   ├── OpenSans-LightItalic.ttf
    │   ├── OpenSans-Medium.ttf
    │   ├── OpenSans-MediumItalic.ttf
    │   ├── OpenSans-Regular.ttf
    │   ├── OpenSans-SemiBold.ttf
    │   └── OpenSans-SemiBoldItalic.ttf
    ├── OpenSans_Condensed
    │   ├── OpenSans_Condensed-Bold.ttf
    │   ├── OpenSans_Condensed-BoldItalic.ttf
    │   ├── OpenSans_Condensed-ExtraBold.ttf
    │   ├── OpenSans_Condensed-ExtraBoldItalic.ttf
    │   ├── OpenSans_Condensed-Italic.ttf
    │   ├── OpenSans_Condensed-Light.ttf
    │   ├── OpenSans_Condensed-LightItalic.ttf
    │   ├── OpenSans_Condensed-Medium.ttf
    │   ├── OpenSans_Condensed-MediumItalic.ttf
    │   ├── OpenSans_Condensed-Regular.ttf
    │   ├── OpenSans_Condensed-SemiBold.ttf
    │   └── OpenSans_Condensed-SemiBoldItalic.ttf
    └── OpenSans_SemiCondensed
        ├── OpenSans_SemiCondensed-Bold.ttf
        ├── OpenSans_SemiCondensed-BoldItalic.ttf
        ├── OpenSans_SemiCondensed-ExtraBold.ttf
        ├── OpenSans_SemiCondensed-ExtraBoldItalic.ttf
        ├── OpenSans_SemiCondensed-Italic.ttf
        ├── OpenSans_SemiCondensed-Light.ttf
        ├── OpenSans_SemiCondensed-LightItalic.ttf
        ├── OpenSans_SemiCondensed-Medium.ttf
        ├── OpenSans_SemiCondensed-MediumItalic.ttf
        ├── OpenSans_SemiCondensed-Regular.ttf
        ├── OpenSans_SemiCondensed-SemiBold.ttf
        └── OpenSans_SemiCondensed-SemiBoldItalic.ttf

I've implemented a change to the social plugin that specifically matches the -Regular.ttf version in this fork. It uses os.walk() rather than glob() to find the files. Either would probably be fine but I'd implemented it before your fix for the Inter font (#5420 - see related links).

It sounds like work is in progress on the social plugin, so please let me know if you would like me to submit a PR for this or just pick it up yourself.

Related links

Reproduction

example.zip

Steps to reproduce

If you add

                print(f"{match.group(1)} - {font[match.group(1)]}")

on line 465 of plugin.py then run mkdocs build you get the output

...
Regular - .cache/plugin/social/static/OpenSans_Condensed/OpenSans_Condensed-Regular.ttf
...
Regular - .cache/plugin/social/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-Regular.ttf
...
Regular - .cache/plugin/social/static/OpenSans/OpenSans-Regular.ttf
...

It's an accident of file ordering that the last one is the one we want, and shouldn't be relied upon.

Browser

No response

Before submitting

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions