mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
de9a031073
* FEATURE: use canonical links in posts.rss feed Previously we used non canonical links in posts.rss These links get crawled frequently by crawlers when discovering new content forcing crawlers to hop to non canonical pages just to end up visiting canonical pages This uses up expensive crawl time and adds load on Discourse sites Old links were of the form: `https://DOMAIN/t/SLUG/43/21` New links are of the form `https://DOMAIN/t/SLUG/43?page=2#post_21` This also adds a post_id identified element to crawler view that was missing. Note, to avoid very expensive N+1 queries required to figure out the page a post is on during rss generation, we cache that information. There is a smart "cache breaker" which ensures worst case scenario is a "page drift" - meaning we would publicize a post is on page 11 when it is actually on page 10 due to post deletions. Cache holds for up to 12 hours. Change only impacts public post RSS feeds (`/posts.rss`)
22 lines
1.1 KiB
Plaintext
22 lines
1.1 KiB
Plaintext
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<rss version="2.0" xmlns:discourse="http://www.discourse.org/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
|
<channel>
|
|
<% lang = SiteSetting.find_by_name('default_locale').try(:value) %>
|
|
<% site_email = SiteSetting.find_by_name('contact_email').try(:value) %>
|
|
<title><%= @title %></title>
|
|
<link><%= @link %></link>
|
|
<description><%= @description %></description>
|
|
<% @posts.each do |post| %>
|
|
<% next unless post.user %>
|
|
<item>
|
|
<title><%= post.topic.title %></title>
|
|
<dc:creator><![CDATA[<%= "@#{post.user.username}#{" #{post.user.name}" if (post.user.name.present? && SiteSetting.enable_names?)}" -%>]]></dc:creator>
|
|
<description><![CDATA[ <%= PrettyText.format_for_email(post.cooked, post).html_safe %> ]]></description>
|
|
<link><%= cached_post_url(post, use_canonical: @use_canonical) %></link>
|
|
<pubDate><%= post.created_at.rfc2822 %></pubDate>
|
|
<guid isPermaLink="false"><%= Discourse.current_hostname %>-post-<%= post.id %></guid>
|
|
</item>
|
|
<% end %>
|
|
</channel>
|
|
</rss>
|