Embedding a book from Google Books

AI 生成的摘要

Embedding a Book from Google Books

tophee is looking for a way to embed a Google Books preview into Discourse. Google Books offers a plain link and an iframe, but neither works out of the box. tophee considers using the whitelist-iframe plugin to whitelist google.books.com.

dax suggests looking at the integration on discussbook.com and its source code, which uses JavaScript and the Google Books API library. tophee is interested in this approach, but notes that the previews don’t work.

tophee successfully uses the whitelist-iframe plugin to embed Google Books previews. Shortly after, dax announces the release of the Google Books Plugin for Discourse integration.

tophee reveals that they had customizations made for the plugin, indicating a potential solution for embedding Google Books previews in Discourse.

What’s the best practice for embedding an book preview from Google Books?

Google books provides both a plain link and an iframe, but neither of them work out of the box:

By “don’t work” I mean they don’t give me a onebox when pasted into discourse.

The only solution I see at the moment is to whitelist google.books.com using @simon’s whitelist-iframe plugin. Is this the best/only way forward?

Take a look here https://discussbook.com/ and here view-source:https://discussbook.com/assets/plugin-third-party-6ae2c6dcefb0b7bf8b18b7b7f6c91a8882c9cde5f35e429cf3c2cb85fe77e855.js .

I think that site add a js script and a script src to include the API library Developer's Guide  |  Google Books APIs  |  Google for Developers

That books integration looks fascinating (though the previews don’t seem to work, I just get an empty lightbox). What I had in mind was oneboxing the preview, but this might also work (when it works), maybe even better.

I will have to look into that source code later to see what in those 1383 lines is relevant here (I am not a programmer).

Are you saying that the whole integration is done only via JS, no discourse plugin?

I’m not sure, but you can ask to @net_deamon (see Discussbook on discourse, anybody interested? Not paid, but collaboration).

If he wrote a plugin you can ask him to share it

I have successfully added google books to the iframe whitelist using the whitelist-iframe plugin. :tada: and it works just perfectly when pasting the iframe code that google books provides by default.

A plugin has been released today:

I know, I ordered some customizations for it :stuck_out_tongue_winking_eye: