publify_core 9.0.0.pre6 → 9.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of publify_core might be problematic. Click here for more details.

Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -0
  3. data/README.md +9 -0
  4. data/app/controllers/admin/base_controller.rb +0 -6
  5. data/app/controllers/admin/content_controller.rb +34 -15
  6. data/app/controllers/admin/dashboard_controller.rb +4 -9
  7. data/app/controllers/admin/feedback_controller.rb +1 -0
  8. data/app/controllers/admin/notes_controller.rb +1 -1
  9. data/app/controllers/admin/pages_controller.rb +3 -7
  10. data/app/controllers/admin/sidebar_controller.rb +1 -0
  11. data/app/controllers/admin/tags_controller.rb +1 -0
  12. data/app/controllers/articles_controller.rb +50 -55
  13. data/app/controllers/comments_controller.rb +2 -3
  14. data/app/controllers/content_controller.rb +8 -17
  15. data/app/controllers/feedback_controller.rb +5 -39
  16. data/app/controllers/notes_controller.rb +1 -3
  17. data/app/controllers/setup_controller.rb +14 -18
  18. data/app/controllers/tags_controller.rb +13 -15
  19. data/app/controllers/theme_controller.rb +7 -5
  20. data/app/controllers/xml_controller.rb +11 -59
  21. data/app/helpers/authors_helper.rb +2 -2
  22. data/app/helpers/base_helper.rb +11 -4
  23. data/app/helpers/xml_helper.rb +2 -2
  24. data/app/jobs/application_job.rb +2 -0
  25. data/app/models/archives_sidebar.rb +8 -11
  26. data/app/models/article.rb +53 -72
  27. data/app/models/article/factory.rb +1 -1
  28. data/app/models/blog.rb +17 -40
  29. data/app/models/comment.rb +4 -3
  30. data/app/models/content.rb +18 -21
  31. data/app/models/content_base.rb +0 -5
  32. data/app/models/feedback.rb +76 -54
  33. data/app/models/meta_sidebar.rb +1 -0
  34. data/app/models/note.rb +7 -0
  35. data/app/models/page.rb +10 -5
  36. data/app/models/ping.rb +0 -113
  37. data/app/models/post_type.rb +1 -0
  38. data/app/models/redirect.rb +1 -1
  39. data/app/models/resource.rb +1 -19
  40. data/app/models/sidebar.rb +1 -1
  41. data/app/models/static_sidebar.rb +1 -0
  42. data/app/models/tag.rb +13 -9
  43. data/app/models/tag_sidebar.rb +4 -4
  44. data/app/models/trackback.rb +1 -8
  45. data/app/models/trigger.rb +1 -15
  46. data/app/models/user.rb +2 -9
  47. data/app/uploaders/resource_uploader.rb +33 -2
  48. data/app/views/accounts/confirm.html.erb +0 -1
  49. data/app/views/admin/content/_article_list.html.erb +1 -1
  50. data/app/views/admin/content/_form.html.erb +3 -7
  51. data/app/views/admin/pages/_form.html.erb +2 -2
  52. data/app/views/admin/seo/_general.html.erb +33 -28
  53. data/app/views/admin/seo/_permalinks.html.erb +2 -2
  54. data/app/views/admin/seo/_titles.html.erb +36 -36
  55. data/app/views/admin/settings/display.html.erb +20 -27
  56. data/app/views/admin/settings/feedback.html.erb +44 -51
  57. data/app/views/admin/settings/index.html.erb +14 -14
  58. data/app/views/admin/settings/write.html.erb +12 -30
  59. data/app/views/admin/tags/_index_and_form.html.erb +1 -1
  60. data/app/views/articles/_archives_article.html.erb +9 -0
  61. data/app/views/articles/_article.html.erb +8 -6
  62. data/app/views/articles/_article_collection.html.erb +1 -1
  63. data/app/views/articles/_article_excerpt.html.erb +10 -8
  64. data/app/views/articles/_article_links.html.erb +4 -2
  65. data/app/views/articles/_comment_list.html.erb +5 -5
  66. data/app/views/articles/_full_article_content.html.erb +4 -2
  67. data/app/views/articles/archives.html.erb +10 -20
  68. data/app/views/articles/feedback_atom_feed.atom.builder +5 -5
  69. data/app/views/articles/feedback_rss_feed.rss.builder +12 -13
  70. data/app/views/articles/index_atom_feed.atom.builder +3 -4
  71. data/app/views/articles/index_rss_feed.rss.builder +9 -10
  72. data/app/views/articles/read.html.erb +5 -31
  73. data/app/views/articles/search.html.erb +1 -1
  74. data/app/views/articles/trackback.xml.builder +1 -1
  75. data/app/views/authors/show.html.erb +11 -21
  76. data/app/views/authors/show_atom_feed.atom.builder +3 -4
  77. data/app/views/authors/show_rss_feed.rss.builder +9 -10
  78. data/app/views/comments/_comment.html.erb +17 -16
  79. data/app/views/feedback/index.atom.builder +7 -0
  80. data/app/views/feedback/index.rss.builder +19 -0
  81. data/app/views/notes/_note.html.erb +16 -15
  82. data/app/views/notes/index.html.erb +1 -1
  83. data/app/views/notification_mailer/_mail_footer.html.erb +0 -2
  84. data/app/views/notification_mailer/_mail_header.html.erb +2 -0
  85. data/app/views/notification_mailer/article.html.erb +4 -3
  86. data/app/views/notification_mailer/comment.html.erb +7 -6
  87. data/app/views/notification_mailer/notif_user.html.erb +3 -8
  88. data/app/views/setup/index.html.erb +4 -0
  89. data/app/views/shared/_atom_header.atom.builder +3 -3
  90. data/app/views/shared/_atom_item_article.atom.builder +26 -19
  91. data/app/views/shared/_atom_item_comment.atom.builder +3 -5
  92. data/app/views/shared/_atom_item_trackback.atom.builder +3 -4
  93. data/app/views/shared/_page_header.html.erb +1 -1
  94. data/app/views/shared/_rss_item_article.rss.builder +10 -15
  95. data/app/views/shared/_rss_item_comment.rss.builder +1 -2
  96. data/app/views/shared/_rss_item_trackback.rss.builder +1 -1
  97. data/app/views/tags/index.html.erb +2 -2
  98. data/app/views/xml/sitemap.googlesitemap.builder +7 -0
  99. data/config/initializers/mime_types.rb +0 -1
  100. data/config/locales/da.yml +8 -37
  101. data/config/locales/de.yml +7 -36
  102. data/config/locales/en.yml +7 -36
  103. data/config/locales/es-MX.yml +8 -37
  104. data/config/locales/fr.yml +7 -36
  105. data/config/locales/he.yml +4 -33
  106. data/config/locales/it.yml +7 -36
  107. data/config/locales/ja.yml +5 -34
  108. data/config/locales/lt.yml +7 -36
  109. data/config/locales/nb-NO.yml +7 -36
  110. data/config/locales/nl.yml +9 -38
  111. data/config/locales/pl.yml +8 -37
  112. data/config/locales/pt-BR.yml +8 -37
  113. data/config/locales/ro.yml +9 -38
  114. data/config/locales/ru.yml +7 -36
  115. data/config/locales/zh-CN.yml +6 -35
  116. data/config/locales/zh-TW.yml +7 -36
  117. data/config/routes.rb +6 -28
  118. data/db/migrate/113_initial_schema.rb +191 -191
  119. data/db/migrate/114_fixes_buggy_articles_and_notes.rb +6 -7
  120. data/db/migrate/115_drops_categories_for_tags.rb +3 -3
  121. data/db/migrate/20150207131657_add_missing_indexes.rb +1 -1
  122. data/db/migrate/20150807134129_simplify_redirect_relations.rb +1 -1
  123. data/db/migrate/20150808052637_add_blog_ids.rb +3 -5
  124. data/db/migrate/20150808191127_add_blog_id_to_redirects.rb +1 -1
  125. data/db/migrate/20150810094754_add_blog_id_to_tags.rb +1 -1
  126. data/db/migrate/20160108111120_add_devise_to_users.rb +3 -3
  127. data/db/migrate/20160108184201_move_last_connection_to_last_sign_in_at.rb +1 -1
  128. data/db/migrate/20160110094906_remove_profiles_rights.rb +1 -1
  129. data/db/migrate/20160605103918_replace_profile_id_with_string.rb +1 -3
  130. data/db/migrate/20160605154632_remove_profiles.rb +2 -2
  131. data/db/migrate/20160701061851_demand_blog_id_on_contents.rb +1 -1
  132. data/db/migrate/20160701062604_add_blog_id_to_resources.rb +1 -1
  133. data/db/migrate/20170528093024_move_resources_to_content.rb +5 -0
  134. data/db/migrate/20170528094923_move_tags_to_content.rb +6 -0
  135. data/db/migrate/20170528201606_remove_separate_published_flag.rb +5 -0
  136. data/db/migrate/20170605071626_remove_extra_state_columns_from_feedback.rb +6 -0
  137. data/db/migrate/20170702105201_remove_published_at_from_feedback.rb +5 -0
  138. data/db/seeds.rb +1 -1
  139. data/lib/publify_core.rb +0 -1
  140. data/lib/publify_core/version.rb +1 -1
  141. data/lib/publify_guid.rb +1 -1
  142. data/lib/publify_time.rb +2 -2
  143. data/lib/sidebar_field.rb +19 -12
  144. data/lib/transforms.rb +1 -0
  145. metadata +102 -66
  146. data/.gitignore +0 -13
  147. data/.rspec +0 -2
  148. data/.rubocop.yml +0 -84
  149. data/.rubocop_todo.yml +0 -148
  150. data/.travis.yml +0 -27
  151. data/Gemfile +0 -17
  152. data/README.rdoc +0 -3
  153. data/Rakefile +0 -35
  154. data/app/assets/stylesheets/publify_core/.keep +0 -0
  155. data/app/controllers/.keep +0 -0
  156. data/app/controllers/admin/migrations_controller.rb +0 -19
  157. data/app/controllers/concerns/.keep +0 -0
  158. data/app/controllers/trackbacks_controller.rb +0 -36
  159. data/app/helpers/.keep +0 -0
  160. data/app/mailers/.keep +0 -0
  161. data/app/models/.keep +0 -0
  162. data/app/models/article/states.rb +0 -179
  163. data/app/models/concerns/.keep +0 -0
  164. data/app/models/feedback/states.rb +0 -256
  165. data/app/services/migrator.rb +0 -25
  166. data/app/views/.keep +0 -0
  167. data/app/views/comments/index.html.erb +0 -1
  168. data/app/views/comments/index_atom_feed.atom.builder +0 -8
  169. data/app/views/comments/index_rss_feed.rss.builder +0 -20
  170. data/app/views/trackbacks/index_atom_feed.atom.builder +0 -7
  171. data/app/views/trackbacks/index_rss_feed.rss.builder +0 -20
  172. data/app/views/trackbacks/trackback.xml.builder +0 -4
  173. data/app/views/xml/feed.googlesitemap.builder +0 -7
  174. data/app/views/xml/rsd.rsd.builder +0 -8
  175. data/lib/stateful.rb +0 -106
  176. data/publify_core.gemspec +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4ddb8abe1bcadcc8e3361b43640b49c27d19d88
