preaction / Statocles

Static website CMS
http://preaction.me/statocles
Other
84 stars 33 forks source link

Add OEmbed consumer plugin #519

Open preaction opened 7 years ago

preaction commented 7 years ago

oEmbed is an open standard for embedding third-party content on a page. It is supported by many sites including Flickr, Instagram, Meetup, Reddit, Codepen, SoundCloud, WordPress.com, Twitch, Vimeo, and YouTube. It would be nice if we could consume oEmbed content from these providers with a simple syntax.

The simplest possibility is to create a new plugin, Statocles::Plugin::OEmbed, that provides a single template helper function, oembed. This template helper function should take a single argument, the URL to embed. The plugin should determine if the URL is an oEmbed-capable resource (see section 4, Discovery, of the oEmbed website), and, if it is, request the oEmbed content from the site and write it to the page.

If the URL does not appear to oEmbed-enabled, or there is any other problem with loading the URL, a warning should be written to the log and a link to the content inserted in its place.

There exists a CPAN module to load this content already, Web::oEmbed, but it uses LWP and we already have Mojo::UserAgent. I would prefer a solution that uses Mojo::UserAgent and keeps multiple requests in-flight at once, for performance reasons.

The plugin should make every attempt to cache the content of requests it makes, so as to speed up rebuilding of the site. Cached content should be stored in the directory .statocles/cache/plugin/OEmbed/. If cached content exists, we should follow the HTTP caching rules provided by the content: Revalidating if requested, expiring if necessary, processing 304 Not Modified responses as appropriate. This caching convention will eventually be factored out into helper methods in Statocles::Plugin that all plugins will have.