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

og:image and og:type not always set #389

Closed
LorenzBung opened this issue May 14, 2020 · 6 comments
Closed

og:image and og:type not always set #389

LorenzBung opened this issue May 14, 2020 · 6 comments

Comments

@LorenzBung
Copy link

LorenzBung commented May 14, 2020

If I see this correctly, the og:image is set to image.path (in this line). But if only image: /url/to/image is specified, the tag is not set because image.path is not present, right? Shouldn't there be the following:

{% if seo_tag.image %}
    {% if seo_tag.image.path %}
        <meta property="og:image" content="{{ seo_tag.image.path }}" />
    {% else %}
        <meta property="og:image" content="{{ seo_tag.image }}" />
    {% endif %}
    ...
{% endif %}

Also, og:type is not set anywhere when setting seo.type, as specified in the advanced usage guide. Am I doing something wrong here? I tried setting seo.type in the _config.yml and also setting it in the front matter of pages and posts.

@ashmaroli
Copy link
Member

Alternatively, we could also use the default filter:

{% if seo_tag.image %}
    {% if seo_tag.image.path %}
       <meta property="og:image" content="{{ seo_tag.image.path | default: seo_tag.image }}" />
    {% endif %}
    ...
{% endif %}

But ultimately with either of the route, the problem is that if seo_tag.image is a Hash that has values set only for height and width, then the value for the meta tag's attribute content would end up being incorrect.

@LorenzBung
Copy link
Author

LorenzBung commented May 14, 2020

I think this should suffice as workaround:

{% if seo_tag.image %}
    {% if seo_tag.image.path %}
        <meta property="og:image" content="{{ seo_tag.image.path }}" />
        /* Put the checks for width and height here */
    {% else %}
        {% if seo_tag.image.width or seo_tag.image.height %}
            /* width and height are set, but image is an object -> do nothing */
        {% else %}
            <meta property="og:image" content="{{ seo_tag.image }}" />
        {% endif %}
    {% endif %}
{% endif %}

Of course, this only checks for the width and height children of the object.
Ugly solution, but I think Liquid has no not, right?

@LorenzBung
Copy link
Author

LorenzBung commented May 14, 2020

Even better solution, using the first filter of liquid:

{% if seo_tag.image.first %}
    /* image is object */
    {% if seo_tag.image.path %}
        <meta property="og:image" content="{{ seo_tag.image.path }}" />
        /* check if width and height are set */
        {% if seo_tag.image.width %}
            <meta property="og:image:width" content="{{ seo_tag.image.width }}" />
        {% endif %}
        {% if seo_tag.image.height %}
            <meta property="og:image:height" content="{{ seo_tag.image.height }}" />
        {% endif %}
    {% endif %}
{% else %}
    {% if seo_tag.image %}
        /* image is string */
        <meta property="og:image" content="{{ seo_tag.image }}" />
    {% endif %}
{% endif %}

@jekyllbot
Copy link
Contributor

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.

@LorenzBung
Copy link
Author

What about the pull requests?

@jekyllbot
Copy link
Contributor

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.

@jekyll jekyll locked and limited conversation to collaborators Nov 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants