From 248683576b2264dea5fdc7e5994d2c695aef43c7 Mon Sep 17 00:00:00 2001 From: Sidharth Date: Sat, 3 Feb 2018 13:16:45 +0530 Subject: [PATCH 1/3] RSS for Tag with image correction --- app/controllers/tag_controller.rb | 7 +++-- app/views/tag/rss.rss.builder | 29 +++++++++++-------- .../rss_for_tagged_with_author.rss.builder | 8 ++--- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/app/controllers/tag_controller.rb b/app/controllers/tag_controller.rb index 670c9a929e..6a3a3ab9cc 100644 --- a/app/controllers/tag_controller.rb +++ b/app/controllers/tag_controller.rb @@ -347,9 +347,10 @@ def rss end def rss_for_tagged_with_author - @user = User.find_by(name: params[:author]) - @notes = Tag.tagged_nodes_by_author([params[:tagname]], @user) - .limit(20) + @user = User.find_by(name: params[:authorname]) + @notes = Tag.tagged_nodes_by_author(params[:tagname], @user) + .where(status: 1) + .limit(20) respond_to do |format| format.rss do response.headers['Content-Type'] = 'application/xml; charset=utf-8' diff --git a/app/views/tag/rss.rss.builder b/app/views/tag/rss.rss.builder index 97cf7cc3f1..9391a2af6f 100644 --- a/app/views/tag/rss.rss.builder +++ b/app/views/tag/rss.rss.builder @@ -1,19 +1,22 @@ -xml.instruct! :xml, :version => "1.0" -xml.rss :version => "2.0" do +xml.rss :version => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom' do xml.channel do xml.title "Research tagged '#{params[:tagname]}'" xml.description "Open source environmental science research at Public Lab" xml.link "https://#{request.host}/feed/tag/"+params[:tagname]+".rss" @notes.each do |node| - + body = node.body - body = "
"+node.body if node.main_image - - xml.item do - xml.title node.title - xml.author node.author.name - if node.power_tag('date') != '' + uname = node.author.username + email = node.author.email + if node.author.user.has_power_tag('twitter') + uname = node.author.user.get_value_of_power_tag('twitter') + end + author_format = "@#{uname} (#{email})" + xml.item do + xml.title " #{node.title}" + xml.author author_format + if node.power_tag('date') != '' begin xml.pubDate DateTime.strptime(node.power_tag('date'), "%m-%d-%Y").rfc822 rescue @@ -22,10 +25,12 @@ xml.rss :version => "2.0" do else xml.pubDate node.created_at.to_s(:rfc822) end - #xml.link url_for :only_path => false, :controller => 'notes', :action => 'show', :id => node.nid xml.link "https://" + request.host.to_s + node.path - #xml.image "//#{ request.host }/"+node.main_image.path(:default) if node.main_image - xml.description auto_link(node.latest.render_body, :sanitize => false) + if node.main_image + xml.description { xml.cdata!("#{node.main_image.title}

#{auto_link(node.latest.render_body, :sanitize => false)}

") } + else + xml.description { xml.cdata!("PublicLab

#{auto_link(node.latest.render_body, :sanitize => false)}

") } + end xml.guid url_for :only_path => false, :controller => 'notes', :action => 'show', :id => node.nid end end diff --git a/app/views/tag/rss_for_tagged_with_author.rss.builder b/app/views/tag/rss_for_tagged_with_author.rss.builder index 38c83fe523..491a056903 100644 --- a/app/views/tag/rss_for_tagged_with_author.rss.builder +++ b/app/views/tag/rss_for_tagged_with_author.rss.builder @@ -1,8 +1,8 @@ xml.rss :version => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom' do xml.channel do - xml.title "Research tagged '#{params[:tagname]}' by #{params[:authorname]}" + xml.title "Research tagged '#{params[:tagname]}' by '#{params[:authorname]}'" xml.description "Open source environmental science research at Public Lab" - xml.link "https://#{request.host}/feed/tag/"+params[:tagname]+"/author/"+"params[:authorname]"+".rss" + xml.link "https://#{request.host}/feed/tag/"+params[:tagname]+"/author/"+params[:authorname]+".rss" @notes.each do |node| @@ -27,9 +27,9 @@ xml.rss :version => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom' do end xml.link "https://" + request.host.to_s + node.path if node.main_image - xml.description { xml.cdata!("#{node.main_image.title}") } + xml.description { xml.cdata!("#{node.main_image.title}

#{auto_link(node.latest.render_body, :sanitize => false)}

") } else - xml.description { xml.cdata!("PublicLab

#{body}

