* Move logic to determine noindex from view to model This brings attention to the code and allows for faster unit tests. I expect we'll be modifying this soon to deemphasize the code tag as a marker of quality. * Replace "5" constant with home feed minimum score * Remove check for "code" tags in low quality article check This made sense for DEV and other devrel communities, but is no longer necessary for Forems. * Add UserExperience setting for minimum index score - add setting, I used `index_minimum_score` to match the `home_feed_minimum_score`, `minimum_index_score` feels natural but breaks the pattern. - use this to determine whether to include article in the sitemap - use this to determine whether to add noindex meta to article show page * Remove unneeded tests Since there's no longer any check for <code> tags in the body, omit those tests (which passed anyway). * Add new setting to admin page
39 lines
1.2 KiB
Ruby
39 lines
1.2 KiB
Ruby
class SitemapsController < ApplicationController
|
|
before_action :set_cache_control_headers, only: %i[show]
|
|
|
|
SITEMAP_REGEX = /\Asitemap-(?<date_string>[A-Z][a-z][a-z]-\d{4})\.xml\z/
|
|
|
|
def show
|
|
match = params[:sitemap].match(SITEMAP_REGEX)
|
|
not_found unless match && match[:date_string]
|
|
begin
|
|
date = Time.zone.parse(match[:date_string]).at_beginning_of_month
|
|
rescue ArgumentError
|
|
not_found
|
|
end
|
|
|
|
@articles = Article.published
|
|
.where("published_at > ? AND published_at < ? AND score > ?",
|
|
date, date.end_of_month, Settings::UserExperience.index_minimum_score)
|
|
.pluck(:path, :last_comment_at)
|
|
|
|
set_surrogate_controls(date)
|
|
set_cache_control_headers(@max_age,
|
|
stale_while_revalidate: @stale_while_revalidate,
|
|
stale_if_error: @stale_if_error)
|
|
render layout: false
|
|
end
|
|
|
|
private
|
|
|
|
def set_surrogate_controls(date)
|
|
@stale_if_error = "86400"
|
|
if date > 1.month.ago
|
|
@max_age = "8640" # one hour
|
|
@stale_while_revalidate = "43200" # half a day
|
|
else
|
|
@max_age = "259200" # three days
|
|
@stale_while_revalidate = "432000" # five days
|
|
end
|
|
end
|
|
end
|