Skip to content

Commit

Permalink
Sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
crmne committed Dec 27, 2024
1 parent 9c5c572 commit d0bdfc1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@
/node_modules/

repomix-output.txt
sitemap.xml.gz
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ COPY --from=build /rails /rails
# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
chown -R rails:rails db log storage tmp
chown -R rails:rails db log storage tmp && \
touch public/sitemap.xml.gz && \
chown rails:rails public/sitemap.xml.gz
USER 1000:1000

# Entrypoint prepares the database.
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ group :test do
gem "capybara"
gem "selenium-webdriver"
end

gem "sitemap_generator", "~> 6.3"
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ GEM
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sexp_processor (4.17.3)
sitemap_generator (6.3.0)
builder (~> 3.0)
smart_properties (1.17.0)
solid_cable (3.0.5)
actioncable (>= 7.2)
Expand Down Expand Up @@ -488,6 +490,7 @@ DEPENDENCIES
rails_real_favicon
rubocop-rails-omakase
selenium-webdriver
sitemap_generator (~> 6.3)
solid_cable
solid_cache
solid_queue
Expand Down
10 changes: 10 additions & 0 deletions app/jobs/sitemap_refresh_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class SitemapRefreshJob < ApplicationJob
queue_as :default

def perform
Rails.logger.info "Refreshing sitemap..."
Rails.application.load_tasks
Rake::Task["sitemap:create"].invoke
Rails.logger.info "Sitemap refresh complete"
end
end
6 changes: 6 additions & 0 deletions config/initializers/boot_sitemap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Rails.application.config.after_initialize do
if defined?(Rails::Server)
# Give the app a few seconds to fully initialize before generating sitemap
SitemapRefreshJob.set(wait: 10.seconds).perform_later
end
end
11 changes: 11 additions & 0 deletions config/sitemap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Set the host name for URL creation
SitemapGenerator::Sitemap.default_host = "https://clusterheadachetracker.com"

SitemapGenerator::Sitemap.create do
# Add static pages
add root_path, priority: 1.0, changefreq: "daily"
add faq_path, priority: 0.7, changefreq: "monthly"
add imprint_path, priority: 0.7, changefreq: "monthly"
add privacy_policy_path, priority: 0.7, changefreq: "monthly"
add feedback_path, priority: 0.7, changefreq: "monthly"
end

0 comments on commit d0bdfc1

Please sign in to comment.