From 908bba8c133edc357d2bfe8da7dd23d23fd59e6b Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 8 Mar 2013 15:58:37 -0500 Subject: [PATCH] First stab at oneboxing of meta.discourse.org --- app/assets/images/favicons/discourse.png | Bin 0 -> 561 bytes app/helpers/application_helper.rb | 6 ++--- app/models/user.rb | 5 ++++ app/views/topics/show.html.erb | 4 +++- app/views/users/show.html.erb | 2 +- ...se_onebox.rb => discourse_local_onebox.rb} | 2 +- lib/oneboxer/discourse_remote_onebox.rb | 22 ++++++++++++++++++ lib/topic_view.rb | 5 ++++ 8 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 app/assets/images/favicons/discourse.png rename lib/oneboxer/{discourse_onebox.rb => discourse_local_onebox.rb} (98%) create mode 100644 lib/oneboxer/discourse_remote_onebox.rb diff --git a/app/assets/images/favicons/discourse.png b/app/assets/images/favicons/discourse.png new file mode 100644 index 0000000000000000000000000000000000000000..4795da14fb99fb6ac0d84fd29c0e72404765dcce GIT binary patch literal 561 zcmV-10?z%3P)F-Gy-1#2%+&2-cjrp@mwwqF7528blPA=;WxuF8&i%9h|y2I7^)!A_z{B zKy}kJP#qi&?kH+&HN9YCf0*1k*t@1727IRH{l3rhd7tO|3VOoInKp0>uz}fqxeC;Q z$ByT^-SwiYQ3sv^*L$Ho@xbxi`_Vz}YOX{trhutXa4D2X0}TOt2Y^{a*UinQ{~`t$ zy8a5d08k1f7CJIlPYBMR6kItfD9RFv9l>%KMiAT3b+Os>tHR2exA#Y<6iD3BB-FD> zw7DY6EQ8=tM@E}Yl6rU-<;*A|k%%jme3l>6 zd7iDcP@QkFE=8tY3O zOTF2^Z|6a}$?zMGW95aI>v(QmSUEF <%= auto_discovery_link_tag(@topic_view, {action: :feed, format: :rss}, title: t('rss_posts_in_topic', topic: @topic_view.title), type: 'application/rss+xml') %> - <%= crawlable_meta_data(title: @topic_view.title, description: @topic_view.summary) %> + <%= crawlable_meta_data(title: @topic_view.title, + description: @topic_view.summary, + image: @topic_view.image_url) %> <% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 169bd2dc393..fdfee589790 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -5,5 +5,5 @@

<%= t 'powered_by_html' %>

<% content_for :head do %> - <%= crawlable_meta_data(title: @user.username, description: @user.bio_summary) %> + <%= crawlable_meta_data(title: @user.username, description: @user.bio_summary, image: @user.small_avatar_url) %> <% end %> diff --git a/lib/oneboxer/discourse_onebox.rb b/lib/oneboxer/discourse_local_onebox.rb similarity index 98% rename from lib/oneboxer/discourse_onebox.rb rename to lib/oneboxer/discourse_local_onebox.rb index 8933f883d87..5fd7b2c694d 100644 --- a/lib/oneboxer/discourse_onebox.rb +++ b/lib/oneboxer/discourse_local_onebox.rb @@ -2,7 +2,7 @@ require_dependency 'oneboxer/oembed_onebox' require_dependency 'freedom_patches/rails4' module Oneboxer - class DiscourseOnebox < BaseOnebox + class DiscourseLocalOnebox < BaseOnebox include ActionView::Helpers::DateHelper matcher do diff --git a/lib/oneboxer/discourse_remote_onebox.rb b/lib/oneboxer/discourse_remote_onebox.rb new file mode 100644 index 00000000000..34e2c90de5b --- /dev/null +++ b/lib/oneboxer/discourse_remote_onebox.rb @@ -0,0 +1,22 @@ +require_dependency 'oneboxer/oembed_onebox' +require_dependency 'freedom_patches/rails4' + +module Oneboxer + class DiscourseRemoteOnebox < HandlebarsOnebox + + matcher /^https?\:\/\/meta\.discourse\.org\/.*$/ + favicon 'discourse.png' + + def template + template_path('simple_onebox') + end + + def parse(data) + doc = Nokogiri::HTML(data) + open_graph = Oneboxer.parse_open_graph(doc) + open_graph['text'] = open_graph['description'] + open_graph + end + + end +end diff --git a/lib/topic_view.rb b/lib/topic_view.rb index 8883fe307ce..768554feb87 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -79,6 +79,11 @@ class TopicView Summarize.new(posts.first.cooked).summary end + def image_url + return nil if posts.blank? + posts.first.user.small_avatar_url + end + def filter_posts(opts = {}) if opts[:post_number].present? # Get posts near a post