og_pilot_ruby 0.3.0 → 0.3.1
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9624035f48941775c8b1e55637f9d20e6c65a10ffdcfe983ab47ef2ae53dae5d
|
|
4
|
+
data.tar.gz: 4889190ff785ff95df863f3e320fa17c04f08e1ae2f9772ffa405922440ec58f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e43e439eea7e9a8684c77cbc591a94dabc41b40b4096b8ea06eba2a8a73cb680868f362360ede49242285e94902b0258439bf40c47ae5ca91206098c74eb6b6
|
|
7
|
+
data.tar.gz: 5b966815886946cf1af21c2028a1e9a0721a8c820df34557e8bdd047fc457fe7650b8b4848a5438ecf56dbb8cb0653519bdcf6b8a2999800ab29e9f4f2071a99
|
data/README.md
CHANGED
|
@@ -28,6 +28,7 @@ Override as needed:
|
|
|
28
28
|
OgPilotRuby.configure do |config|
|
|
29
29
|
config.api_key = ENV.fetch("OG_PILOT_API_KEY")
|
|
30
30
|
config.domain = ENV.fetch("OG_PILOT_DOMAIN")
|
|
31
|
+
# config.strip_extensions = true
|
|
31
32
|
end
|
|
32
33
|
```
|
|
33
34
|
|
|
@@ -103,6 +104,17 @@ The gem handles `iss` (domain) and `sub` (API key prefix) automatically.
|
|
|
103
104
|
| `iat` | No | — | Issued-at timestamp for daily cache busting |
|
|
104
105
|
| `path` | No | auto-set | Request path for image rendering context. When provided, it overrides auto-resolution (see [Path handling](#path-handling)) |
|
|
105
106
|
|
|
107
|
+
### Configuration options
|
|
108
|
+
|
|
109
|
+
| Option | Default | Description |
|
|
110
|
+
|--------------------|-------------------------|--------------------------------------------------------------------------|
|
|
111
|
+
| `api_key` | `ENV["OG_PILOT_API_KEY"]` | Your OG Pilot API key |
|
|
112
|
+
| `domain` | `ENV["OG_PILOT_DOMAIN"]` | Your domain registered with OG Pilot |
|
|
113
|
+
| `base_url` | `https://ogpilot.com` | OG Pilot API base URL |
|
|
114
|
+
| `open_timeout` | `5` | Connection timeout in seconds |
|
|
115
|
+
| `read_timeout` | `10` | Read timeout in seconds |
|
|
116
|
+
| `strip_extensions` | `true` | When `true`, file extensions are stripped from resolved paths (see [Strip extensions](#strip-extensions)) |
|
|
117
|
+
|
|
106
118
|
### Ruby options
|
|
107
119
|
|
|
108
120
|
| Option | Default | Description |
|
|
@@ -161,12 +173,37 @@ Fetch JSON metadata instead:
|
|
|
161
173
|
```ruby
|
|
162
174
|
payload = {
|
|
163
175
|
template: "page",
|
|
164
|
-
title: "Hello OG Pilot"
|
|
176
|
+
title: "Hello OG Pilot"q
|
|
165
177
|
}
|
|
166
178
|
|
|
167
179
|
data = OgPilotRuby.create_image(**payload, json: true)
|
|
168
180
|
```
|
|
169
181
|
|
|
182
|
+
### Strip extensions
|
|
183
|
+
|
|
184
|
+
When `strip_extensions` is enabled, the client removes file extensions from the
|
|
185
|
+
last segment of every resolved path. This ensures that `/docs`, `/docs.md`,
|
|
186
|
+
`/docs.php`, and `/docs.html` all resolve to `"/docs"`, so analytics are
|
|
187
|
+
consolidated under a single path regardless of the URL extension.
|
|
188
|
+
|
|
189
|
+
Multiple extensions are also stripped (`/archive.tar.gz` becomes `/archive`).
|
|
190
|
+
Dotfiles like `/.hidden` are left unchanged. Query strings are preserved.
|
|
191
|
+
|
|
192
|
+
```ruby
|
|
193
|
+
OgPilotRuby.configure do |config|›
|
|
194
|
+
config.strip_extensions = true
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# All of these resolve to path "/docs":
|
|
198
|
+
OgPilotRuby.create_image(title: "Docs", path: "/docs")
|
|
199
|
+
OgPilotRuby.create_image(title: "Docs", path: "/docs.md")
|
|
200
|
+
OgPilotRuby.create_image(title: "Docs", path: "/docs.php")
|
|
201
|
+
|
|
202
|
+
# Nested paths work too: /blog/my-post.html → /blog/my-post
|
|
203
|
+
# Query strings are preserved: /docs.md?ref=main → /docs?ref=main
|
|
204
|
+
# Dotfiles are unchanged: /.hidden stays /.hidden
|
|
205
|
+
```
|
|
206
|
+
|
|
170
207
|
## Development
|
|
171
208
|
|
|
172
209
|
Run tests with:
|
data/lib/og_pilot_ruby/client.rb
CHANGED
|
@@ -166,9 +166,32 @@ module OgPilotRuby
|
|
|
166
166
|
|
|
167
167
|
cleaned = extract_request_uri(cleaned)
|
|
168
168
|
cleaned = "/#{cleaned}" unless cleaned.start_with?("/")
|
|
169
|
+
cleaned = strip_extension(cleaned) if config.strip_extensions
|
|
169
170
|
cleaned
|
|
170
171
|
end
|
|
171
172
|
|
|
173
|
+
def strip_extension(path)
|
|
174
|
+
path_part, query = path.split("?", 2)
|
|
175
|
+
|
|
176
|
+
dir = File.dirname(path_part)
|
|
177
|
+
base = File.basename(path_part)
|
|
178
|
+
|
|
179
|
+
# Don't strip dotfiles like "/.hidden" or "/.env" — only strip when
|
|
180
|
+
# there's a non-dot character before the first meaningful dot.
|
|
181
|
+
unless base.match?(/\A\./) # starts with dot = hidden file, skip
|
|
182
|
+
base = base.sub(/\..+\z/, "")
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
stripped = if dir == "/" || dir == "."
|
|
186
|
+
"/#{base}"
|
|
187
|
+
else
|
|
188
|
+
"#{dir}/#{base}"
|
|
189
|
+
end
|
|
190
|
+
stripped = "/" if stripped.empty?
|
|
191
|
+
|
|
192
|
+
query ? "#{stripped}?#{query}" : stripped
|
|
193
|
+
end
|
|
194
|
+
|
|
172
195
|
def extract_request_uri(value)
|
|
173
196
|
return value unless value.start_with?("http://", "https://")
|
|
174
197
|
|
|
@@ -5,7 +5,7 @@ module OgPilotRuby
|
|
|
5
5
|
DEFAULT_BASE_URL = "https://ogpilot.com"
|
|
6
6
|
private_constant :DEFAULT_BASE_URL
|
|
7
7
|
|
|
8
|
-
attr_accessor :api_key, :domain, :base_url, :open_timeout, :read_timeout
|
|
8
|
+
attr_accessor :api_key, :domain, :base_url, :open_timeout, :read_timeout, :strip_extensions
|
|
9
9
|
|
|
10
10
|
def initialize
|
|
11
11
|
@api_key = ENV.fetch("OG_PILOT_API_KEY", nil)
|
|
@@ -13,6 +13,7 @@ module OgPilotRuby
|
|
|
13
13
|
@base_url = DEFAULT_BASE_URL
|
|
14
14
|
@open_timeout = 5
|
|
15
15
|
@read_timeout = 10
|
|
16
|
+
@strip_extensions = true
|
|
16
17
|
end
|
|
17
18
|
end
|
|
18
19
|
end
|