diff --git a/app/assets/javascripts/discourse/templates/post.js.handlebars b/app/assets/javascripts/discourse/templates/post.js.handlebars index 861e0184162..2e8212f3e43 100644 --- a/app/assets/javascripts/discourse/templates/post.js.handlebars +++ b/app/assets/javascripts/discourse/templates/post.js.handlebars @@ -76,9 +76,9 @@
{{{cooked}}}
{{#if view.showExpandButton}} {{#if controller.loadingExpanded}} - + {{else}} - + {{/if}} {{/if}} {{view Discourse.PostMenuView postBinding="this" postViewBinding="view"}} diff --git a/app/assets/stylesheets/desktop/topic-post.scss b/app/assets/stylesheets/desktop/topic-post.scss index 453678f72bb..e06d4dcdaa5 100644 --- a/app/assets/stylesheets/desktop/topic-post.scss +++ b/app/assets/stylesheets/desktop/topic-post.scss @@ -413,6 +413,9 @@ span.post-count { opacity: .8; } +button.expand-post { + margin-top: 10px; +} #topic-footer-buttons { .btn { diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index c313de95d3f..3176379223a 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -147,8 +147,9 @@ class PostsController < ApplicationController post = find_post_from_params content = Rails.cache.fetch("embed-topic:#{post.topic_id}", expires_in: 10.minutes) do url = TopicEmbed.where(topic_id: post.topic_id).pluck(:embed_url).first - doc = TopicEmbed.find_remote(url) - doc.content + title, body = TopicEmbed.find_remote(url) + body << TopicEmbed.imported_from_html(url) + body end render json: {cooked: content} rescue diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rb index afa912ae72d..7321b32f0ad 100644 --- a/app/models/topic_embed.rb +++ b/app/models/topic_embed.rb @@ -10,6 +10,10 @@ class TopicEmbed < ActiveRecord::Base url.downcase.sub(/\/$/, '').sub(/\-+/, '-') end + def self.imported_from_html(url) + "\n
\n#{I18n.t('embed.imported_from', link: "#{url}")}\n" + end + # Import an article from a source (RSS/Atom/Other) def self.import(user, url, title, contents) return unless url =~ /^https?\:\/\// @@ -17,7 +21,7 @@ class TopicEmbed < ActiveRecord::Base if SiteSetting.embed_truncate contents = first_paragraph_from(contents) end - contents << "\n
\n#{I18n.t('embed.imported_from', link: "#{url}")}\n" + contents << imported_from_html(url) url = normalize_url(url) @@ -60,15 +64,35 @@ class TopicEmbed < ActiveRecord::Base require 'ruby-readability' url = normalize_url(url) - Readability::Document.new(open(url).read, - tags: %w[div p code pre h1 h2 h3 b em i strong a img ul li ol], - attributes: %w[href src]) + original_uri = URI.parse(url) + doc = Readability::Document.new(open(url).read, + tags: %w[div p code pre h1 h2 h3 b em i strong a img ul li ol blockquote], + attributes: %w[href src], + remove_empty_nodes: false) + + tags = {'img' => 'src', 'script' => 'src', 'a' => 'href'} + title = doc.title + doc = Nokogiri::HTML(doc.content) + doc.search(tags.keys.join(',')).each do |node| + url_param = tags[node.name] + src = node[url_param] + unless (src.empty?) + uri = URI.parse(src) + unless uri.host + uri.scheme = original_uri.scheme + uri.host = original_uri.host + node[url_param] = uri.to_s + end + end + end + + [title, doc.to_html] end def self.import_remote(user, url, opts=nil) opts = opts || {} - doc = find_remote(url) - TopicEmbed.import(user, url, opts[:title] || doc.title, doc.content) + title, body = find_remote(url) + TopicEmbed.import(user, url, opts[:title] || title, body) end # Convert any relative URLs to absolute. RSS is annoying for this.