emgithub icon indicating copy to clipboard operation
emgithub copied to clipboard

Cannot Embed on Medium

Open weeping-angel opened this issue 2 years ago • 4 comments

Hey there,

I found emgithub.com to be extremely useful to my workflow, but I cannot embed my code snippets (from my repo) on medium.com. This is maybe because they use "embed.ly" to handle all the interactive embeddings.

@yusanshi , Would you please consider listing "emgithub.com" on Embedly? It would help a LOT of people.

Thanks in advance!

weeping-angel avatar Jul 18 '22 09:07 weeping-angel

I went to embed.ly and I guess you meant Become an Embedly Provider. If emgithub.com becomes a provider of embed.ly, we can paste something like https://emgithub.com/pytorch/pytorch/blob/master/torch/nn/cpp.py and it will render the embedded code automatically.

Sounds a wonderful idea. But after I read the guidelines about becoming a provider, things seem to get hard, considering emgithub.com is hosted on GitHub Pages, i.e., a totally static website.

To be specific, they use the oembed protocol. And to implement this, the provider must be able to respond with dynamic content in JSON or XML format.

An example: curl "https://www.youtube.com/oembed?url=https%3A//youtube.com/watch%3Fv%3DM3r2XDceM6A&format=json" will output:

{"title":"Amazing Nintendo Facts","author_name":"ZackScott","author_url":"https:
//www.youtube.com/c/ZackScott","type":"video","height":113,"width":200,"version"
:"1.0","provider_name":"YouTube","provider_url":"https://www.youtube.com/","thum
bnail_height":360,"thumbnail_width":480,"thumbnail_url":"https://i.ytimg.com/vi/
M3r2XDceM6A/hqdefault.jpg","html":"\u003ciframe width=\u0022200\u0022 height=\u0
022113\u0022 src=\u0022https://www.youtube.com/embed/M3r2XDceM6A?feature=oembed\
u0022 frameborder=\u00220\u0022 allow=\u0022accelerometer; autoplay; clipboard-w
rite; encrypted-media; gyroscope; picture-in-picture\u0022 allowfullscreen title
=\u0022Amazing Nintendo Facts\u0022\u003e\u003c/iframe\u003e"}

However, GitHub Pages is a static site hosting service and can not respond dynamically. So something like requesting emgithub.com/oembed?url=github.com/pytorch/pytorch/blob/master/torch/nn/cpp.py and getting a dynamically generated JSON is not possible.

yusanshi avatar Jul 18 '22 12:07 yusanshi

If emgithub.com got dynamic, a server will be needed. Then the hardware may need upgrading if the site traffic goes high. It gets easier to be attacked. And of course, it costs money.

So currently I have no plan to make it dynamic.

I'll keep the issue open and mark it as "help wanted", in case I was wrong about how oembed works and someone got a solution to make it possible with GitHub Pages.

yusanshi avatar Jul 18 '22 12:07 yusanshi

I'm not sure about responding with Dynamic results ... but if you want to respond with some logic in the backend, I recommend using the AWS Lambda Serverless functions. They're super cheap (almost free I would say) and easy to set up.

weeping-angel avatar Jul 18 '22 15:07 weeping-angel

Thanks for the suggestion. I'll take a look once get some free time...

yusanshi avatar Jul 18 '22 16:07 yusanshi