opengraphplus 0.1.8 → 0.1.10
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 +22 -7
- data/lib/generators/opengraphplus/base_generator.rb +3 -3
- data/lib/generators/opengraphplus/credentials/credentials_generator.rb +3 -3
- data/lib/generators/opengraphplus/credentials/templates/initializer.rb.tt +1 -1
- data/lib/generators/opengraphplus/env/env_generator.rb +1 -1
- data/lib/generators/opengraphplus/env/templates/initializer.rb.tt +1 -1
- data/lib/generators/opengraphplus/install/templates/initializer.rb +2 -2
- data/lib/opengraphplus/image_generator.rb +6 -14
- data/lib/opengraphplus/rails/controller.rb +4 -7
- data/lib/opengraphplus/signature/url.rb +1 -1
- data/lib/opengraphplus/version.rb +1 -1
- data/lib/opengraphplus.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0d5e0af7ba91d92d1f9c20380bd19c0d684eb68e65fb7f90bfdb803b051c3d4a
|
|
4
|
+
data.tar.gz: 4bc63ce1ff20de87a5101edea02ffa931875a8231bed0047cc90ee69cede2a6f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5f4d532d192695beb6fd9565e3cf8a12e5e478cb72fdebc7467a26122810eeedf5d75fd9bee5e78cbd74f8879de040ccae1d2c4352ca099308a311f6cbe99ee9
|
|
7
|
+
data.tar.gz: b238b9d0ac0aff9bf41164d8d9b9a8b882557c6e57f57bd1d2230b36d03a8ea6a20ab8c0d9302a828c6083141f9d6fa9b8b2d39a66b01306f2d42ab74af4c9cb
|
data/README.md
CHANGED
|
@@ -27,27 +27,27 @@ Sign up at [og.plus](https://og.plus) to get your API key.
|
|
|
27
27
|
#### Using environment variables
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
|
-
rails g opengraphplus:env
|
|
30
|
+
rails g opengraphplus:env ogplus_live_████████████████████
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
This will:
|
|
34
|
-
- Append `
|
|
34
|
+
- Append `OGPLUS__API_KEY=ogplus_live_████████████████████` to your `.env` file (or the first env file found)
|
|
35
35
|
- Create `config/initializers/opengraphplus.rb`
|
|
36
36
|
|
|
37
37
|
To specify a different env file:
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
|
-
rails g opengraphplus:env
|
|
40
|
+
rails g opengraphplus:env ogplus_live_████████████████████ -e .envrc
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
#### Using Rails credentials
|
|
44
44
|
|
|
45
45
|
```bash
|
|
46
|
-
rails g opengraphplus:credentials
|
|
46
|
+
rails g opengraphplus:credentials ogplus_live_████████████████████
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
This will:
|
|
50
|
-
- Add `
|
|
50
|
+
- Add `ogplus.api_key` to your encrypted `credentials.yml.enc`
|
|
51
51
|
- Create `config/initializers/opengraphplus.rb`
|
|
52
52
|
|
|
53
53
|
#### Manual configuration
|
|
@@ -62,12 +62,27 @@ Then configure manually in `config/initializers/opengraphplus.rb`:
|
|
|
62
62
|
|
|
63
63
|
```ruby
|
|
64
64
|
OpenGraphPlus.configure do |config|
|
|
65
|
-
config.api_key = ENV["
|
|
65
|
+
config.api_key = ENV["OGPLUS__API_KEY"]
|
|
66
66
|
# or
|
|
67
|
-
config.api_key = Rails.application.credentials.
|
|
67
|
+
config.api_key = Rails.application.credentials.ogplus.api_key
|
|
68
68
|
end
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
## Capturing a Different URL
|
|
72
|
+
|
|
73
|
+
By default, OpenGraphPlus screenshots the current request URL for the `og:image`. To screenshot a different URL (e.g., a public preview page when the main page requires authentication):
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
class ArticlesController < ApplicationController
|
|
77
|
+
open_graph do |og|
|
|
78
|
+
og.title = "My Article"
|
|
79
|
+
og.image.url = open_graph_plus_image_url(url_for(format: :opengraph))
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The `open_graph_plus_image_url` helper is available in both controllers and views. It generates a signed URL that tells OpenGraphPlus to screenshot the provided URL instead of the current request.
|
|
85
|
+
|
|
71
86
|
## Verifying OpenGraph Tags
|
|
72
87
|
|
|
73
88
|
You can verify that your pages have the required OpenGraph tags using the included command:
|
|
@@ -5,14 +5,14 @@ require "rails/generators"
|
|
|
5
5
|
module Opengraphplus
|
|
6
6
|
module Generators
|
|
7
7
|
class BaseGenerator < Rails::Generators::Base
|
|
8
|
-
|
|
8
|
+
API_KEY_PREFIXES = %w[ogp_ ogplus_].freeze
|
|
9
9
|
|
|
10
10
|
argument :api_key, type: :string, required: true,
|
|
11
11
|
desc: "Your OpenGraphPlus API key"
|
|
12
12
|
|
|
13
13
|
def validate_api_key
|
|
14
|
-
unless api_key.start_with?(
|
|
15
|
-
say_status :error, "Invalid API key: must start with '#{
|
|
14
|
+
unless API_KEY_PREFIXES.any? { |prefix| api_key.start_with?(prefix) }
|
|
15
|
+
say_status :error, "Invalid API key: must start with '#{API_KEY_PREFIXES.join("' or '")}'", :red
|
|
16
16
|
raise SystemExit
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -23,11 +23,11 @@ module Opengraphplus
|
|
|
23
23
|
yaml_content = credentials.read.presence || ""
|
|
24
24
|
config = parse_yaml(yaml_content)
|
|
25
25
|
|
|
26
|
-
config["
|
|
27
|
-
config["
|
|
26
|
+
config["ogplus"] ||= {}
|
|
27
|
+
config["ogplus"]["api_key"] = api_key
|
|
28
28
|
|
|
29
29
|
credentials.write(yaml_dump(config))
|
|
30
|
-
say_status :insert, "credentials.yml.enc (
|
|
30
|
+
say_status :insert, "credentials.yml.enc (ogplus.api_key)", :green
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def create_initializer
|
|
@@ -13,7 +13,7 @@ module Opengraphplus
|
|
|
13
13
|
desc: "Specific env file to write to (e.g., .env, .envrc)"
|
|
14
14
|
|
|
15
15
|
ENV_FILES = %w[.env .env.local .env.development .env.development.local .envrc].freeze
|
|
16
|
-
ENV_VAR_NAME = "
|
|
16
|
+
ENV_VAR_NAME = "OGPLUS__API_KEY"
|
|
17
17
|
|
|
18
18
|
def append_to_env_file
|
|
19
19
|
if options[:envfile]
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
# Get your API key at https://opengraphplus.com/dashboard
|
|
4
4
|
OpenGraphPlus.configure do |config|
|
|
5
5
|
# Use Rails credentials.
|
|
6
|
-
config.api_key = Rails.application.credentials.
|
|
6
|
+
config.api_key = Rails.application.credentials.ogplus_api_key
|
|
7
7
|
|
|
8
8
|
# Or use ENV:
|
|
9
|
-
# config.api_key = ENV["
|
|
9
|
+
# config.api_key = ENV["OGPLUS__API_KEY"]
|
|
10
10
|
end
|
|
@@ -2,24 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
module OpenGraphPlus
|
|
4
4
|
class ImageGenerator
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def initialize(request)
|
|
8
|
-
@request = request
|
|
5
|
+
def initialize(api_key)
|
|
6
|
+
@api_key = api_key
|
|
9
7
|
end
|
|
10
8
|
|
|
11
|
-
def url
|
|
12
|
-
return nil unless api_key
|
|
9
|
+
def url(source_url)
|
|
10
|
+
return nil unless @api_key
|
|
13
11
|
|
|
14
12
|
Signature::URL.new
|
|
15
|
-
.signed_path("/api/websites/v1", api_key)
|
|
16
|
-
.build("image", url:
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def api_key
|
|
22
|
-
@api_key ||= OpenGraphPlus.configuration.api_key
|
|
13
|
+
.signed_path("/api/websites/v1", @api_key)
|
|
14
|
+
.build("image", url: source_url)
|
|
23
15
|
end
|
|
24
16
|
end
|
|
25
17
|
end
|
|
@@ -7,7 +7,7 @@ module OpenGraphPlus
|
|
|
7
7
|
include OpenGraphPlus::Rails::Helper
|
|
8
8
|
|
|
9
9
|
included do
|
|
10
|
-
helper_method :open_graph, :open_graph_tags, :open_graph_meta_tags
|
|
10
|
+
helper_method :open_graph, :open_graph_tags, :open_graph_meta_tags, :open_graph_plus_image_url
|
|
11
11
|
before_action :set_default_open_graph
|
|
12
12
|
append_before_action :set_default_open_graph_image
|
|
13
13
|
end
|
|
@@ -18,8 +18,8 @@ module OpenGraphPlus
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def
|
|
22
|
-
|
|
21
|
+
def open_graph_plus_image_url(source_url = request.original_url)
|
|
22
|
+
OpenGraphPlus.image_url(source_url)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
private
|
|
@@ -30,10 +30,7 @@ module OpenGraphPlus
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def set_default_open_graph_image
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
generated_url = open_graph_image_generator.url
|
|
36
|
-
open_graph.image.url = generated_url if generated_url
|
|
33
|
+
open_graph.image.url ||= open_graph_plus_image_url
|
|
37
34
|
end
|
|
38
35
|
end
|
|
39
36
|
end
|
|
@@ -10,7 +10,7 @@ module OpenGraphPlus
|
|
|
10
10
|
attr_reader :base_uri
|
|
11
11
|
|
|
12
12
|
def initialize(base_url: nil)
|
|
13
|
-
@base_uri = URI.parse(base_url || ENV.fetch("
|
|
13
|
+
@base_uri = URI.parse(base_url || ENV.fetch("OGPLUS_URL", DEFAULT_BASE_URL))
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def signed_path(prefix, api_key)
|
data/lib/opengraphplus.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opengraphplus
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brad Gessler
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-01-
|
|
10
|
+
date: 2026-01-16 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: activesupport
|