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

Allow title of social cards to respect MkDocs hooks #7023

Closed
4 tasks done
ofek opened this issue Apr 7, 2024 · 2 comments
Closed
4 tasks done

Allow title of social cards to respect MkDocs hooks #7023

ofek opened this issue Apr 7, 2024 · 2 comments
Labels
change request Issue requests a new feature or improvement resolved by config change Issue can be mitigated by the reporter

Comments

@ofek
Copy link
Sponsor Collaborator

ofek commented Apr 7, 2024

Context

No response

Description

I would like to change the title default to be derived from the h1. This PR from the maintainer of MkDocs introduced a hook that satisfies every relevant component that I can see except for the generated social cards: pypa/hatch#1239

I'm using the latest version of the insiders edition.

Related links

https://squidfunk.github.io/mkdocs-material/plugins/social/#option.title

Use Cases

Full context is here: mkdocs/mkdocs#3532

Visuals

Inside https://github.com/pypa/hatch/blob/gh-pages/dev/how-to/publish/auth/index.html I see:

<title>How to authenticate for index publishing - Hatch</title>

But the card uses the nav: https://github.com/pypa/hatch/blob/gh-pages/dev/assets/images/social/how-to/publish/auth.png

social card

Before submitting

@squidfunk
Copy link
Owner

Thanks for suggesting. Insiders already allows to change many attributes for the default social card layouts by using the on_page_markdown hook, which deliberately uses a "latest" event priority to allow other plugins and hooks to change metadata before the social card is queued up for rendering. Moving rendering to on_page_content might be possible, but the problem is that the _title_from_render might contain markup, which will jam the social plugin.

Sticking to the title MkDocs derives before rendering is safe in regards to that it does not contain markup. Also note, that there are currently issues with title handling in MkDocs:

It seems that it was fixed, but we're still awaiting a release. We can re-evaluate this request once the changes are finally released, because it is unclear whether the title from rendering can "just be used" due to the potential presence of markup or unresolved icon short codes. Until then, here's a self-contained minimal reproduction that showcases how to change attributes for social cards programmatically in on_page_markdown for demo purposes:

social-card-title-hook.zip

Additionally, to work around the problem manually, you can use the following metadata in your page:

---
social:
  cards_layout_options:
    title: My page social card title
---

# My page title

Closing as resolved with configuration change.

@squidfunk squidfunk added change request Issue requests a new feature or improvement resolved by config change Issue can be mitigated by the reporter labels Apr 8, 2024
@ofek
Copy link
Sponsor Collaborator Author

ofek commented Apr 8, 2024

That hook works beautifully, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change request Issue requests a new feature or improvement resolved by config change Issue can be mitigated by the reporter
Projects
None yet
Development

No branches or pull requests

2 participants