feat: sitemap generation

Automatically generates the sitemap upon deploy and pings the search
engines. A bit naive but it works. Uses Ruby because this is a book
about using Ruby.
This commit is contained in:
Brett Chalupa 2022-12-11 19:56:14 -05:00
parent e25d1908cb
commit 8d843582dc
4 changed files with 48 additions and 0 deletions

View file

@ -22,6 +22,16 @@ jobs:
- run: mdbook build
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108
with:
ruby-version: '3.1'
- name: Install dependencies
run: bundle install
- run: ./bin/sitemap.rb
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.ref == 'refs/heads/main' }}

3
Gemfile Normal file
View file

@ -0,0 +1,3 @@
source "https://rubygems.org"
gem 'sitemap_generator', '~> 6.3'

15
Gemfile.lock Normal file
View file

@ -0,0 +1,15 @@
GEM
remote: https://rubygems.org/
specs:
builder (3.2.4)
sitemap_generator (6.3.0)
builder (~> 3.0)
PLATFORMS
arm64-darwin-21
DEPENDENCIES
sitemap_generator (~> 6.3)
BUNDLED WITH
2.3.23

20
bin/sitemap.rb Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'sitemap_generator'
puts `mdbook build`
SitemapGenerator::Sitemap.default_host = 'https://book.dragonriders.community'
SitemapGenerator::Sitemap.public_path = 'book'
SitemapGenerator::Sitemap.compress = false
SitemapGenerator::Sitemap.create do
add '/', changefreq: 'weekly', priority: 0.9
# assumes no nested URLs
Dir.glob('book/*.html').each do |file|
file = file.split('/').last
next if file == "index.html"
add "/#{file}", changefreq: 'weekly'
end
end
SitemapGenerator::Sitemap.ping_search_engines