mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 05:23:39 +08:00
First stab at oneboxing of meta.discourse.org
This commit is contained in:
parent
53d8e49a5d
commit
908bba8c13
BIN
app/assets/images/favicons/discourse.png
Normal file
BIN
app/assets/images/favicons/discourse.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 561 B |
|
@ -36,7 +36,7 @@ module ApplicationHelper
|
||||||
def crawlable_meta_data(opts=nil)
|
def crawlable_meta_data(opts=nil)
|
||||||
|
|
||||||
opts ||= {}
|
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}"
|
opts[:url] ||= "#{Discourse.base_url}#{request.fullpath}"
|
||||||
|
|
||||||
# Add opengraph tags
|
# Add opengraph tags
|
||||||
|
@ -45,8 +45,8 @@ module ApplicationHelper
|
||||||
result << tag(:meta, property: 'twitter:card', content: "summary")
|
result << tag(:meta, property: 'twitter:card', content: "summary")
|
||||||
[:image, :url, :title, :description].each do |property|
|
[:image, :url, :title, :description].each do |property|
|
||||||
if opts[property].present?
|
if opts[property].present?
|
||||||
result << tag(:meta, property: "og:#{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]) << "\n"
|
result << tag(:meta, {property: "twitter:#{property}", content: opts[property]}, nil, false) << "\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -320,6 +320,11 @@ class User < ActiveRecord::Base
|
||||||
"https://www.gravatar.com/avatar/#{email_hash}.png?s={size}&r=pg&d=identicon"
|
"https://www.gravatar.com/avatar/#{email_hash}.png?s={size}&r=pg&d=identicon"
|
||||||
end
|
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
|
# return null for local avatars, a template for gravatar
|
||||||
def avatar_template
|
def avatar_template
|
||||||
User.avatar_template(email)
|
User.avatar_template(email)
|
||||||
|
|
|
@ -24,5 +24,7 @@
|
||||||
|
|
||||||
<% content_for :head do %>
|
<% 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') %>
|
<%= 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 %>
|
<% end %>
|
||||||
|
|
|
@ -5,5 +5,5 @@
|
||||||
<p><%= t 'powered_by_html' %></p>
|
<p><%= t 'powered_by_html' %></p>
|
||||||
|
|
||||||
<% content_for :head do %>
|
<% 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 %>
|
<% end %>
|
||||||
|
|
|
@ -2,7 +2,7 @@ require_dependency 'oneboxer/oembed_onebox'
|
||||||
require_dependency 'freedom_patches/rails4'
|
require_dependency 'freedom_patches/rails4'
|
||||||
|
|
||||||
module Oneboxer
|
module Oneboxer
|
||||||
class DiscourseOnebox < BaseOnebox
|
class DiscourseLocalOnebox < BaseOnebox
|
||||||
include ActionView::Helpers::DateHelper
|
include ActionView::Helpers::DateHelper
|
||||||
|
|
||||||
matcher do
|
matcher do
|
22
lib/oneboxer/discourse_remote_onebox.rb
Normal file
22
lib/oneboxer/discourse_remote_onebox.rb
Normal 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
|
|
@ -79,6 +79,11 @@ class TopicView
|
||||||
Summarize.new(posts.first.cooked).summary
|
Summarize.new(posts.first.cooked).summary
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def image_url
|
||||||
|
return nil if posts.blank?
|
||||||
|
posts.first.user.small_avatar_url
|
||||||
|
end
|
||||||
|
|
||||||
def filter_posts(opts = {})
|
def filter_posts(opts = {})
|
||||||
if opts[:post_number].present?
|
if opts[:post_number].present?
|
||||||
# Get posts near a post
|
# Get posts near a post
|
||||||
|
|
Loading…
Reference in New Issue
Block a user