First stab at oneboxing of meta.discourse.org

This commit is contained in:
Robin Ward 2013-03-08 15:58:37 -05:00
parent 53d8e49a5d
commit 908bba8c13
8 changed files with 40 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 561 B

View File

@ -36,7 +36,7 @@ module ApplicationHelper
def crawlable_meta_data(opts=nil)
opts ||= {}
opts[:image] ||= "#{Discourse.base_url}#{SiteSetting.logo_url}"
opts[:image] ||= "#{Discourse.base_url}#{SiteSetting.logo_small_url}"
opts[:url] ||= "#{Discourse.base_url}#{request.fullpath}"
# Add opengraph tags
@ -45,8 +45,8 @@ module ApplicationHelper
result << tag(:meta, property: 'twitter:card', content: "summary")
[:image, :url, :title, :description].each do |property|
if opts[property].present?
result << tag(:meta, property: "og:#{property}", content: opts[property]) << "\n"
result << tag(:meta, property: "twitter:#{property}", content: opts[property]) << "\n"
result << tag(:meta, {property: "og:#{property}", content: opts[property]}, nil, false) << "\n"
result << tag(:meta, {property: "twitter:#{property}", content: opts[property]}, nil, false) << "\n"
end
end

View File

@ -320,6 +320,11 @@ class User < ActiveRecord::Base
"https://www.gravatar.com/avatar/#{email_hash}.png?s={size}&r=pg&d=identicon"
end
# Don't pass this up to the client - it's meant for server side use
def small_avatar_url
"https://www.gravatar.com/avatar/#{email_hash}.png?s=50&r=pg&d=identicon"
end
# return null for local avatars, a template for gravatar
def avatar_template
User.avatar_template(email)

View File

@ -24,5 +24,7 @@
<% content_for :head do %>
<%= 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 %>

View File

@ -5,5 +5,5 @@
<p><%= t 'powered_by_html' %></p>
<% 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 %>

View File

@ -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

View File

@ -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

View File

@ -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