Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sitemap updates #886

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ gem 'activerecord-session_store'

gem 'gravtastic', '~> 3.2.6'

gem 'dynamic_sitemaps', github: 'lassebunk/dynamic_sitemaps', branch: 'master'
gem 'sitemap_generator'

gem 'whenever', '~> 1.0.0'

Expand Down
11 changes: 3 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ GIT
tess_rdf_extractors (0.1.0)
linkeddata (~> 3.2.0)

GIT
remote: https://github.com/lassebunk/dynamic_sitemaps.git
revision: 37beeba143e8202218ee814056231b0e6974bafb
branch: master
specs:
dynamic_sitemaps (2.0.0)

GIT
remote: https://github.com/radar/by_star
revision: d7811c0c50f30262b4862b384c50f22f36e54f07
Expand Down Expand Up @@ -687,6 +680,8 @@ GEM
sitemap-parser (0.5.6)
nokogiri (~> 1.6)
typhoeus (>= 0.6, < 2.0)
sitemap_generator (6.3.0)
builder (~> 3.0)
sixarm_ruby_unaccent (1.2.0)
slim (4.1.0)
temple (>= 0.7.6, < 0.9)
Expand Down Expand Up @@ -800,7 +795,6 @@ DEPENDENCIES
country_select (<= 4.0.0)
devise
devise_invitable (~> 2.0.5)
dynamic_sitemaps!
eventbrite_sdk
font-awesome-sass (~> 4.7.0)
friendly_id (~> 5.2.4)
Expand Down Expand Up @@ -863,6 +857,7 @@ DEPENDENCIES
simplecov
simplecov-lcov
sitemap-parser (~> 0.5.6)
sitemap_generator
slim
sunspot_rails!
terser
Expand Down
11 changes: 3 additions & 8 deletions config/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@
end

# Generate a new sitemap...
if !schedules['sitemap'].nil?
every :"#{schedules['sitemap']['every']}", at: "#{schedules['sitemap']['at']}" do
rake "sitemap:generate"
end
else
every :day, at: '1am' do
rake "sitemap:generate"
end
every schedules.dig('sitemap', 'every')&.to_sym || :day,
at: schedules.dig('sitemap', 'at') || '1am' do
rake "sitemap:refresh"
end

# Process subscriptions...
Expand Down
90 changes: 27 additions & 63 deletions config/sitemap.rb
Original file line number Diff line number Diff line change
@@ -1,66 +1,30 @@
# Change this to your host. See the readme at https://github.com/lassebunk/dynamic_sitemaps
# for examples of multiple hosts and folders.
base_url = URI.parse(TeSS::Config.base_url)
host_with_port = base_url.host
if base_url.port != base_url.default_port
host_with_port += ":#{base_url.port}"
end

protocol base_url.scheme
host host_with_port

sitemap :site do
url root_url, last_mod: Time.now, change_freq: 'daily', priority: 1.0
url about_url, change_freq: 'weekly', priority: 0.4
if TeSS::Config.feature['materials']
url materials_url, last_mod: Time.now, change_freq: 'daily', priority: 0.7
end
if TeSS::Config.feature['events']
url events_url, last_mod: Time.now, change_freq: 'daily', priority: 0.7
# Set the host name for URL creation
SitemapGenerator::Sitemap.default_host = TeSS::Config.base_url

SitemapGenerator::Sitemap.create(compress: false, sitemaps_path: 'sitemaps/', include_root: false) do
types = {
materials: { resources: Material.from_verified_users, changefreq: 'daily', priority: 0.7 },
events: { resources: Event.from_verified_users, changefreq: 'daily', priority: 0.7 },
content_providers: { resources: ContentProvider, changefreq: 'weekly', priority: 0.4 },
workflows: { resources: Workflow.from_verified_users.visible_by(nil), changefreq: 'daily', priority: 0.6 },
collections: { resources: Collection.from_verified_users.visible_by(nil), changefreq: 'daily', priority: 0.6 }
}

group(filename: :site) do
add root_path, changefreq: 'daily', priority: 1.0
add about_path, priority: 0.4
types.each do |type, options|
next unless TeSS::Config.feature[type.to_s]
add polymorphic_path(type), lastmod: options[:resources].maximum(:updated_at), **options.except(:resources)
end
end
if TeSS::Config.feature['workflows']
url workflows_url, last_mod: Time.now, change_freq: 'daily', priority: 0.6
end
if TeSS::Config.feature['content_providers']
url content_providers_url, last_mod: Time.now, change_freq: 'weekly', priority: 0.4

types.each do |type, options|
next unless TeSS::Config.feature[type.to_s]
group(filename: type) do
options[:resources].find_each do |resource|
add polymorphic_path(resource), lastmod: resource.updated_at
end
end
end
end

# You can have multiple sitemaps like the above – just make sure their names are different.

# Automatically link to all pages using the routes specified
# using "resources :pages" in config/routes.rb. This will also
# automatically set <lastmod> to the date and time in page.updated_at:
#
# sitemap_for Page.scoped

sitemap_for Material.from_verified_users if TeSS::Config.feature['materials']
sitemap_for Event.from_verified_users if TeSS::Config.feature['events']
sitemap_for ContentProvider if TeSS::Config.feature['content_providers']
sitemap_for Workflow.from_verified_users.visible_by(nil) if TeSS::Config.feature['workflows']

# For products with special sitemap name and priority, and link to comments:
#
# sitemap_for Product.published, name: :published_products do |product|
# url product, last_mod: product.updated_at, priority: (product.featured? ? 1.0 : 0.7)
# url product_comments_url(product)
# end

# If you want to generate multiple sitemaps in different folders (for example if you have
# more than one domain, you can specify a folder before the sitemap definitions:
#
# Site.all.each do |site|
# folder "sitemaps/#{site.domain}"
# host site.domain
#
# sitemap :site do
# url root_url
# end
#
# sitemap_for site.products.scoped
# end

# Ping search engines after sitemap generation:
#

ping_with "#{base_url.scheme}://#{host}/sitemap.xml" if Rails.env.production?