4
- data.tar.gz: 9aaf729490e771bb1c0550f141a21b6f8a70a8e8
3
+ metadata.gz: 1f81670a189d8b1a57d349dc688c93340d586128
4
+ data.tar.gz: 5fd4da9990342b133e045b7a797564407dbf915d
5
5
  SHA512:
6
- metadata.gz: 7b86a3b54ba1aff46aaeaa761027dcebd04b3cc0421ee3368a128e09a76fea8e5b4449b867a7118c23ade55bcaf007f7a919540762d74ea238a167bff38d2407
7
- data.tar.gz: 351d77f8f08da235ca634570e2ccdcbb8c7a627f29ce2b2f986f1abe182a49bd9b3746d6a27434527948c688d3376063e906fa3934640a96375a792eb9686c53
6
+ metadata.gz: a69c04c575796c90ac2df1c7d7de537c328f6633e93e94833896efb27c355239c8a5d211bd9b3fb4938c45d847cf38323fca36ed4a1b17a96ec082bb2b6415a2
7
+ data.tar.gz: 0f4331c8fdb2fdc2c1bc2f1b61ed7cc0918bf195a1afe1f794adbb1f8d40e18b5cc077ef4e19a534702ea66448b6bda267629c4ea8f7939b72005bca7ff0b84f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # Changelog
2
2
 
