{"id":13395076,"url":"https://github.com/discourse/onebox","last_synced_at":"2025-05-14T15:05:49.238Z","repository":{"id":423674,"uuid":"11273069","full_name":"discourse/onebox","owner":"discourse","description":"(DEPRECATED) A gem for turning URLs into website previews","archived":false,"fork":false,"pushed_at":"2024-02-01T14:15:14.000Z","size":5707,"stargazers_count":793,"open_issues_count":0,"forks_count":163,"subscribers_count":45,"default_branch":"main","last_synced_at":"2025-04-19T13:16:30.529Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/discourse/onebox","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/discourse.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-09T04:44:38.000Z","updated_at":"2024-12-18T02:34:24.000Z","dependencies_parsed_at":"2024-06-18T13:58:20.175Z","dependency_job_id":null,"html_url":"https://github.com/discourse/onebox","commit_stats":{"total_commits":1586,"total_committers":105,"mean_commits":"15.104761904761904","dds":0.7938209331651954,"last_synced_commit":"a40aabdffe51d35d6a715b92776dc8be97f34dc3"},"previous_names":[],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discourse%2Fonebox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discourse%2Fonebox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discourse%2Fonebox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discourse%2Fonebox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/discourse","download_url":"https://codeload.github.com/discourse/onebox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253720643,"owners_count":21953094,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T17:01:41.192Z","updated_at":"2025-05-14T15:05:49.194Z","avatar_url":"https://github.com/discourse.png","language":"Ruby","funding_links":[],"categories":["Ruby","Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# :warning: This project isn't maintained anymore as the onebox library has [moved into core repository](https://github.com/discourse/discourse/tree/main/lib/onebox). If you wish to help by maintaining the project please contact sam.saffron@discourse.org.\n\nonebox\n======\n\n[![Gem Version](https://badge.fury.io/rb/onebox.svg)](https://rubygems.org/gems/onebox)\n[![Code Climate](https://codeclimate.com/github/dysania/onebox.svg)](https://codeclimate.com/github/dysania/onebox)\n[![Build Status](https://travis-ci.org/discourse/onebox.svg)](https://travis-ci.org/discourse/onebox)\n\nOnebox is a library for turning media URLs into simple HTML previews of the resource.\n\nOnebox currently has support for page, image, and video URLs for many popular sites.\n\nIt's great if you want users to input URLs and have your application convert them into\nrich previews for display. For example, a link to a YouTube video would be automatically\nconverted into a video player.\n\nIt was originally created for [Discourse](http://discourse.org) but has since been\nextracted into this convenient gem for all to use!\n\nUsage\n-----\n\nUsing onebox is fairly simple!\nFirst, make sure the library is required:\n\n``` ruby\nrequire \"onebox\"\n```\n\nThen pass a link to the library's interface:\n\n``` ruby\nrequire \"onebox\"\n\nurl = \"http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2\"\npreview = Onebox.preview(url)\n```\n\nThis will contain a simple Onebox::Preview object that handles all the transformation.\nFrom here you either call `Onebox::Preview#to_s` or just pass the object to a string:\n\n``` ruby\nrequire \"onebox\"\n\nurl = \"http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2\"\npreview = Onebox.preview(url)\n\"#{preview}\" == preview.to_s #=\u003e true\n```\n\n### Twitch Onebox\n\nTo be able to embed Twitch video and clips, pass `hostname` in the options to `Onebox.preview`\n\n```ruby\npreview = Onebox.preview(url, hostname: 'www.example.com')\n```\n\nRuby Support\n------------\n\nThe onebox library is supported on all \"officially\" supported versions of Ruby.\n\nThis means you must be on Ruby 2.4 or above for it to work.\n\nDevelopment Preview Interface\n-----------------------------\n\nThe onebox gem comes with a development server for previewing the results\nof your changes. You can run it by running `bundle exec rake server` after checking\nout the project. You can then try out URLs.\n\nThe server doesn't reload code changes automatically (PRs accepted!) so\nmake sure to hit CTRL-C and restart the server to try a code change out.\n\nAdding Support for a new URL\n----------------------------\n\n  1. Check if the site supports [oEmbed](http://oembed.com/) or [Open Graph](https://developers.facebook.com/docs/opengraph/).\n     If it does, you can probably get away with just allowing the URL in `Onebox::Engine::AllowlistedGenericOnebox` (see: [Allowlisted Generic Onebox caveats](#user-content-allowlisted-generic-onebox-caveats)).\n     If the site does not support open standards, you can create a new engine.\n\n  2. Create new onebox engine\n\n     ``` ruby\n     # in lib/onebox/engine/name_onebox.rb\n\n     module Onebox\n       module Engine\n         class NameOnebox\n           include LayoutSupport\n           include HTML\n\n           private\n\n           def data\n             {\n               url: @url,\n               name: raw.css(\"h1\").inner_text,\n               image: raw.css(\"#main-image\").first[\"src\"],\n               description: raw.css(\"#postBodyPS\").inner_text\n             }\n           end\n         end\n       end\n     end\n     ```\n\n  3. Create new onebox spec using [FakeWeb](https://github.com/chrisk/fakeweb)\n\n     ``` ruby\n     # in spec/lib/onebox/engine/name_spec.rb\n     require \"spec_helper\"\n\n     describe Onebox::Engine::NameOnebox do\n       let(:link) { \"http://example.com\" }\n       let(:html) { described_class.new(link).to_html }\n\n       before do\n         fake(link, response(\"name\"))\n       end\n\n       it \"has the video's title\" do\n         expect(html).to include(\"title\")\n       end\n\n       it \"has the video's still shot\" do\n         expect(html).to include(\"photo.jpg\")\n       end\n\n       it \"has the video's description\" do\n         expect(html).to include(\"description\")\n       end\n\n       it \"has the URL to the resource\" do\n         expect(html).to include(link)\n       end\n     end\n     ```\n\n  4. Create new mustache template\n\n     ``` html\n     # in templates/name.mustache\n     \u003cdiv class=\"onebox\"\u003e\n       \u003ca href=\"{{url}}\"\u003e\n         \u003ch1\u003e{{name}}\u003c/h1\u003e\n         \u003ch2 class=\"host\"\u003eexample.com\u003c/h2\u003e\n         \u003cimg src=\"{{image}}\" /\u003e\n         \u003cp\u003e{{description}}\u003c/p\u003e\n       \u003c/a\u003e\n     \u003c/div\u003e\n     ```\n\n  5. Create new fixture from HTML response for your FakeWeb request(s)\n\n     ``` bash\n     curl --output spec/fixtures/oneboxname.response -L -X GET http://example.com\n     ```\n\n  6. Require in Engine module\n\n     ``` ruby\n     # in lib/onebox/engine.rb\n     require_relative \"engine/name_onebox\"\n     ```\n\nAllowlisted Generic Onebox caveats\n----------------------------------\n\nThe Allowlisted Generic Onebox has some caveats for its use, beyond simply allowlisting the domain.\n\n  1. The domain must be allowlisted\n  2. The URL you're oneboxing cannot be a root url (e.g. `http://example.com` won't work, but `http://example.com/page` will)\n  3. If the oneboxed URL responds with oEmbed and has a `rich` type: the `html` content must contain an `\u003ciframe\u003e`. Responses without an iframe will not be oneboxed.\n\nIgnoring Canonical URLs\n-----------------------\n\nOnebox prefers to use canonical URLs instead of the raw inputted URL when searching for Open Graph metadata. If your site's canonical URL does not have opengraph metadata, use the `og:ignore_canonical` property to have Onebox ignore the canonical URL.\n\n```html\n\u003cmeta property=\"og:ignore_canonical\" content=\"true\" /\u003e\n```\n\nInstalling\n----------\n\nAdd this line to your application's Gemfile:\n\n    gem \"onebox\"\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install onebox\n\n\nIssues / Discussion\n-------------------\n\nDiscussion of the Onebox gem, its development and features should be done on\n[Discourse Meta](https://meta.discourse.org).\n\nContributing\n------------\n\n  1. Fork it\n  2. Create your feature branch (`git checkout -b my-new-feature`)\n  3. Commit your changes (`git commit -am 'Add some feature'`)\n  4. Push to the branch (`git push origin my-new-feature`)\n  5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscourse%2Fonebox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiscourse%2Fonebox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscourse%2Fonebox/lists"}