summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/rss_controller.rb34
-rw-r--r--app/helpers/content_helper.rb2
-rw-r--r--app/models/page.rb7
-rw-r--r--app/views/rss/updates.rdf.builder2
-rw-r--r--app/views/rss/updates.xml.builder2
5 files changed, 23 insertions, 24 deletions
diff --git a/app/controllers/rss_controller.rb b/app/controllers/rss_controller.rb
index 655ccba4..c2149d90 100644
--- a/app/controllers/rss_controller.rb
+++ b/app/controllers/rss_controller.rb
@@ -1,19 +1,12 @@
1class RssController < ApplicationController 1class RssController < ApplicationController
2 2
3 before_action :get_host 3 before_action :get_host
4 4
5 def updates 5 def updates
6 expires_in 31.minutes, :public => true 6 expires_in 31.minutes, :public => true
7
8 I18n.locale = I18n.default_locale 7 I18n.locale = I18n.default_locale
9 8
10 @items = Page.heads 9 @items = feed_items("update")
11 .joins("JOIN taggings ON taggings.taggable_id = pages.id
12 AND taggings.taggable_type = 'Page'
13 AND taggings.context = 'tags'")
14 .joins("JOIN tags ON tags.id = taggings.tag_id")
15 .where("LOWER(tags.name) = ?", "update")
16 .order("published_at DESC").limit(20)
17 10
18 respond_to do |format| 11 respond_to do |format|
19 format.xml {} 12 format.xml {}
@@ -23,16 +16,10 @@ class RssController < ApplicationController
23 16
24 def tag_updates 17 def tag_updates
25 expires_in 31.minutes, :public => true 18 expires_in 31.minutes, :public => true
26
27 I18n.locale = I18n.default_locale 19 I18n.locale = I18n.default_locale
28 @tag = params[:tag] 20
29 @items = Page.heads 21 @tag = params[:tag]
30 .joins("JOIN taggings ON taggings.taggable_id = pages.id 22 @items = feed_items(@tag)
31 AND taggings.taggable_type = 'Page'
32 AND taggings.context = 'tags'")
33 .joins("JOIN tags ON tags.id = taggings.tag_id")
34 .where("LOWER(tags.name) = ?", @tag.downcase)
35 .order("published_at DESC").limit(20)
36 23
37 respond_to do |format| 24 respond_to do |format|
38 format.xml {} 25 format.xml {}
@@ -40,7 +27,14 @@ class RssController < ApplicationController
40 end 27 end
41 28
42 protected 29 protected
43 30
31 def feed_items tag
32 Page.aggregate(:tags => tag.to_s.downcase,
33 :limit => 20,
34 :order_by => "published_at",
35 :order_direction => "DESC")
36 end
37
44 def get_host 38 def get_host
45 @host = request.protocol + request.host_with_port 39 @host = request.protocol + request.host_with_port
46 end 40 end
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb
index 57f8c960..9d52c110 100644
--- a/app/helpers/content_helper.rb
+++ b/app/helpers/content_helper.rb
@@ -123,7 +123,7 @@ module ContentHelper
123 sanitize(content, :attributes => cccms_attributes) 123 sanitize(content, :attributes => cccms_attributes)
124 end 124 end
125 125
126 rescue 126 rescue => e
127 Rails.logger.error("aggregate shortcode failed on page #{@page&.id}: #{e.class}: #{e.message}") 127 Rails.logger.error("aggregate shortcode failed on page #{@page&.id}: #{e.class}: #{e.message}")
128 fallback = content.sub(/\[aggregate[^\]]*\]/, "") 128 fallback = content.sub(/\[aggregate[^\]]*\]/, "")
129 fallback = sanitize(fallback, :attributes => cccms_attributes) 129 fallback = sanitize(fallback, :attributes => cccms_attributes)
diff --git a/app/models/page.rb b/app/models/page.rb
index cf003f74..a66527da 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -61,7 +61,7 @@ class Page < ApplicationRecord
61 unless options[:tags].blank? 61 unless options[:tags].blank?
62 tag_names = options[:tags].gsub(/\s/, ",").split(",").map(&:strip).map(&:downcase).uniq.reject(&:blank?) 62 tag_names = options[:tags].gsub(/\s/, ",").split(",").map(&:strip).map(&:downcase).uniq.reject(&:blank?)
63 63
64 unless tag_names.empty? 64 unless tag_names.empty?
65 scope = scope 65 scope = scope
66 .joins("JOIN taggings ON taggings.taggable_id = pages.id 66 .joins("JOIN taggings ON taggings.taggable_id = pages.id
67 AND taggings.taggable_type = 'Page' 67 AND taggings.taggable_type = 'Page'
@@ -71,6 +71,11 @@ class Page < ApplicationRecord
71 .group("pages.id") 71 .group("pages.id")
72 .having("COUNT(DISTINCT tags.id) = ?", tag_names.length) 72 .having("COUNT(DISTINCT tags.id) = ?", tag_names.length)
73 end 73 end
74
75 CccConventions::TAG_SCOPES.values_at(*tag_names).compact.uniq.each do |root|
76 scope = scope.where("nodes.unique_name = ? OR nodes.unique_name LIKE ?",
77 root, "#{root}/%")
78 end
74 end 79 end
75 80
76 if options[:node] && options[:children] == "direct" 81 if options[:node] && options[:children] == "direct"
diff --git a/app/views/rss/updates.rdf.builder b/app/views/rss/updates.rdf.builder
index b02d34ff..b4fecdb0 100644
--- a/app/views/rss/updates.rdf.builder
+++ b/app/views/rss/updates.rdf.builder
@@ -6,7 +6,7 @@ xml.tag!("rdf:RDF", "xmlns:rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
6 xml.title("Chaos Computer Club: Updates") 6 xml.title("Chaos Computer Club: Updates")
7 xml.link("https://www.ccc.de") 7 xml.link("https://www.ccc.de")
8 xml.description("Kabelsalat ist gesund.") 8 xml.description("Kabelsalat ist gesund.")
9 xml.tag!("dc:date", @items.first.published_at.xmlschema) 9 xml.tag!("dc:date", @items.first&.published_at&.xmlschema) if @items.any?
10 end 10 end
11 11
12 xml.image( "rdf:about" => "https://www.ccc.de/images/chaosknoten.gif") do 12 xml.image( "rdf:about" => "https://www.ccc.de/images/chaosknoten.gif") do
diff --git a/app/views/rss/updates.xml.builder b/app/views/rss/updates.xml.builder
index 27845c4c..f261de89 100644
--- a/app/views/rss/updates.xml.builder
+++ b/app/views/rss/updates.xml.builder
@@ -4,7 +4,7 @@ xml.feed(:xmlns => "http://www.w3.org/2005/Atom", "xml:base" => @host) do
4 xml.title("Chaos Computer Club Updates") 4 xml.title("Chaos Computer Club Updates")
5 xml.link(:href => "https://www.ccc.de/") 5 xml.link(:href => "https://www.ccc.de/")
6 xml.link(:rel => "self", :href => "#{@host}/rss/updates.xml") 6 xml.link(:rel => "self", :href => "#{@host}/rss/updates.xml")
7 xml.updated(@items.first.published_at.xmlschema) 7 xml.updated((@items.first&.published_at || Time.now).xmlschema)
8 xml.author do 8 xml.author do
9 xml.name("Chaos Computer Club e.V.") 9 xml.name("Chaos Computer Club e.V.")
10 end 10 end