-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08ab8a0
commit 9093470
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class SitemapsController < ApplicationController | ||
def show | ||
render xml: generate_sitemap_string | ||
end | ||
|
||
private | ||
|
||
def generate_sitemap_string | ||
Rails.cache.fetch("sitemap", expires_in: 24.hours) do | ||
adapter = SitemapStringAdapter.new | ||
|
||
SitemapGenerator::Sitemap.default_host = "https://www.rubyvideo.dev" | ||
|
||
SitemapGenerator::Sitemap.create(adapter: adapter) do | ||
add talks_path, priority: 0.9, changefreq: "daily" | ||
|
||
Talk.find_each do |talk| | ||
add talk_path(talk), priority: 0.8, lastmod: talk.updated_at | ||
end | ||
|
||
add speakers_path, priority: 0.7, changefreq: "daily" | ||
|
||
Speaker.find_each do |speaker| | ||
add speaker_path(speaker), priority: 0.8, lastmod: speaker.updated_at | ||
end | ||
end | ||
|
||
adapter.sitemap_content | ||
end | ||
end | ||
|
||
class SitemapStringAdapter | ||
attr_reader :sitemap_content | ||
|
||
def write(location, raw_data) | ||
@sitemap_content ||= "" | ||
@sitemap_content << raw_data | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file | ||
User-agent: * | ||
Disallow: | ||
|
||
Sitemap: https://www.rubyvideo.com/sitemap.xml |