3
+ ## 9.0.0
4
+
5
+ * Replace page caching with fragment caching
6
+ * Replace home-grown state machine with aasm
7
+ * Remove automigration. Users should run db:migrate themselves
8
+ * Let first-run users pick their own password instead of generating one
9
+
10
+ * Dependencies
11
+ - Update dependencies
12
+ - Drop support for Ruby 2.1
13
+
14
+ * Removing of old/outdated functionality
15
+ - Remove support for feedburner
16
+ - Drop old redirects
17
+ - Remove RSD end point
18
+
19
+ * Feedback
20
+ - Stop sending trackbacks and pingbacks
21
+ - Stop accepting trackbacks
22
+
23
+ * Improve Atom/RSS feeds
24
+ - Fix URLs used for resources
25
+ - Fix URL/alternate links to not just point to the site root
26
+ - Unify comment and trackback feeds into feedback feed
27
+ - Add caching for feeds
28
+ - Fix atom entry publication date
29
+ - Fix ordering of feedback feed by using created_at
30
+
31
+ * Bug fixes
32
+ - Fix user resource image display when using Fog
33
+ - Fix sending of welcome email
34
+ - Fix Tag page description
35
+ - Handle setting published_at to blank
36
+ - Handle preview of articles without publication date
37
+ - Include CSRF meta tag so remote forms work
38
+ - Fix sidebar field rendering in admin
39
+ - Fix formatting of settings forms in admin
40
+
41
+ * Code improvements
42
+ - Performance improvements
43
+ - Improve tags controller
44
+ - Clean up archives and authors page code
45
+ - Unify content models more to improve performance when mixing models
46
+
3
47
  ## 9.0.0.pre6 / 2016-12-23
