TopGit theo dõi discourse/onebox trên GitHub, đã đạt 791 sao. (DEPRECATED) A gem for turning URLs into website previews
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
:warning: This project isn't maintained anymore as the onebox library has moved into core repository. If you wish to help by maintaining the project please contact [email protected].
onebox
Onebox is a library for turning media URLs into simple HTML previews of the resource.
Onebox currently has support for page, image, and video URLs for many popular sites.
It's great if you want users to input URLs and have your application convert them into
rich previews for display. For example, a link to a YouTube video would be automatically
converted into a video player.
It was originally created for Discourse but has since been
extracted into this convenient gem for all to use!
Usage
Using onebox is fairly simple!
First, make sure the library is required:
This will contain a simple Onebox::Preview object that handles all the transformation.
From here you either call Onebox::Preview#to_s or just pass the object to a string:
The onebox library is supported on all "officially" supported versions of Ruby.
This means you must be on Ruby 2.4 or above for it to work.
Development Preview Interface
The onebox gem comes with a development server for previewing the results
of your changes. You can run it by running bundle exec rake server after checking
out the project. You can then try out URLs.
The server doesn't reload code changes automatically (PRs accepted!) so
make sure to hit CTRL-C and restart the server to try a code change out.
Adding Support for a new URL
Check if the site supports oEmbed or Open Graph.
If it does, you can probably get away with just allowing the URL in Onebox::Engine::AllowlistedGenericOnebox (see: Allowlisted Generic Onebox caveats).
If the site does not support open standards, you can create a new engine.
Create new onebox engine
# in lib/onebox/engine/name_onebox.rb
module Onebox
module Engine
class NameOnebox
include LayoutSupport
include HTML
private
def data
{
url: @url,
name: raw.css("h1").inner_text,
image: raw.css("#main-image").first["src"],
description: raw.css("#postBodyPS").inner_text
}
end
end
end
end
Create new onebox spec using FakeWeb
# in spec/lib/onebox/engine/name_spec.rb
require "spec_helper"
describe Onebox::Engine::NameOnebox do
let(:link) { "http://example.com" }
let(:html) { described_class.new(link).to_html }
before do
fake(link, response("name"))
end
it "has the video's title" do
expect(html).to include("title")
end
it "has the video's still shot" do
expect(html).to include("photo.jpg")
end
it "has the video's description" do
expect(html).to include("description")
end
it "has the URL to the resource" do
expect(html).to include(link)
end
end
Create new fixture from HTML response for your FakeWeb request(s)
curl --output spec/fixtures/oneboxname.response -L -X GET http://example.com
Require in Engine module
# in lib/onebox/engine.rb
require_relative "engine/name_onebox"
Allowlisted Generic Onebox caveats
The Allowlisted Generic Onebox has some caveats for its use, beyond simply allowlisting the domain.
The domain must be allowlisted
The URL you're oneboxing cannot be a root url (e.g. http://example.com won't work, but http://example.com/page will)
If the oneboxed URL responds with oEmbed and has a rich type: the html content must contain an <iframe>. Responses without an iframe will not be oneboxed.
Ignoring Canonical URLs
Onebox 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.
discourse/onebox có 791 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/discourse/onebox. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
discourse/onebox có phải mã nguồn mở không?
Có — discourse/onebox phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/discourse/onebox.
discourse/onebox còn đang phát triển không?
Commit gần nhất trên discourse/onebox là 2.5 năm trước (theo timestamp GitHub). Repo có 158 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
discourse/onebox dùng license gì?
discourse/onebox phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
discourse/onebox là gì?
discourse/onebox (discourse/onebox) là dự án Ruby trên GitHub. Theo mô tả gốc: (DEPRECATED) A gem for turning URLs into website previews
discourse/onebox viết bằng ngôn ngữ gì?
discourse/onebox chủ yếu viết bằng Ruby. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc thêm về discourse/onebox ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/discourse/onebox là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
onebox có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về onebox.