mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Show more context in Discourse topic oneboxes
Currently when generating a onebox for Discourse topics, some important context is missing such as categories and tags. This patch addresses this issue by introducing a new onebox engine dedicated to display this information when available. Indeed to get this new information, categories and tags are exposed in the topic metadata as opengraph tags.
This commit is contained in:
committed by
Loïc Guitaut
parent
d2e9ea6193
commit
14d97f9cf1
51
spec/lib/onebox/engine/discourse_topic_onebox_spec.rb
Normal file
51
spec/lib/onebox/engine/discourse_topic_onebox_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Onebox::Engine::DiscourseTopicOnebox do
|
||||
subject(:onebox) { described_class.new(url) }
|
||||
|
||||
describe "#data" do
|
||||
subject(:data) { onebox.data }
|
||||
|
||||
let(:url) do
|
||||
"https://meta.discourse.org/t/congratulations-most-stars-in-2013-github-octoverse/12483"
|
||||
end
|
||||
let(:expected_data) do
|
||||
{
|
||||
article_published_time: "6 Feb 14",
|
||||
article_published_time_title: "04:55AM - 06 February 2014",
|
||||
article_tags: %w[how-to sso],
|
||||
card: "summary",
|
||||
categories: [{ name: "praise", color: "9EB83B" }],
|
||||
data1: "1 mins 🕑",
|
||||
data2: "9 ❤",
|
||||
description:
|
||||
"Congratulations Discourse for qualifying Repositories with the most stars on GitHub Octoverse. And that too in just over an year, way to go! 💥",
|
||||
domain: "Discourse Meta",
|
||||
favicon:
|
||||
"https://d11a6trkgmumsb.cloudfront.net/optimized/3X/b/3/b33be9538df3547fcf9d1a51a4637d77392ac6f9_2_32x32.png",
|
||||
ignore_canonical: "true",
|
||||
image:
|
||||
"https://d11a6trkgmumsb.cloudfront.net/optimized/2X/d/d063b3b0807377d98695ee08042a9ba0a8c593bd_2_690x362.png",
|
||||
label1: "Reading time",
|
||||
label2: "Likes",
|
||||
link:
|
||||
"https://meta.discourse.org/t/congratulations-most-stars-in-2013-github-octoverse/12483",
|
||||
published_time: "2014-02-06T04:55:19+00:00",
|
||||
render_category_block?: true,
|
||||
render_tags?: true,
|
||||
site_name: "Discourse Meta",
|
||||
title: "Congratulations, most stars in 2013 GitHub Octoverse!",
|
||||
url:
|
||||
"https://meta.discourse.org/t/congratulations-most-stars-in-2013-github-octoverse/12483",
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
stub_request(:get, url).to_return(status: 200, body: onebox_response("discourse_topic"))
|
||||
end
|
||||
|
||||
it "returns the expected data" do
|
||||
expect(data).to include expected_data
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -24,4 +24,32 @@ RSpec.describe Onebox::OpenGraph do
|
||||
og = described_class.new(doc)
|
||||
expect(og.image).to eq("http://test.com/test'ing.mp3")
|
||||
end
|
||||
|
||||
describe "Collections" do
|
||||
subject(:graph) { described_class.new(doc) }
|
||||
|
||||
let(:doc) { Nokogiri.HTML(<<-HTML) }
|
||||
<html>
|
||||
<title>test</title>
|
||||
<meta property="og:article:tag" content="<b>tag1</b>" />
|
||||
<meta property="og:article:tag" content="tag2" />
|
||||
<meta property="og:article:section" content="category1" />
|
||||
<meta property="og:article:section" content="category2" />
|
||||
<meta property="og:article:section:color" content="ff0000" />
|
||||
<meta property="og:article:section:color" content="0000ff" />
|
||||
</html>
|
||||
HTML
|
||||
|
||||
it "handles multiple article:tag tags" do
|
||||
expect(graph.article_tags).to eq %w[tag1 tag2]
|
||||
end
|
||||
|
||||
it "handles multiple article:section tags" do
|
||||
expect(graph.article_sections).to eq %w[category1 category2]
|
||||
end
|
||||
|
||||
it "handles multiple article:section:color tags" do
|
||||
expect(graph.article_section_colors).to eq %w[ff0000 0000ff]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user