helios-sitemap 0.1.0 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +54 -38
- data/lib/generators/helios/sitemap/install/install_generator.rb +40 -0
- data/lib/generators/helios/sitemap/install/templates/initializer.rb +32 -0
- data/lib/generators/helios/sitemap/install/templates/sitemap_controller.rb +16 -0
- data/lib/generators/helios/sitemap/install/templates/sitemap_refresh_job.rb +9 -0
- data/{app/jobs/helios/sitemap/refresh_job.rb → lib/helios/sitemap/refresh_service.rb} +15 -19
- data/lib/helios/sitemap/version.rb +1 -1
- data/lib/helios/sitemap.rb +1 -0
- data/lib/helios-sitemap.rb +1 -0
- metadata +7 -3
- data/app/jobs/helios/sitemap/application_job.rb +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8cefad961f0f74b3ec173b0b9587185859160cd846fa5ed7e0ac61fc6892a76
|
|
4
|
+
data.tar.gz: a4eb3cf44d45a91bbc551be41a07d5e4ad2947ef832bea8e282bcd299543fab3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 44600ff4533240069ff39c19205cf0e93862555edbe5f6e6fd62b78a62f8388ba886efef50330536a65e459ae38142b74a22c92082ed005c15055959800a93f8
|
|
7
|
+
data.tar.gz: 40040ba99a18cd67c4cb7c1fac6241a31fd323baec1226a087848d63c66a4c9ae0f8d44a19828a2f31ac5abf6f4f81b9ea134fd6768537bafc8e1910f0341d56
|
data/README.md
CHANGED
|
@@ -12,66 +12,82 @@ Add to your Gemfile:
|
|
|
12
12
|
gem "helios-sitemap"
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Then
|
|
15
|
+
Then:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bundle install
|
|
19
|
+
bin/rails generate helios:sitemap:install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The install generator creates three files in your app:
|
|
23
|
+
|
|
24
|
+
- `config/initializers/helios_sitemap.rb` — configuration (host, S3 settings, sitemap entries)
|
|
25
|
+
- `app/jobs/sitemap_refresh_job.rb` — background job that calls the refresh service
|
|
26
|
+
- `app/controllers/sitemap_controller.rb` — proxies the sitemap from S3
|
|
27
|
+
- Adds a `get "sitemap.xml"` route
|
|
16
28
|
|
|
17
29
|
## Configuration
|
|
18
30
|
|
|
19
|
-
|
|
31
|
+
Edit `config/initializers/helios_sitemap.rb`:
|
|
20
32
|
|
|
21
33
|
```ruby
|
|
22
34
|
Helios::Sitemap.configure do |config|
|
|
23
35
|
config.default_host = "https://example.com"
|
|
24
36
|
|
|
25
37
|
# S3 storage (defaults to ENV vars if not set)
|
|
26
|
-
config.aws_bucket = ENV["AWS_SITEMAP_BUCKET"]
|
|
27
|
-
config.aws_region = ENV["AWS_REGION"]
|
|
28
|
-
config.aws_access_key_id = ENV["AWS_ACCESS_KEY_ID"]
|
|
29
|
-
config.aws_secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
# Define what goes in your sitemap
|
|
38
|
+
# config.aws_bucket = ENV["AWS_SITEMAP_BUCKET"]
|
|
39
|
+
# config.aws_region = ENV["AWS_REGION"]
|
|
40
|
+
# config.aws_access_key_id = ENV["AWS_ACCESS_KEY_ID"]
|
|
41
|
+
# config.aws_secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
|
|
42
|
+
# config.s3_object_key = "sitemaps/sitemap.xml.gz"
|
|
43
|
+
|
|
44
|
+
# Define what goes in your sitemap.
|
|
45
|
+
# The block receives a SitemapGenerator::Sitemap instance.
|
|
36
46
|
config.sitemap_entries = ->(sitemap) {
|
|
37
47
|
sitemap.add "/", changefreq: "weekly", priority: 1.0
|
|
38
|
-
Post.published.find_each do |post|
|
|
39
|
-
sitemap.add "/#{post.slug}", changefreq: "weekly", priority: 0.7
|
|
40
|
-
end
|
|
41
|
-
}
|
|
42
48
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
urls << "https://example.com/#{post.slug}"
|
|
48
|
-
end
|
|
49
|
-
urls
|
|
49
|
+
# Dynamic entries from your database:
|
|
50
|
+
# Post.published.find_each do |post|
|
|
51
|
+
# sitemap.add "/#{post.slug}", changefreq: "weekly", priority: 0.7
|
|
52
|
+
# end
|
|
50
53
|
}
|
|
54
|
+
|
|
55
|
+
# IndexNow integration (optional)
|
|
56
|
+
# config.indexnow_domain = ENV["INDEXNOW_DOMAIN"]
|
|
57
|
+
# config.indexnow_api_key = ENV["INDEXNOW_API_KEY"]
|
|
58
|
+
# config.indexnow_urls = -> {
|
|
59
|
+
# Page.published.map { |p| "https://example.com/#{p.slug}" }
|
|
60
|
+
# }
|
|
51
61
|
end
|
|
52
62
|
```
|
|
53
63
|
|
|
54
|
-
##
|
|
64
|
+
## Generating & Uploading
|
|
55
65
|
|
|
56
|
-
|
|
66
|
+
The installed `SitemapRefreshJob` calls `Helios::Sitemap::RefreshService.call`, which:
|
|
57
67
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
1. Generates `sitemap.xml.gz` using `sitemap_generator`
|
|
69
|
+
2. Uploads it to your configured S3 bucket
|
|
70
|
+
3. Submits URLs to IndexNow (if configured)
|
|
61
71
|
|
|
62
|
-
|
|
63
|
-
- `GET /sitemap.xml` - Serves the sitemap XML from S3
|
|
64
|
-
- `GET /sitemap.xml.gz` - Serves the gzipped sitemap from S3
|
|
72
|
+
Schedule the job however your app handles recurring work:
|
|
65
73
|
|
|
66
|
-
|
|
74
|
+
```ruby
|
|
75
|
+
# Manual trigger
|
|
76
|
+
SitemapRefreshJob.perform_later
|
|
67
77
|
|
|
68
|
-
|
|
78
|
+
# With sidekiq-scheduler (config/sidekiq.yml):
|
|
79
|
+
# SitemapRefreshJob:
|
|
80
|
+
# every: ['3d']
|
|
81
|
+
# class: SitemapRefreshJob
|
|
69
82
|
|
|
70
|
-
|
|
71
|
-
Helios::Sitemap::RefreshJob.perform_later
|
|
83
|
+
# With any other job scheduler or cron
|
|
72
84
|
```
|
|
73
85
|
|
|
74
|
-
|
|
86
|
+
The job lives in your app so you can customize it — add error handling, logging, notifications, or call additional services after the sitemap refreshes.
|
|
87
|
+
|
|
88
|
+
## Serving the Sitemap
|
|
89
|
+
|
|
90
|
+
The installed `SitemapController` fetches the gzipped sitemap from S3 and serves it at `/sitemap.xml`. This works on ephemeral-disk platforms where the generated file wouldn't persist between deploys.
|
|
75
91
|
|
|
76
92
|
## Environment Variables
|
|
77
93
|
|
|
@@ -81,8 +97,8 @@ You can schedule this however you prefer (cron, recurring job, after publishing
|
|
|
81
97
|
| `AWS_REGION` | AWS region |
|
|
82
98
|
| `AWS_ACCESS_KEY_ID` | AWS access key |
|
|
83
99
|
| `AWS_SECRET_ACCESS_KEY` | AWS secret key |
|
|
84
|
-
| `INDEXNOW_DOMAIN` | Your domain for IndexNow |
|
|
85
|
-
| `INDEXNOW_API_KEY` | Your IndexNow API key |
|
|
100
|
+
| `INDEXNOW_DOMAIN` | Your domain for IndexNow (optional) |
|
|
101
|
+
| `INDEXNOW_API_KEY` | Your IndexNow API key (optional) |
|
|
86
102
|
|
|
87
103
|
## License
|
|
88
104
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Helios
|
|
4
|
+
module Sitemap
|
|
5
|
+
module Generators
|
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
|
8
|
+
|
|
9
|
+
desc "Installs Helios::Sitemap initializer, job, and controller into your app"
|
|
10
|
+
|
|
11
|
+
def copy_initializer
|
|
12
|
+
template "initializer.rb", "config/initializers/helios_sitemap.rb"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def copy_job
|
|
16
|
+
template "sitemap_refresh_job.rb", "app/jobs/sitemap_refresh_job.rb"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def copy_controller
|
|
20
|
+
template "sitemap_controller.rb", "app/controllers/sitemap_controller.rb"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def add_route
|
|
24
|
+
route 'get "sitemap.xml", to: "sitemap#show"'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def print_next_steps
|
|
28
|
+
say ""
|
|
29
|
+
say "Helios::Sitemap installed!", :green
|
|
30
|
+
say ""
|
|
31
|
+
say "Next steps:"
|
|
32
|
+
say " 1. Edit config/initializers/helios_sitemap.rb to configure your host and sitemap entries"
|
|
33
|
+
say " 2. Set these ENV vars: AWS_REGION, AWS_SITEMAP_BUCKET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY"
|
|
34
|
+
say " 3. Schedule SitemapRefreshJob in your job runner (e.g. sidekiq-scheduler)"
|
|
35
|
+
say ""
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Helios::Sitemap.configure do |config|
|
|
4
|
+
# The canonical host for your sitemap URLs
|
|
5
|
+
config.default_host = "https://example.com"
|
|
6
|
+
|
|
7
|
+
# S3 settings (defaults read from ENV vars)
|
|
8
|
+
# config.aws_region = ENV["AWS_REGION"]
|
|
9
|
+
# config.aws_bucket = ENV["AWS_SITEMAP_BUCKET"]
|
|
10
|
+
# config.aws_access_key_id = ENV["AWS_ACCESS_KEY_ID"]
|
|
11
|
+
# config.aws_secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
|
|
12
|
+
# config.s3_object_key = "sitemaps/sitemap.xml.gz"
|
|
13
|
+
|
|
14
|
+
# Define your sitemap entries.
|
|
15
|
+
# The block receives a SitemapGenerator::Sitemap instance.
|
|
16
|
+
config.sitemap_entries = ->(sitemap) {
|
|
17
|
+
sitemap.add "/", changefreq: "daily", priority: 0.9
|
|
18
|
+
# sitemap.add "/about", changefreq: "weekly"
|
|
19
|
+
|
|
20
|
+
# Dynamic entries from your database:
|
|
21
|
+
# Page.published.find_each do |page|
|
|
22
|
+
# sitemap.add "/#{page.slug}", lastmod: page.updated_at, changefreq: "weekly"
|
|
23
|
+
# end
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# IndexNow integration (optional)
|
|
27
|
+
# config.indexnow_domain = ENV["INDEXNOW_DOMAIN"]
|
|
28
|
+
# config.indexnow_api_key = ENV["INDEXNOW_API_KEY"]
|
|
29
|
+
# config.indexnow_urls = -> {
|
|
30
|
+
# Page.published.map { |p| "https://example.com/#{p.slug}" }
|
|
31
|
+
# }
|
|
32
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open-uri"
|
|
4
|
+
|
|
5
|
+
class SitemapController < ApplicationController
|
|
6
|
+
def show
|
|
7
|
+
config = Helios::Sitemap.configuration
|
|
8
|
+
url = "https://#{config.aws_bucket}.s3.#{config.aws_region}.amazonaws.com/#{config.s3_object_key}"
|
|
9
|
+
|
|
10
|
+
gz_data = URI.open(url).read
|
|
11
|
+
|
|
12
|
+
render plain: gz_data,
|
|
13
|
+
content_type: "application/gzip",
|
|
14
|
+
content_disposition: 'attachment; filename="sitemap.xml.gz"'
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -5,17 +5,17 @@ require "aws-sdk-s3"
|
|
|
5
5
|
|
|
6
6
|
module Helios
|
|
7
7
|
module Sitemap
|
|
8
|
-
class
|
|
9
|
-
|
|
8
|
+
class RefreshService
|
|
9
|
+
def self.call
|
|
10
|
+
new.call
|
|
11
|
+
end
|
|
10
12
|
|
|
11
|
-
def
|
|
13
|
+
def call
|
|
12
14
|
config = Helios::Sitemap.configuration
|
|
13
15
|
|
|
14
|
-
urls = collect_urls(config)
|
|
15
|
-
|
|
16
16
|
generate_sitemap(config)
|
|
17
17
|
upload_to_s3(config) unless Rails.env.development?
|
|
18
|
-
submit_to_indexnow(
|
|
18
|
+
submit_to_indexnow(config)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
private
|
|
@@ -34,25 +34,21 @@ module Helios
|
|
|
34
34
|
def upload_to_s3(config)
|
|
35
35
|
file_path = Rails.root.join("public", "sitemap.xml.gz")
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
file_path,
|
|
41
|
-
bucket: config.aws_bucket,
|
|
42
|
-
key: config.s3_object_key,
|
|
43
|
-
content_type: "application/gzip"
|
|
37
|
+
s3 = Aws::S3::Resource.new(
|
|
38
|
+
region: config.aws_region,
|
|
39
|
+
credentials: Aws::Credentials.new(config.aws_access_key_id, config.aws_secret_access_key)
|
|
44
40
|
)
|
|
45
41
|
|
|
42
|
+
obj = s3.bucket(config.aws_bucket).object(config.s3_object_key)
|
|
43
|
+
obj.upload_file(file_path.to_s, content_type: "application/gzip")
|
|
44
|
+
|
|
46
45
|
Rails.logger.info("[helios-sitemap] Uploaded sitemap to s3://#{config.aws_bucket}/#{config.s3_object_key}")
|
|
47
46
|
end
|
|
48
47
|
|
|
49
|
-
def
|
|
50
|
-
return
|
|
51
|
-
|
|
52
|
-
config.indexnow_urls.call
|
|
53
|
-
end
|
|
48
|
+
def submit_to_indexnow(config)
|
|
49
|
+
return unless config.indexnow_urls
|
|
54
50
|
|
|
55
|
-
|
|
51
|
+
urls = config.indexnow_urls.call
|
|
56
52
|
return unless urls.any?
|
|
57
53
|
|
|
58
54
|
Rails.logger.info("[helios-sitemap] Submitting #{urls.count} URLs to IndexNow")
|
data/lib/helios/sitemap.rb
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "helios/sitemap"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: helios-sitemap
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: '0.2'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jason Fleetwood-Boldt
|
|
@@ -66,16 +66,20 @@ files:
|
|
|
66
66
|
- app/controllers/helios/sitemap/application_controller.rb
|
|
67
67
|
- app/controllers/helios/sitemap/sitemap_controller.rb
|
|
68
68
|
- app/helpers/helios/sitemap/application_helper.rb
|
|
69
|
-
- app/jobs/helios/sitemap/application_job.rb
|
|
70
|
-
- app/jobs/helios/sitemap/refresh_job.rb
|
|
71
69
|
- app/mailers/helios/sitemap/application_mailer.rb
|
|
72
70
|
- app/models/helios/sitemap/application_record.rb
|
|
73
71
|
- app/views/layouts/helios/sitemap/application.html.erb
|
|
74
72
|
- config/routes.rb
|
|
73
|
+
- lib/generators/helios/sitemap/install/install_generator.rb
|
|
74
|
+
- lib/generators/helios/sitemap/install/templates/initializer.rb
|
|
75
|
+
- lib/generators/helios/sitemap/install/templates/sitemap_controller.rb
|
|
76
|
+
- lib/generators/helios/sitemap/install/templates/sitemap_refresh_job.rb
|
|
77
|
+
- lib/helios-sitemap.rb
|
|
75
78
|
- lib/helios/sitemap.rb
|
|
76
79
|
- lib/helios/sitemap/configuration.rb
|
|
77
80
|
- lib/helios/sitemap/engine.rb
|
|
78
81
|
- lib/helios/sitemap/index_now_service.rb
|
|
82
|
+
- lib/helios/sitemap/refresh_service.rb
|
|
79
83
|
- lib/helios/sitemap/version.rb
|
|
80
84
|
- lib/tasks/helios/sitemap_tasks.rake
|
|
81
85
|
homepage: https://github.com/heliosdev/helios-sitemap
|