Skip to content

Commit

Permalink
Added functionality for sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Jones committed Jun 15, 2022
1 parent 6d22f74 commit f30c475
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ gem 'tzinfo-data', platforms: [:mswin, :mingw, :x64_mingw, :jruby]

# Include the tech docs gem
gem 'govuk_tech_docs'


gem "builder", "~> 3.0"
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ GEM
autoprefixer-rails (10.4.7.0)
execjs (~> 2)
backports (3.23.0)
builder (3.2.4)
chronic (0.10.2)
chunky_png (1.4.0)
coffee-script (2.4.1)
Expand Down Expand Up @@ -183,6 +184,7 @@ PLATFORMS
x64-mingw32

DEPENDENCIES
builder (~> 3.0)
govuk_tech_docs
tzinfo-data
wdm (~> 0.1.0)
Expand Down
2 changes: 2 additions & 0 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
activate :basic_panel
activate :back_to_top

config[:host] = "https://apply-the-service-standard.education.gov.uk"

GovukTechDocs.configure(self)
1 change: 1 addition & 0 deletions source/sitemap.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<% sitemap.resources.each do |page| %><%= "#{URI.join(config[:host], page.url)}\n" if page.url !~ /\.(css|js|eot|svg|woff|ttf|png|jpg|jpeg|gif|keep)$/ %><% end %>
16 changes: 16 additions & 0 deletions source/sitemap.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
xml.instruct!
xml.urlset 'xmlns' => "http://www.sitemaps.org/schemas/sitemap/0.9" do
sitemap.resources.select { |page| page.destination_path =~ /\.html/ && page.data.noindex != true }.each do |page|
xml.url do
xml.loc URI.join(config[:host], page.destination_path)
last_mod = if page.path.start_with?('articles/')
File.mtime(page.source_file).to_time
else
Time.now
end
xml.lastmod last_mod.iso8601
xml.changefreq page.data.changefreq || "monthly"
xml.priority page.data.priority || "0.5"
end
end
end

0 comments on commit f30c475

Please sign in to comment.