Created RSS / Atom format sitemap with Ruby on Rails

I was in charge of creating RSS feeds for SEO measures on my site, so make a note of how to do it.

Why is RSS for SEO measures?

Before that, let's review the site map.

A sitemap is a "file that you put on your server to make it easier for crawlers to find your page." There are the following types of site maps.

XML sitemap

--Describe all the URLs you want to crawl index. ――The size is large accordingly. ――Therefore, it seems that ** crawlers don't come to see us so much **. Pien

RSS / Atom feed

--Write only recent changes. --Therefore, the size is small. ――So ** crawlers come to see more often than XML sitemaps **.

The site I'm in charge of developing is a site that posts event information and attracts customers, so ** More new pages per day ** → I want you to crawl the new and added pages ** as soon as possible ** → I decided to set up an RSS / Atom feed as well as a site map.

RSS feed creation

Standard library

Rails has a standard library (https://docs.ruby-lang.org/ja/latest/library/rss.html) for handling RSS, and you can use it just by requiring it.

require 'rss'

Feed creation process

And where you want to make an RSS feed

##
# [param] event_list :List of entries to put in the feed
#
def create_rss_feed(event_list)
  #This time Atom1.Created in 0 format
  feed = RSS::Maker.make('atom') do |maker|
    maker.channel.about = 'tag:sample.com:feed' #An ID that uniquely identifies the feed. Maybe anything unique.
    maker.channel.title = "New event" #Feed title
    maker.channel.description = "Introducing the latest information on the event." #Feed description
    maker.channel.link = 'https://sample.com/' #Site URL
    maker.channel.author = 'Event secretariat' #Feed creator
    maker.channel.date = .strftime('%Y-%m-%d %H:%M:%S') #Last updated date and time of the feed

    event_list.each_with_index do |event|
      maker.items.new_item do |item|
        item.link = event.url #URL of detail page
        item.title = event.title #Detail page title
        item.date = event.start_time.strftime('%Y-%m-%d %H:%M:%S') #Dates for events, publication dates for articles, etc.
      end
    end
  end
  render xml: feed.to_xml
end

If you write and execute such a process The RSS feed is displayed on the browser like this! This time I created it in a format called Atom, but when creating it in a different format

RSS::Maker.make('atom')


 For example, if RSS 2.0, this "atom" part should be changed to "2.0".


## in conclusion
 The standard library was prepared, so it was completed in no time.
 I just think Rails is amazing.


Recommended Posts

Created RSS / Atom format sitemap with Ruby on Rails
[Ruby on Rails] View test with RSpec
Notes on using FCM with Ruby on Rails
[Ruby on Rails] Controller test with RSpec
Introducing Rspec with Ruby on Rails x Docker
Publish the app made with ruby on rails
[Rails] Procedure for linking databases with Ruby On Rails
Determine the current page with Ruby on Rails
I made a portfolio with Ruby On Rails
Ruby on Rails Elementary
Ruby on Rails basics
Ruby On Rails Association
[Ruby on Rails] Delete s3 images with Active Strage
Run Ruby on Rails RSpec tests with GitHub Actions
Portfolio creation Ruby on Rails
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on Rails basic learning ①
Format Ruby with VS Code
[Ruby on Rails] about has_secure_password
Ruby on rails learning record-2020.10.07 ②
Commentary on partial! --Ruby on Rails
[Rails] Specify format with link_to
Ruby on rails learning record-2020.10.07 ①
Cancel Ruby on Rails migration
Ruby on rails learning record -2020.10.06
Ruby on Rails Basic Memorandum
I tried installing Ruby on Rails related plugin with vim-plug
[Ruby on Rails] Add a column with a foreign key constraint
[Ruby on Rails] Implement login function by add_token_to_users with API
[Apple login] Sign in with Apple implementation procedure (Ruby on Rails)
Install Ruby on MSYS2 with pacman
Ruby on Rails Overview (Beginner Summary)
[Ruby on Rails] Read try (: [],: key)
Installing Ruby + Rails on Ubuntu 18.04 (rbenv)
[Ruby on Rails] Introduced paging function
I want to add a browsing function with ruby on rails
Ruby on Rails development environment construction with Docker + VSCode (Remote Container)
Basic knowledge of Ruby on Rails
Progate Ruby on Rails5 Looking Back
How to use Ruby on Rails
Understand code coverage with Rspec, the Ruby on Rails test framework
[Ruby on Rails] Add / Remove Columns
Programming with ruby (on the way)
Ruby on Rails Japanese-English support i18n
[Ruby on Rails] CSV output function
Ruby on Rails 6.0 environment construction memo
[Ruby on Rails] What is Bcrypt?
Ruby On Rails devise routing conflict
[Ruby on Rails] Comment function implementation
[Ruby on Rails] DM, chat function
[Ruby on Rails] Convenient helper method
Steps to build a Ruby on Rails development environment with Vagrant
Install ruby on Ubuntu 20.04 with rbenv
[Ruby on Rails] Stop "looping until ..."
[Ruby on Rails] Create a pie chart for each column with Chartkick
[Ruby on Rails] NoMethodError: undefined method `t'for # <ActiveRecord :: Migration: 〇〇〇〇> Dealing with errors
[Ruby on Rails] Error that Couldn't find User with ... after logging out
[Ruby on Rails] Introduction of initial data
[Ruby on Rails] Search function (not selected)