FEATURE: provide extra signal about content age to crawlers

Adds Last-Modified field to help teach crawlers not to crawl old content
This commit is contained in:
Sam
2018-04-13 14:58:33 +10:00
parent 6179c0ce51
commit 3632b8d8d6
2 changed files with 23 additions and 0 deletions

View File

@ -117,6 +117,14 @@ class TopicsController < ApplicationController
canonical_url UrlHelper.absolute_without_cdn(@topic_view.canonical_path)
# provide hint to crawlers only for now
# we would like to give them a bit more signal about age of data
if use_crawler_layout?
if last_modified = @topic_view.posts&.map { |p| p.updated_at }&.max&.httpdate
response.headers['Last-Modified'] = last_modified
end
end
perform_show_response
rescue Discourse::InvalidAccess => ex