Skip to content

Instantly share code, notes, and snippets.

@rossmari
Last active August 29, 2015 14:18
Show Gist options
  • Save rossmari/b73d90bf652bfc5eff50 to your computer and use it in GitHub Desktop.
Save rossmari/b73d90bf652bfc5eff50 to your computer and use it in GitHub Desktop.
Implementation of sitemap generator for engine ( use gem SitemapGenerator )
# STEP 3
# in application.rb of your main application add
require "fortuna/sitemap"
# and then you can use it from anywhere
# [1] Example from console, generate sitemap for engine:
>> Fortuna::Sitemap.new
# In '/home/rossmari/Projects/ebox/public/':
# Fortuna::Girl Load (0.8ms) SELECT "fortuna_girls".* FROM "fortuna_girls"
# + sitemap.xml 5 links / 1.43 KB
# Sitemap stats: 5 links / 1 sitemaps / 0m00s
# [2] Example from main application sitemap.rb
SitemapGenerator::Sitemap.compress = false
SitemapGenerator::Sitemap.create(default_host: 'http://www.ebox.ru', filename: :sitemap) do
# generate content for models of main application
Publication.find_each do |publication|
add admin_publication_path(publication), lastmod: publication.updated_at
end
end
# run Fortuna engine sitemap generator
Fortuna::Sitemap.new
# STEP 1
# Fortuna engine sitemap generator class
module Fortuna
class Sitemap
# also specify sitemap file name unique for this engine
def initialize
SitemapGenerator::Sitemap.create(default_host: 'http://www.ebox.ru/fortuna/', filename: :fortuna_sitemap) do
Girl.find_each do |girl|
add Engine.routes.url_helpers.admin_girl_path(girl), lastmod: girl.updated_at
end
end
end
end
end
# STEP 2
# require sitemap generator class in engine to use it from main application
require "fortuna/engine"
require "fortuna/engine_sitemap"
module Fortuna
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment