-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fix issue where twitter cards not registering #29
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Josh!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK although I'm not sure I fully understand the {% if ... %}
block. 🤔
xanadu_sphinx_theme/layout.html
Outdated
{% if metatags is defined %} | ||
{% set description = metatags.split('\n') %} | ||
{{ description[0] | replace("og:", "") | replace("property", "name") }} | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is probably correct, but can you explain what exactly it does? In particular:
- Isn't
metatags
always defined if we have those<meta>
tags above? - Why are we printing only the first meta tag? What about the rest?
- What does printing actually accomplish here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very old code that got lost in the great XST merger, so I'm trying to cast my mind back!
Isn't metatags always defined if we have those tags above?
I think this refers to the .. meta::
ReST role. If a ReST page defines a metadata block this way, then this if statement is evaluated as true.
Why are we printing only the first meta tag? What about the rest?
I might be wrong, but my understanding is that there is an assumption that there is only one meta block on the page (see https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#html-meta or https://docutils.sourceforge.io/docs/ref/rst/directives.html#metadata).
So I think description[0]
is hardcoding this assumption? But I'm not sure.
What does printing actually accomplish here?
Good question 🤔
It looks like it is converting the following,
.. meta::
:property="og:description": An example demo using the Xanadu Sphinx Theme generated using Sphinx Gallery.
:property="og:image": https://pennylane.ai/qml/_static/wigner.png
into
<meta content="An example demo using the Xanadu Sphinx Theme generated using Sphinx Gallery." property="og:description" />
<meta content="https://pennylane.ai/qml/_static/wigner.png" property="og:image" />
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this refers to the
.. meta::
ReST role. If a ReST page defines a metadata block this way, then this if statement is evaluated as true.
Makes sense!
I might be wrong, but my understanding is that there is an assumption that there is only one meta block on the page (see https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#html-meta or https://docutils.sourceforge.io/docs/ref/rst/directives.html#metadata).
So I think
description[0]
is hardcoding this assumption? But I'm not sure.
I'm not sure that assumption is actually enforced anywhere but I think I can live it. That said, based on the documentation, you would think that
metatags.split('\n')[0]
would simply refer to the first defined <meta>
tag. 🤔
Good question 🤔
It looks like it is converting the following,
.. meta:: :property="og:description": An example demo using the Xanadu Sphinx Theme generated using Sphinx Gallery. :property="og:image": https://pennylane.ai/qml/_static/wigner.png
into
<meta content="An example demo using the Xanadu Sphinx Theme generated using Sphinx Gallery." property="og:description" /> <meta content="https://pennylane.ai/qml/_static/wigner.png" property="og:image" />
Ah, that makes sense, but this brings to mind another question:
{{ description[0] | replace("og:", "") | replace("property", "name") }}
Above, we see a call to replace("og:", "")
; however, there are clearly occurrences of og:
in the output. So what is that filter supposed to be doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what is that filter supposed to be doing?
I have no idea 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what does the output look like if we remove that filter? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<meta content="An example demo using the Xanadu Sphinx Theme generated using Sphinx Gallery." property="og:description" />
<meta content="https://pennylane.ai/qml/_static/wigner.png" property="og:image" />
Seems to have made no difference like you thought 😆
Co-authored-by: Mikhail Andrenkov <Mandrenkov@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks good to me! 🚢
Co-authored-by: Mikhail Andrenkov <Mandrenkov@users.noreply.github.com>
Context: The
.. meta::
directive in ReST is supposed to automatically create HTML<meta>
tags, and we use this in the QML repo to automatically register Open Graph social media cards. However, this was not working.Description of the Change: Add Jinja2 templating to ensure the OpenGraph card is correctly created.
Benefits: Fixes bug, card will now display on Twitter.
Possible Drawbacks: n/a
Related GitHub Issues: n/a