Files
grecia/config/sitemap.rb
Javi Martín f871658510 Use default_url_options to generate absolute URLs
In the dev seeds, we were using `Setting["url"]/proposals`, but we can
use `proposals_url` instead, similar to what we do in the rest of the
application.

We can do a similar thing in the sitemap. This way the sitemap will also
work on installations who haven't manually set the "url" setting.

Since we aren't using `Setting["url"]` anywhere anymore, we're removing
it.

This setting was mainly redundant, since we already had the
`server_name` in the secrets. Furthermore, `server_name` is
automatically configured when running the installer, while
`Setting["url"]` had to be manually set in the admin section the
application was installed.

Note we're using `ActionMailer::Base` setting to generate URLs. Sounds a
bit strange, but it's a standard way Rails provides to generate URLs
outside the context of a request.
2022-10-02 16:54:06 +02:00

55 lines
1.5 KiB
Ruby

# not use compression
class SitemapGenerator::FileAdapter
def gzip(stream, data)
stream.write(data)
stream.close
end
end
SitemapGenerator::Sitemap.namer = SitemapGenerator::SimpleNamer.new(:sitemap, extension: ".xml")
# default host
SitemapGenerator::Sitemap.verbose = false if Rails.env.test?
SitemapGenerator::Sitemap.default_host = root_url(ActionMailer::Base.default_url_options)
# sitemap generator
SitemapGenerator::Sitemap.create do
add help_path
add how_to_use_path
add faq_path
if Setting["process.debates"]
add debates_path, priority: 0.7, changefreq: "daily"
Debate.find_each do |debate|
add debate_path(debate), lastmod: debate.updated_at
end
end
if Setting["process.proposals"]
add proposals_path, priority: 0.7, changefreq: "daily"
Proposal.find_each do |proposal|
add proposal_path(proposal), lastmod: proposal.updated_at
end
end
if Setting["process.budgets"]
add budgets_path, priority: 0.7, changefreq: "daily"
Budget.find_each do |budget|
add budget_path(budget), lastmod: budget.updated_at
end
end
if Setting["process.polls"]
add polls_path, priority: 0.7, changefreq: "daily"
Poll.find_each do |poll|
add poll_path(poll), lastmod: poll.starts_at
end
end
if Setting["process.legislation"]
add legislation_processes_path, priority: 0.7, changefreq: "daily"
Legislation::Process.find_each do |process|
add legislation_process_path(process), lastmod: process.start_date
end
end
end