forked from lobsters/lobsters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsitemap.rb
29 lines (22 loc) · 954 Bytes
/
sitemap.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
SitemapGenerator::Sitemap.default_host = "https://lobste.rs"
check_hourly = 4.days.ago
check_daily = 2.weeks.ago
top_score = Story.all.maximum('upvotes')
SitemapGenerator::Sitemap.create do
%w{/about /chat}.each do |path|
add path, changefreq: 'monthly', lastmod: nil
end
add recent_path, changefreq: 'always', priority: 1
add newest_path, changefreq: 'always', priority: 1
add comments_path, changefreq: 'always', priority: 1
Story.order('id desc').find_each do |story|
last_comment = story.comments.order('id desc').first
lastmod = story.created_at
lastmod = last_comment.updated_at if last_comment && last_comment.updated_at > lastmod
changefreq = 'monthly'
changefreq = 'daily' if lastmod >= check_daily
changefreq = 'hourly' if lastmod >= check_hourly
priority = 1.0 * story.upvotes / top_score
add story.comments_path, lastmod: lastmod, changefreq: changefreq, priority: priority
end
end