4
48
 
5
49
  * Remove now-broken caching of theme assets
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # PublifyCore
2
+
3
+ This is the core of the Publify blogging system.
4
+
5
+ See [the main Publify repository](https://github.com/publify/publify/) for more details.
6
+
7
+ ## License
8
+
9
+ See MIT-LICENSE for details.
@@ -8,7 +8,6 @@ class Admin::BaseController < BaseController
8
8
  layout 'administration'
9
9
 
10
10
  before_action :login_required, except: [:login, :signup]
11
- before_action :look_for_needed_db_updates, except: [:login, :signup]
12
11
 
13
12
  private
14
13
 
@@ -33,9 +32,4 @@ class Admin::BaseController < BaseController
33
32
  flash[:notice] = I18n.t('admin.base.successfully_deleted', name: controller_name.humanize)
34
33
  redirect_to action: 'index'
35
34
  end
36
-
37
- def look_for_needed_db_updates
38
- migrator = Migrator.new
39
- redirect_to admin_migrations_path if migrator.migrations_pending?
40
- end
41
35
  end
@@ -37,6 +37,12 @@ class Admin::ContentController < Admin::BaseController
37
37
 
38
38
  update_article_attributes
39
39
 
40
+ if @article.draft
41
+ @article.state = 'draft'
42
+ elsif @article.draft?
43
+ @article.publish!
44
+ end
45
+
40
46
  if @article.save
41
47
  flash[:success] = I18n.t('admin.content.create.success')
42
48
  redirect_to action: 'index'
@@ -60,6 +66,12 @@ class Admin::ContentController < Admin::BaseController
60
66
 
61
67
  update_article_attributes
62
68
 
69
+ if @article.draft
70
+ @article.state = 'draft'
71
+ elsif @article.draft?
72
+ @article.publish!
73
+ end
74
+
63
75
  if @article.save
64
76
  Article.where(parent_id: @article.id).map(&:destroy) unless @article.draft
65
77
  flash[:success] = I18n.t('admin.content.update.success')
@@ -92,10 +104,9 @@ class Admin::ContentController < Admin::BaseController
92
104
 
93
105
  @article.attributes = params[:article].permit!
94
106
 
95
- @article.published = false
96
107
  @article.author = current_user
97
108
  @article.save_attachments!(params[:attachments])
98
- @article.state = 'draft' unless @article.state == 'withdrawn'
109
+ @article.state = 'draft' unless @article.withdrawn?
99
110
  @article.text_filter ||= current_user.default_text_filter
100
111
 
101
112
  if @article.title.blank?
@@ -115,14 +126,14 @@ class Admin::ContentController < Admin::BaseController
115
126
  protected
116
127
 
117
128
  def get_fresh_or_existing_draft_for_article
118
- if @article.published && @article.id
119
- parent_id = @article.id
120
- @article =
121
- this_blog.articles.drafts.child_of(parent_id).first || this_blog.articles.build
122
- @article.allow_comments = this_blog.default_allow_comments
123
- @article.allow_pings = this_blog.default_allow_pings
124
- @article.parent_id = parent_id
125
- end
129
+ return unless @article.published? && @article.id
130
+
131
+ parent_id = @article.id
132
+ @article =
133
+ this_blog.articles.drafts.child_of(parent_id).first || this_blog.articles.build
134
+ @article.allow_comments = this_blog.default_allow_comments
135
+ @article.allow_pings = this_blog.default_allow_pings
136
+ @article.parent_id = parent_id
126
137
  end
127
138
 
128
139
  attr_accessor :resources, :resource
@@ -131,8 +142,6 @@ class Admin::ContentController < Admin::BaseController
131
142
 
132
143
  def load_resources
133
144
  @post_types = PostType.all
134
- @images = Resource.images_by_created_at.page(params[:page]).per(10)
135
- @resources = Resource.without_images_by_filename
136
145
  @macros = TextFilterPlugin.macro_filters
137
146
  end
138
147
 
@@ -148,15 +157,25 @@ class Admin::ContentController < Admin::BaseController
148
157
  end
149
158
 
150
159
  def update_article_attributes
151
- @article.attributes = update_params
160
+ @article.assign_attributes(update_params)
152
161
  @article.author = current_user
153
162
  @article.save_attachments!(params[:attachments])
154
- @article.state = 'draft' if @article.draft
155
163
  @article.text_filter ||= current_user.default_text_filter
156
164
  end
157
165
 
158
166
  def update_params
159
- params.require(:article).except(:id).permit!
167
+ params.
168
+ require(:article).
169
+ permit(:allow_comments,
170
+ :allow_pings,
171
+ :body,
172
+ :body_and_extended,
173
+ :draft,
174
+ :extended,
175
+ :permalink,
176
+ :published_at,
177
+ :title,
178
+ :keywords)
160
179
  end
161
180
 
162
181
  def get_layout
@@ -9,9 +9,10 @@ class Admin::DashboardController < Admin::BaseController
9
9
  t = Time.new
10
10
  today = t.strftime('%Y-%m-%d 00:00')
11
11
 
12
- # Since last venue
13
- @newposts_count = Article.published_since(current_user.last_sign_in_at).count
14
- @newcomments_count = Feedback.published_since(current_user.last_sign_in_at).count
12
+ # Since last visit
13
+ last_sign_in = current_user.last_sign_in_at
14
+ @newposts_count = Article.published_since(last_sign_in).count
15
+ @newcomments_count = Feedback.created_since(last_sign_in).count
15
16
 
16
17
  # Today
17
18
  @statposts = Article.published.where('published_at > ?', today).count
@@ -29,7 +30,6 @@ class Admin::DashboardController < Admin::BaseController
29
30
 
30
31
  @statspam = Comment.spam.count
31
32
  @inbound_links = inbound_links
32
- @publify_links = publify_dev
33
33
  publify_version
34
34
  end
35
35
 
@@ -61,11 +61,6 @@ class Admin::DashboardController < Admin::BaseController
61
61
  fetch_rss(url).reverse.compact
62
62
  end
63
63
 
64
- def publify_dev
65
- url = 'http://blog.publify.co/articles.rss'
66
- fetch_rss(url)[0..2]
67
- end
68
-
69
64
  def fetch_rss(url)
70
65
  open(url) do |http|
71
66
  return parse_rss(http.read)
@@ -75,6 +75,7 @@ class Admin::FeedbackController < Admin::BaseController
75
75
  @feedback ||= @article.comments
76
76
  end
77
77
 
78
+ # TODO: Replace with actions that move to a specified state
78
79
  def change_state
79
80
  return unless request.xhr?
80
81
 
@@ -20,7 +20,7 @@ class Admin::NotesController < Admin::BaseController
20
20
  def create
21
21
  note = new_note
22
22
 
23
- note.published = true
23
+ note.state = 'published'
24
24
  note.attributes = params[:note].permit!
25
25
  note.text_filter ||= current_user.default_text_filter
26
26
  note.published_at ||= Time.now
@@ -1,8 +1,8 @@
1
1
  # coding: utf-8
2
+
2
3
  require 'base64'
3
4
 
4
5
  class Admin::PagesController < Admin::BaseController
5
- before_action :set_images, only: [:new, :edit]
6
6
  before_action :set_macro, only: [:new, :edit]
7
7
  before_action :set_page, only: [:show, :edit, :update, :destroy]
8
8
 
@@ -16,8 +16,8 @@ class Admin::PagesController < Admin::BaseController
16
16
  def new
17
17
  @page = Page.new
18
18
  @page.text_filter ||= default_textfilter
19
- @page.published = true
20
19
  @page.user_id = current_user.id
20
+ @page.state = 'published'
21
21
  end
22
22
 
23
23
  def edit
@@ -60,10 +60,6 @@ class Admin::PagesController < Admin::BaseController
60
60
  @macros = TextFilterPlugin.macro_filters
61
61
  end
62
62
 
63
- def set_images
64
- @images = Resource.images.by_created_at.page(1).per(10)
65
- end
66
-
67
63
  def get_layout
68
64
  case action_name
69
65
  when 'new', 'edit', 'create'
@@ -82,6 +78,6 @@ class Admin::PagesController < Admin::BaseController
82
78
 
83
79
  # Never trust parameters from the scary internet, only allow the white list through.
84
80
  def page_params
85
- params.require(:page).permit(:title, :body, :name, :published, :text_filter)
81
+ params.require(:page).permit(:title, :body, :name, :state, :text_filter)
86
82
  end
87
83
  end
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  class Admin::SidebarController < Admin::BaseController
3
4
  def index
4
5
  @available = SidebarRegistry.available_sidebars
@@ -22,6 +22,7 @@ class Admin::TagsController < Admin::BaseController
22
22
  def update
23
23
  old_name = @tag.name
24
24
  if @tag.update(tag_params)
25
+ # TODO: Check whether these redirects are useful or ignored.
25
26
  Redirect.create(from_path: "/tag/#{old_name}", to_path: @tag.permalink_url(nil, true))
26
27
  redirect_to admin_tags_url, notice: I18n.t('admin.tags.edit.success')
27
28
  else
@@ -8,31 +8,24 @@ class ArticlesController < ContentController
8
8
  helper :'admin/base'
9
9
 
10
10
  def index
11
- conditions = this_blog.statuses_in_timeline ? ['type in (?, ?)', 'Article', 'Note'] : ['type = ?', 'Article']
11
+ wanted_types = this_blog.statuses_in_timeline ? ['Article', 'Note'] : ['Article']
12
12
 
13
13
  limit = this_blog.per_page(params[:format])
14
- @articles = if params[:year].blank?
15
- this_blog.contents.published.where(conditions).page(params[:page]).per(limit)
16
- else
17
- this_blog.contents.published_at(params.values_at(:year, :month, :day)).where(conditions).page(params[:page]).per(limit)
18
- end
19
-
20
- @page_title = this_blog.home_title_template
21
- @description = this_blog.home_desc_template
22
- if params[:year]
23
- @page_title = this_blog.archives_title_template
24
- @description = this_blog.archives_desc_template
25
- elsif params[:page]
26
- @page_title = this_blog.paginated_title_template
27
- @description = this_blog.paginated_desc_template
28
- end
29
- @page_title = @page_title.to_title(@articles, this_blog, params)
30
- @description = @description.to_title(@articles, this_blog, params)
31
-
32
- @keywords = this_blog.meta_keywords
14
+ articles_base = if params[:year].blank?
15
+ this_blog.contents.published
16
+ else
17
+ this_blog.contents.published_at(params.values_at(:year, :month, :day))
18
+ end
19
+ @articles = articles_base.includes(:user, :resources, :tags, :text_filter).
20
+ where(type: wanted_types).page(params[:page]).per(limit)
33
21
 
34
22
  respond_to do |format|
35
- format.html { render_paginated_index }
23
+ format.html do
24
+ set_index_title_and_description(this_blog, params)
25
+ @keywords = this_blog.meta_keywords
26
+
27
+ render_paginated_index
28
+ end
36
29
  format.atom do
37
30
  render_articles_feed('atom')
38
31
  end
@@ -50,8 +43,8 @@ class ArticlesController < ContentController
50
43
  @description = this_blog.search_desc_template.to_title(@articles, this_blog, params)
51
44
  respond_to do |format|
52
45
  format.html { render 'search' }
53
- format.rss { render 'index_rss_feed', layout: false }
54
- format.atom { render 'index_atom_feed', layout: false }
46
+ format.rss { render_articles_feed 'rss' }
47
+ format.atom { render_articles_feed 'atom' }
55
48
  end
56
49
  end
57
50
 
@@ -91,15 +84,15 @@ class ArticlesController < ContentController
91
84
  return redirect_to URI.parse(@article.permalink_url).path, status: 301 if @article
92
85
  end
93
86
 
94
- r = Redirect.find_by(from_path: from)
95
- return redirect_to r.full_to_path, status: 301 if r # Let redirection made outside of the blog on purpose (deal with it, Brakeman!)
96
-
97
- render 'errors/404', status: 404
87
+ r = Redirect.find_by!(from_path: from)
88
+ # TODO: If linked to article, directly redirect to the article.
89
+ # Let redirection made outside of the blog on purpose (deal with it, Brakeman!)
90
+ redirect_to r.full_to_path, status: 301 if r
98
91
  end
99
92
 
100
93
  def archives
101
94
  limit = this_blog.limit_archives_display
102
- @articles = this_blog.published_articles.page(params[:page]).per(limit)
95
+ @articles = this_blog.published_articles.includes(:tags).page(params[:page]).per(limit)
103
96
  @page_title = this_blog.archives_title_template.to_title(@articles, this_blog, params)
104
97
  @keywords = this_blog.meta_keywords
105
98
  @description = this_blog.archives_desc_template.to_title(@articles, this_blog, params)
@@ -115,13 +108,10 @@ class ArticlesController < ContentController
115
108
  end
116
109
 
117
110
  def view_page
118
- if (@page = Page.find_by(name: Array(params[:name]).join('/'))) && @page.published?
119
- @page_title = @page.title
120
- @description = this_blog.meta_description
121
- @keywords = this_blog.meta_keywords
122
- else
123
- render 'errors/404', status: 404
124
- end
111
+ @page = Page.published.find_by!(name: Array(params[:name]).join('/'))
112
+ @page_title = @page.title
113
+ @description = this_blog.meta_description
114
+ @keywords = this_blog.meta_keywords
125
115
  end
126
116
 
127
117
  # TODO: Move to TextfilterController?
@@ -131,6 +121,20 @@ class ArticlesController < ContentController
131
121
 
132
122
  private
133
123
 
124
+ def set_index_title_and_description(blog, parameters)
125
+ @page_title = blog.home_title_template
126
+ @description = blog.home_desc_template
127
+ if parameters[:year]
128
+ @page_title = blog.archives_title_template
129
+ @description = blog.archives_desc_template
130
+ elsif parameters[:page]
131
+ @page_title = blog.paginated_title_template
132
+ @description = blog.paginated_desc_template
133
+ end
134
+ @page_title = @page_title.to_title(@articles, blog, parameters)
135
+ @description = @description.to_title(@articles, blog, parameters)
136
+ end
137
+
134
138
  def verify_config
135
139
  if !this_blog.configured?
136
140
  redirect_to controller: 'setup', action: 'index'
@@ -143,15 +147,16 @@ class ArticlesController < ContentController
143
147
 
144
148
  # See an article We need define @article before
145
149
  def show_article
146
- @comment = Comment.new
147
- @page_title = this_blog.article_title_template.to_title(@article, this_blog, params)
148
- @description = this_blog.article_desc_template.to_title(@article, this_blog, params)
149
- groupings = @article.tags
150
- @keywords = groupings.map(&:name).join(', ')
151
-
152
150
  auto_discovery_feed
153
151
  respond_to do |format|
154
- format.html { render "articles/#{@article.post_type}" }
152
+ format.html do
153
+ @comment = Comment.new
154
+ @page_title = this_blog.article_title_template.to_title(@article, this_blog, params)
155
+ @description = this_blog.article_desc_template.to_title(@article, this_blog, params)
156
+
157
+ @keywords = @article.tags.map(&:name).join(', ')
158
+ render "articles/#{@article.post_type}"
159
+ end
155
160
  format.atom { render_feedback_feed('atom') }
156
161
  format.rss { render_feedback_feed('rss') }
157
162
  format.xml { render_feedback_feed('atom') }
@@ -161,26 +166,16 @@ class ArticlesController < ContentController
161
166
  end
162
167
 
163
168
  def render_articles_feed(format)
164
- if this_blog.feedburner_url.empty? || request.env['HTTP_USER_AGENT'] =~ /FeedBurner/i
165
- render "index_#{format}_feed", layout: false
166
- else
167
- redirect_to "http://feeds2.feedburner.com/#{this_blog.feedburner_url}"
168
- end
169
+ render_cached_xml("index_#{format}_feed", @articles)
169
170
  end
170
171
 
171
172
  def render_feedback_feed(format)
172
- @feedback = @article.published_feedback
173
- render "feedback_#{format}_feed", layout: false
173
+ render_cached_xml("feedback_#{format}_feed", @article)
174
174
  end
175
175
 
176
176
  def render_paginated_index
177
177
  return error! if @articles.empty?
178
- if this_blog.feedburner_url.empty?
179
- auto_discovery_feed(only_path: false)
180
- else
181
- @auto_discovery_url_rss = "http://feeds2.feedburner.com/#{this_blog.feedburner_url}"
182
- @auto_discovery_url_atom = "http://feeds2.feedburner.com/#{this_blog.feedburner_url}"
183
- end
178
+ auto_discovery_feed(only_path: false)
184
179
  render 'index'
185
180
  end
186
181