") } + xml.description { xml.cdata!("PublicLab

#{auto_link(node.latest.render_body, :sanitize => false)}

") } end xml.guid url_for :only_path => false, :controller => 'notes', :action => 'show', :id => node.nid end From 7e1c4e834589aad40edfbb900d6a134bde9c2a71 Mon Sep 17 00:00:00 2001 From: Sidharth Date: Mon, 5 Feb 2018 22:55:16 +0530 Subject: [PATCH 2/3] Image links updated --- app/views/tag/rss.rss.builder | 2 +- app/views/tag/rss_for_tagged_with_author.rss.builder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/tag/rss.rss.builder b/app/views/tag/rss.rss.builder index 9391a2af6f..b961963950 100644 --- a/app/views/tag/rss.rss.builder +++ b/app/views/tag/rss.rss.builder @@ -29,7 +29,7 @@ xml.rss :version => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom' do if node.main_image xml.description { xml.cdata!("#{node.main_image.title}

#{auto_link(node.latest.render_body, :sanitize => false)}

") } else - xml.description { xml.cdata!("PublicLab

#{auto_link(node.latest.render_body, :sanitize => false)}

") } + xml.description { xml.cdata!("PublicLab

#{auto_link(node.latest.render_body, :sanitize => false)}

") } end xml.guid url_for :only_path => false, :controller => 'notes', :action => 'show', :id => node.nid end diff --git a/app/views/tag/rss_for_tagged_with_author.rss.builder b/app/views/tag/rss_for_tagged_with_author.rss.builder index 491a056903..326104fbe1 100644 --- a/app/views/tag/rss_for_tagged_with_author.rss.builder +++ b/app/views/tag/rss_for_tagged_with_author.rss.builder @@ -29,7 +29,7 @@ xml.rss :version => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom' do if node.main_image xml.description { xml.cdata!("#{node.main_image.title}

#{auto_link(node.latest.render_body, :sanitize => false)}

") } else - xml.description { xml.cdata!("PublicLab

#{auto_link(node.latest.render_body, :sanitize => false)}

") } + xml.description { xml.cdata!("PublicLab

#{auto_link(node.latest.render_body, :sanitize => false)}

") } end xml.guid url_for :only_path => false, :controller => 'notes', :action => 'show', :id => node.nid end From 751fd74b25f19d9a8c4729949d79edc3efb10868 Mon Sep 17 00:00:00 2001 From: Sidharth Date: Tue, 6 Feb 2018 06:29:19 +0530 Subject: [PATCH 3/3] Updated rss --- app/views/tag/rss.rss.builder | 10 ++++------ .../tag/rss_for_tagged_with_author.rss.builder | 18 ++++++++---------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/app/views/tag/rss.rss.builder b/app/views/tag/rss.rss.builder index b961963950..200fff25fc 100644 --- a/app/views/tag/rss.rss.builder +++ b/app/views/tag/rss.rss.builder @@ -7,15 +7,13 @@ xml.rss :version => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom' do @notes.each do |node| body = node.body - uname = node.author.username - email = node.author.email + author = node.author.username if node.author.user.has_power_tag('twitter') - uname = node.author.user.get_value_of_power_tag('twitter') + author = "@#{node.author.user.get_value_of_power_tag('twitter')}" end - author_format = "@#{uname} (#{email})" xml.item do - xml.title " #{node.title}" - xml.author author_format + xml.title node.title + xml.author author if node.power_tag('date') != '' begin xml.pubDate DateTime.strptime(node.power_tag('date'), "%m-%d-%Y").rfc822 diff --git a/app/views/tag/rss_for_tagged_with_author.rss.builder b/app/views/tag/rss_for_tagged_with_author.rss.builder index 326104fbe1..989217467d 100644 --- a/app/views/tag/rss_for_tagged_with_author.rss.builder +++ b/app/views/tag/rss_for_tagged_with_author.rss.builder @@ -6,16 +6,14 @@ xml.rss :version => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom' do @notes.each do |node| - body = node.body - uname = node.author.username - email = node.author.email - if node.author.user.has_power_tag('twitter') - uname = node.author.user.get_value_of_power_tag('twitter') - end - author_format = "@#{uname} (#{email})" - xml.item do - xml.title " #{node.title}" - xml.author author_format + body = node.body + author = node.author.username + if node.author.user.has_power_tag('twitter') + author = "@#{node.author.user.get_value_of_power_tag('twitter')}" + end + xml.item do + xml.title node.title + xml.author author if node.power_tag('date') != '' begin xml.pubDate DateTime.strptime(node.power_tag('date'), "%m-%d-%Y").rfc822