Setting the share title (og:title
metatag) without affecting share image (index.png
) on the front page
#7597
-
I've been experimenting with using Material for Mkdocs as a new documentation platform for Robot Framework, a popular open source automation framework. You can see the current prototype here: I've been really happy with the results (generating API docs and setting up versioning were somewhat challenging but now work fine), but there's a small issue related social previews that I haven't been able to fix. The generated social images ( I'm able to change the title to what I want by adding
to the beginning of the front page. Unfortunately that also changes the generated social image ( Interestingly the same issue doesn't occur with other pages. For example, the preview of the API section has "API - Robot Framework" as its share title, as seen here, and the social image has just "API" as its main title. Some questions related to this:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Another problem with social preview is that it doesn't work well with versioning. For example, https://pekkaklarck.github.io/manual itself has no preview, as seen here, only the page it redirects to has. I already tested that this is easy to fix by manually adding required metatags to Update: I added the aforementioned metatags to |
Beta Was this translation helpful? Give feedback.
-
Hello @pekkaklarck, So to answer in order:
Title used for the Social Card mkdocs-material/material/plugins/social/plugin.py Lines 188 to 189 in 25b2107 Title used for the mkdocs-material/material/plugins/social/plugin.py Lines 341 to 344 in 25b2107 From the code we can see the logic is different in both cases, and the different behaviour for the meta tag on non-homepage pages seems to be done on purpose, so it's a feature and not a bug. However, this logic prevents the user from controlling the value.
You could use a hook to modify the
Modifying the saved file later is also an option like you said, but I think it would require parsing the HTML, which isn't necessary with using events above. There are also other ways to add customizability here, but modifying the Example of a hook file:
@squidfunk would need to comment on the discount part, but the docs claim there are no discounts |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply @kamilkrzyskow! I was able to fix the issue using hooks as you proposed. As seen here, the title is now "Robot Framework Manual" instead of just "Manual". I hadn't used or even noticed hooks earlier, and I really like how powerful and simple they are when needing to do something a bit more special. I was also happy to get a good answer from the community so quickly. Based on the code for setting the In this particular case I understand the idea to use a different title format on the home page and on other pages, but in my opinion the home page title should be # Compute page title
title = page.meta.get("title", page.title)
if not page.is_homepage:
title = f"{title} - {config.site_name}" with # Compute page title
title = config.site_name
if not page.is_homepage:
page_title = page.meta.get("title", page.title)
title = f"{page_title} - {title}" Anyway, @squidfunk or whoever wrote the current code may have good reasons for that exact behavior. And for me being able to override the title with hooks is definitely enough. |
Beta Was this translation helpful? Give feedback.
Hello @pekkaklarck,
from your shared links for the social preview we can surmise that the title for the embeds is taken from the
og:title
.So to answer in order:
Title used for the Social Card
mkdocs-material/material/plugins/social/plugin.py
Lines 188 to 189 in 25b2107
Title used for the
og:title
meta tag:mkdocs-material/material/plugins/social/plugin.py
Lines 341 to 344 in 25b2107