-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Use image defined in front matter for social cards #5567
Comments
Thanks for suggesting! Great idea! We can actually implement this with a custom template, which will allow to use the image as a basis and optionally render text on top of the image, which you can decide on a page-by-page basis. For this to work, we need to implement two things that are already on the roadmap:
|
I would really love the ability to just define a card layout template in a page's front matter, personally. I was working on a custom layout in privacyguides/privacyguides.org#2177, and I made the card for the homepage look completely different than the cards for the rest of the site with a bunch of I think this solution would also address this "image-only card" problem, and it would be very powerful in combination with the meta plugin. |
Noted! We will definitely add the ability to change the card layout template + layout options via front matter in an upcoming release! And yes, combining this with the meta plugin will be super powerful. Feel free to open a new issue for this FR, as the FR reported here can likely be solved with what you#re asking, but it is more general. |
Additionally, a new layout called ExamplesDisable social card generation for a page---
social:
cards: false
---
# Headline
... Change social card layout for a page---
social:
cards_layout: default/only/image
---
# Headline
... Change social card layout options for a page---
social:
cards_layout_options:
background_color: red # Change background color to red
background_image: null # Reset background image
---
# Headline
... Page layout options are merged with global options, the former of which are taking precedence. In order to reset options to their defaults, you can use In order to implement the request in the OP, you would just set your image as the background image. The nice thing is that the social plugin will automatically scale it correctly, if it's not fitting the dimensions defined in your layout. Feedback appreciated. |
Documentation added in ab39491. I'll issue a release shortly. |
Released as part of 9.1.18+insiders-4.37.0! |
Good evening, Sorry for the delay in replying, I haven't had much time for my side projects in recent weeks. Thank you very much for the ideas derived from my request and the subsequent implementation! Still impressed with your responsiveness @squidfunk. These changes clearly make the use of the social plugin even more flexible. However, they don't quite meet my request, which was based on feedback from non-technical editors (or those not sufficiently skilled to master the arcana of the YAML frontmatter in mkdocs). If I have the following configuration: - social:
cards: !ENV [MKDOCS_ENABLE_PLUGIN_CARDS, true]
cards_layout_options:
cards_layout: default/only/image
cards_color:
fill: "#3e93a7"
font_family: Ubuntu And a page with : ---
title: The final tutorial
description: "Page WITH image set in frontmatter"
image: https//example.com/image.png
---
## Here we go for the technical writing with Mkdocs
How do I get the image defined in the frontmatter to be used? If I have another page with : ---
title: The final tutorial
description: "Page WITHOUT image set in frontmatter"
---
## Here we go for the technical writing with Mkdocs
How do I generate an image? You mentioned a template, otherwise I was thinking of an mkdocs hook that would write social: cards: false if the image is empty or absent from the frontmatter. Am I missing something? Any thoughts? |
Your request was targeted towards a specific feature: setting a background image on a social card for a single page. What we did is we generalized your request and now allow to set everything in a social card template to a value provided via metadata. I understand that it's not 100% of what you requested, but it allows for much more powerful integrations now. If you want you use a custom metadata property like
I recommend to study the
Please understand that "this is how we work". If we would implement each feature request as desired, Material for MkDocs would be a monster with 237 legs. Only by generalizing and modularizing we can keep the code base clean and the project in a great shape. We always try to put as little "burden of customization" as necessary on the author 😊 |
Oh, and if a little more verbosity is okay, then please just follow my previous comment: ---
social:
cards_layout: default/only/image
cards_layout_options:
background_image: <url>
---
# Page title |
Not exactly. It was about using an image, not specifically as background, just an image which is specified in frontmatter.
I understand and no need to remind me that, don't worry. Note that I'm not complaining about the necessary choices to keep the project generic enough to allow customization and global usage. I was just asking and confirming it was not completely filling my needs, to be sure that I was not missing something. Thanks for template tip :). |
Is there any downside of setting your image as a background image on the social card? The outcome is exactly the same if your image has the same dimension as the card (which it should). Because if you do it like that, you can use all additional functionality of the plugin, like automatically setting the necessary If this turns out to be an important use case, we might reconsider, but the essence of what you requested is now definitely possible, even though you might need a 3-4 line hook or adjust the template to fit it to your taste. |
…ontenus sans image (#921) L'objectif est d'activer le plugin `social` intégré au thème Material qui permet de générer une image automatiquement à partir des métadonnées de la page et de quelques éléments graphiques de base (logo, image de fond...). - doc du plugin intégré au thème : https://squidfunk.github.io/mkdocs-material/setup/setting-up-social-cards/ - ticket pour demander des évolutions sur le plugin social : squidfunk/mkdocs-material#5567
Just to follow the thread and if someone else is intersted, I've achieved the MkDocs's hook that allow to customize the social plugin behavior: https://github.com/geotribu/website/blob/master/hooks/mkdocs/G003_social_cards_adapter.py |
@Guts thanks for sharing! Note that this will only work with the Insiders version of the social plugin. |
Hi @squidfunk, just to follow up here: now, it works too on community version. I've added a `` attribute to theme section that allows me to adjust the hook's behavior depending on which theme's flavoris installed. Next step: using the group plugin. |
Context
As developer of the RSS plugin, I use the
image:
key (illustration:
is also supported) in the frontmatter to use it as media enclosure.Note: in a future release, the RSS plugin will be able to use the image generated by social plugin.
If I enable the social plugin:
Description
The idea is to add an option to tell the social plugin use the image set in the specified key in front matter instead of generating one.
Add option to generate card image only if when there is no
page.meta.image
norpage.meta.illustration
. It would give something like this:When YAML frontmatter does not contains image key, a social card is generated. When YAML frontmatter contains a image URI, it's directly used for the social card without generating one:
Related links
Use Cases
This option lets the author of a content set his illustration image and suggest one autogenerated by default if he is not inpired.
Visuals
No response
Before submitting
The text was updated successfully, but these errors were encountered: