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

calendar: Fix Open Graph tags for better social sharing of ride links #94

Closed
carrythebanner opened this issue Mar 15, 2019 · 7 comments
Closed

Comments

@carrythebanner
Copy link
Collaborator

New ride links do work when shared to Facebook etc. but we can tidy up the Open Graph tags to pull in a better preview.

@fool fool changed the title Fix Open Graph tags for better social sharing of ride links calendar: Fix Open Graph tags for better social sharing of ride links Mar 19, 2019
@fool
Copy link
Member

fool commented Apr 12, 2019

I think all we need to do is add Open Graph tags to pages. As an MVP we add one to the theme, that just uses the shift logo, which will work for every page on the site. This might do the trick (untested, generated from an online tool):

<meta property="og:title" content="Shift">
<meta property="og:site_name" content="Shift website">
<meta property="og:url" content="https://www.shift2bikes.org">
<meta property="og:description" content="Shift’s mission is to promote inclusive bike fun. ">
<meta property="og:type" content="website">
<meta property="og:image" content="https://www.shift2bikes.org/legacycalimages/logos/shift-logo.svg">

Level 2 of this would be to use the page or event title instead of the generic ones.

Level 3 of this would be to use the event image IF EXISTING to replace the shift one. There might be some trivial way to do this like "specify a path whether there's an image or not, and if it 404's it'll fallback to this other default setting", or it might be that we have to embed some logic in the page to check with an API call at serve time but geez let's hope not.

@carrythebanner carrythebanner self-assigned this Apr 23, 2019
@carrythebanner
Copy link
Collaborator Author

Implemented changes in #165, #166, and #167.

@fool
Copy link
Member

fool commented Oct 22, 2019

still needed, at least:

@carrythebanner
Copy link
Collaborator Author

Calendar pages are rendered client-side, but Open Graph tags are in the document head and need to be rendered server-side. There are some possible solutions to serve special data or pre-render some data to crawlers specifically, but it needs some more investigation.

At the very least, we can change the description: "Rides calendar" tag in /site/content/calendar.md to be something a little snappier, as that's what currently appears in as the byline for the shared link.

@fool
Copy link
Member

fool commented Feb 6, 2020

When crawlers and social sharing services visit a netlify (where the calendar is hosted) webpage, Netify returns a prerendered version:

https://docs.netlify.com/site-deploys/post-processing/prerendering/#app

Why is that important? It is a place we could "do anything one can do in javascript on the client side" after the page loads, but before Netlify takes a javascript-already-run snapshot in html, and caches it for a day or two, and returns it to the service in question (twitter, slack, google, facebook, etc).

While that service runs, we can notice that it is running by checking the user agent, since the prerendering service uses headless chrome:

const isPrerender = /HeadlessChrome/.test(window.navigator.userAgent)

to detect we're being prerendered, and then do something like "parse URL, and get needed param to make API request to shift calendar backend": https://api.shift2bikes.org/api/events.php?id=12903 and that returns JSON that could be parsed into better OpenGraph data and "inserted" into the DOM before we allow the snapshot to complete (changing pre-set-to-false window.isprerenderReady to true after the API call and OG tag changing is completed, as described here: https://prerender.io/documentation/best-practices) .

This is pretty convoluted but sounds non terrible to write and implement, parsing the JSON from that API call is the hardest part, and it's not super hard for a JS whiz. Netlify will host the lambda function to do it if we wanted.

@onewheelskyward
Copy link
Contributor

Josh and I are going to pair on this at our next meeting. This would be a HUGE win.

@carrythebanner
Copy link
Collaborator Author

Fixed by #424 and #425.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants