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

Blog twittercard sharing #2970

Merged

Conversation

kaimmej
Copy link
Contributor

@kaimmej kaimmej commented Jun 14, 2024

Issue:

twittercard metadata was not being pulled correctly and rendered into the html of our blog posts. When we went to share them, we were not including all of the information that twitter was expecting. The twitter sharing images looked wierd for 2 reasons: (1) we were applying the label "summary" instead of "summary image large". Twitter displays different cards depending on what we communicate in these meta tags. and (2) we were giving a small OpenSearch logo image, instead of an image at the correct 2:1 ratio.
Additionally, sharing to other sites, such as facebook or Linkedin was broken because we were providing a different image and that image was 404'ing. og image

Summary of changes:

This pull request also includes 8 generic images for the most common blog post categories.
I fixed the logic that was rendering the twitter metatags, organized the file, and added additional metatags that I found in the twitter docs.
I removed the twittercard information from head.html, and abstracted it into head-twitter-metatags.html.
I added generic images for the blog post categories into a new _data file (post_categories.yml) and the logic to pull them into the metadata of blog posts.

File changes:

_data/post_categories.yml

  • Created a new datafile for the post categories. In this data file, links to generic images have been added.
  • Added a commented out path for local testing one of the images. Normally - The pathing is not correct for local, only for the live site. So this is to help with debugging in the future.

_includes/head-twitter-metatags.html

  • Abstracted the twitter metadata into this new .html file.
  • these metatags use the category of the blog post to determine the generic image to use for the twittercard.
  • And if there is a featured image already on the blog post, the featured image is used instead of the generic.

_includes/head.html

  • removed twittercard metadata from head.html. All of this is now in head-twitter-metatags.html.

_layouts/default.html
- Added logic to use either head.html or head-twitter-metatags.html depending on the page type. If it is a blog post, it uses head-twitter-metatags.html, otherwise it uses head.html.

Issues Resolved

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the BSD-3-Clause License.

Notes:

Inspecting the page source for one of our most recent blog posts - we see that the twitter:image is different from the opengraph image. The opengraph image 404's.
image

kaimmej added 5 commits June 10, 2024 13:35
- Created and added generic images for blog posts, these generic images are centered on the most common post categories and are used as a default image for posts that do not have a specific image.
- The images are stored in the assets/media/blog-category-images folder.

New data file
- _data/post_categories.yml. This data file contains the categories for the blog posts and attaches the generic blog post image to the blog post category. Also provides the pathing to the images.

Signed-off-by: kaimmej <[email protected]>
   - I removed the twittercard information from head.html, and abstracted it into head-twitter-metatags.html.
   - Added generic images for the blog post categories into a new _data file (post_categories.yml).

File changes:
_data/post_categories.yml
   - Added the links to the images, forgot to do that in the first commit.
   - Added a commented out path for local testing one of the images. The pathing is not correct for local, only for the live site.

_includes/head-twitter-metatags.html
   - Added the twittercard and og meta tags to the head of the site.
   - these metatags use the category of the blog post to determine the generic image to use for the twittercard.
   - And if there is a featured image already on the blog post, the featured image is used.

_includes/head.html
   - removed twittercard metadata from head.html. All of this is now in head-twitter-metatags.html.

_layouts/default.html
    - Added logic to use either head.html or head-twitter-metatags.html depending on the page type. If it is a blog post, it uses head-twitter-metatags.html, otherwise it uses head.html.

Signed-off-by: kaimmej <[email protected]>
kaimmej and others added 5 commits June 18, 2024 14:59
Changed the category called "default" to "default-category". This was done because the liquid templating has a "default" filter that can be applied, and we should change the name so it doesnt get confused.

Signed-off-by: kaimmej [email protected]
…tag-metadata html page into it, and then head.html is applied to every page.

This was done because we want this metadata to be applied to every page of the site, before this change, it was only being applied to the blog posts.

Signed-off-by: kaimmej [email protected]
nateynateynate
nateynateynate previously approved these changes Jun 19, 2024
Copy link
Member

@nateynateynate nateynateynate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sharing preview improvements, act one scene one.

Copy link
Member

@nateynateynate nateynateynate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here goes nothing!

@nateynateynate nateynateynate merged commit 22c0a0c into opensearch-project:main Jun 19, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants