-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Comments
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):
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. |
still needed, at least:
|
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 |
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:
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 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. |
Josh and I are going to pair on this at our next meeting. This would be a HUGE win. |
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.
The text was updated successfully, but these errors were encountered: