dato 0.7.18 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +42 -5
- data/.ruby-version +1 -1
- data/.travis.yml +2 -2
- data/Gemfile +1 -1
- data/Rakefile +2 -2
- data/TODO.md +28 -0
- data/bin/console +3 -3
- data/bin/rspec +6 -6
- data/dato.gemspec +1 -1
- data/exe/dato +3 -3
- data/lib/dato/account/client.rb +2 -2
- data/lib/dato/api_client.rb +37 -43
- data/lib/dato/api_error.rb +10 -13
- data/lib/dato/cli.rb +18 -18
- data/lib/dato/dump/dsl/add_to_data_file.rb +1 -1
- data/lib/dato/dump/dsl/create_data_file.rb +1 -1
- data/lib/dato/dump/dsl/create_post.rb +1 -1
- data/lib/dato/dump/dsl/directory.rb +4 -4
- data/lib/dato/dump/dsl/root.rb +7 -7
- data/lib/dato/dump/format/json.rb +1 -1
- data/lib/dato/dump/format/toml.rb +5 -6
- data/lib/dato/dump/format/yaml.rb +2 -3
- data/lib/dato/dump/format.rb +3 -3
- data/lib/dato/dump/operation/add_to_data_file.rb +4 -4
- data/lib/dato/dump/operation/create_data_file.rb +3 -3
- data/lib/dato/dump/operation/create_post.rb +5 -6
- data/lib/dato/dump/operation/directory.rb +1 -1
- data/lib/dato/dump/runner.rb +5 -5
- data/lib/dato/dump/ssg_detector.rb +18 -20
- data/lib/dato/json_api_deserializer.rb +15 -16
- data/lib/dato/json_api_serializer.rb +39 -28
- data/lib/dato/json_schema_relationships.rb +19 -23
- data/lib/dato/json_schema_type.rb +47 -0
- data/lib/dato/local/entities_repo.rb +3 -3
- data/lib/dato/local/field_type/color.rb +11 -7
- data/lib/dato/local/field_type/file.rb +18 -24
- data/lib/dato/local/field_type/gallery.rb +1 -1
- data/lib/dato/local/field_type/global_seo.rb +4 -7
- data/lib/dato/local/field_type/lat_lon.rb +1 -1
- data/lib/dato/local/field_type/seo.rb +1 -1
- data/lib/dato/local/field_type/structured_text.rb +63 -0
- data/lib/dato/local/field_type/theme.rb +2 -2
- data/lib/dato/local/field_type/upload_id.rb +5 -5
- data/lib/dato/local/field_type/video.rb +9 -15
- data/lib/dato/local/item.rb +11 -12
- data/lib/dato/local/items_repo.rb +11 -18
- data/lib/dato/local/json_api_entity.rb +4 -3
- data/lib/dato/local/loader.rb +30 -31
- data/lib/dato/local/site.rb +3 -4
- data/lib/dato/paginator.rb +4 -4
- data/lib/dato/repo.rb +23 -30
- data/lib/dato/site/client.rb +5 -5
- data/lib/dato/upload/create_upload_path.rb +7 -10
- data/lib/dato/upload/file.rb +3 -3
- data/lib/dato/upload/image.rb +1 -1
- data/lib/dato/utils/build_modular_block.rb +4 -4
- data/lib/dato/utils/favicon_tags_builder.rb +10 -10
- data/lib/dato/utils/locale_value.rb +1 -1
- data/lib/dato/utils/meta_tags/article_modified_time.rb +3 -3
- data/lib/dato/utils/meta_tags/article_publisher.rb +2 -2
- data/lib/dato/utils/meta_tags/base.rb +5 -6
- data/lib/dato/utils/meta_tags/description.rb +4 -4
- data/lib/dato/utils/meta_tags/image.rb +4 -5
- data/lib/dato/utils/meta_tags/og_locale.rb +2 -2
- data/lib/dato/utils/meta_tags/og_site_name.rb +2 -2
- data/lib/dato/utils/meta_tags/og_type.rb +3 -3
- data/lib/dato/utils/meta_tags/robots.rb +2 -2
- data/lib/dato/utils/meta_tags/title.rb +6 -6
- data/lib/dato/utils/meta_tags/twitter_card.rb +2 -2
- data/lib/dato/utils/meta_tags/twitter_site.rb +2 -2
- data/lib/dato/utils/seo_tags_builder.rb +12 -12
- data/lib/dato/version.rb +1 -1
- data/lib/dato.rb +11 -9
- metadata +10 -8
data/lib/dato/local/loader.rb
CHANGED
@@ -1,32 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "pusher-client"
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
5
|
+
require "dato/local/entities_repo"
|
6
|
+
require "dato/local/items_repo"
|
7
7
|
|
8
8
|
module Dato
|
9
9
|
module Local
|
10
10
|
class Loader
|
11
|
-
attr_reader :client
|
12
|
-
attr_reader :entities_repo
|
13
|
-
attr_reader :items_repo
|
14
|
-
attr_reader :preview_mode
|
11
|
+
attr_reader :client, :entities_repo, :items_repo, :preview_mode
|
15
12
|
|
16
|
-
PUSHER_API_KEY =
|
13
|
+
PUSHER_API_KEY = "75e6ef0fe5d39f481626"
|
17
14
|
|
15
|
+
# rubocop:disable Style/OptionalBooleanParameter
|
18
16
|
def initialize(client, preview_mode = false)
|
19
17
|
@client = client
|
20
18
|
@preview_mode = preview_mode
|
21
19
|
@entities_repo = EntitiesRepo.new
|
22
20
|
@items_repo = ItemsRepo.new(@entities_repo)
|
23
21
|
end
|
22
|
+
# rubocop:enable Style/OptionalBooleanParameter
|
24
23
|
|
25
24
|
def load
|
26
25
|
threads = [
|
27
26
|
Thread.new { Thread.current[:output] = site },
|
28
27
|
Thread.new { Thread.current[:output] = all_items },
|
29
|
-
Thread.new { Thread.current[:output] = all_uploads }
|
28
|
+
Thread.new { Thread.current[:output] = all_uploads },
|
30
29
|
]
|
31
30
|
|
32
31
|
results = threads.map do |t|
|
@@ -39,7 +38,7 @@ module Dato
|
|
39
38
|
end
|
40
39
|
|
41
40
|
def watch(&block)
|
42
|
-
site_id = client.get(
|
41
|
+
site_id = client.get("/site")["data"]["id"]
|
43
42
|
|
44
43
|
return if pusher && pusher.connected
|
45
44
|
|
@@ -69,11 +68,11 @@ module Dato
|
|
69
68
|
private
|
70
69
|
|
71
70
|
def bind_on_site_upsert(&block)
|
72
|
-
bind_on("site:upsert", block) do |
|
71
|
+
bind_on("site:upsert", block) do |_data|
|
73
72
|
threads = [
|
74
73
|
Thread.new { Thread.current[:output] = site },
|
75
74
|
Thread.new { Thread.current[:output] = all_items },
|
76
|
-
Thread.new { Thread.current[:output] = all_uploads }
|
75
|
+
Thread.new { Thread.current[:output] = all_uploads },
|
77
76
|
]
|
78
77
|
|
79
78
|
results = threads.map do |t|
|
@@ -86,16 +85,16 @@ module Dato
|
|
86
85
|
end
|
87
86
|
|
88
87
|
def bind_on_item_upsert(&block)
|
89
|
-
event_type = preview_mode ?
|
88
|
+
event_type = preview_mode ? "preview_mode" : "published_mode"
|
90
89
|
|
91
90
|
bind_on("item:#{event_type}:upsert", block) do |data|
|
92
91
|
payload = client.items.all(
|
93
92
|
{
|
94
|
-
|
95
|
-
version: item_version
|
93
|
+
"filter[ids]" => data[:ids].join(","),
|
94
|
+
version: item_version,
|
96
95
|
},
|
97
96
|
deserialize_response: false,
|
98
|
-
all_pages: true
|
97
|
+
all_pages: true,
|
99
98
|
)
|
100
99
|
|
101
100
|
@entities_repo.upsert_entities(payload)
|
@@ -103,10 +102,10 @@ module Dato
|
|
103
102
|
end
|
104
103
|
|
105
104
|
def bind_on_item_destroy(&block)
|
106
|
-
event_type = preview_mode ?
|
105
|
+
event_type = preview_mode ? "preview_mode" : "published_mode"
|
107
106
|
|
108
107
|
bind_on("item:#{event_type}:destroy", block) do |data|
|
109
|
-
@entities_repo.destroy_entities(
|
108
|
+
@entities_repo.destroy_entities("item", data[:ids])
|
110
109
|
end
|
111
110
|
end
|
112
111
|
|
@@ -114,10 +113,10 @@ module Dato
|
|
114
113
|
bind_on("upload:upsert", block) do |data|
|
115
114
|
payload = client.uploads.all(
|
116
115
|
{
|
117
|
-
|
116
|
+
"filter[ids]" => data[:ids].join(","),
|
118
117
|
},
|
119
118
|
deserialize_response: false,
|
120
|
-
all_pages: true
|
119
|
+
all_pages: true,
|
121
120
|
)
|
122
121
|
|
123
122
|
@entities_repo.upsert_entities(payload)
|
@@ -125,21 +124,21 @@ module Dato
|
|
125
124
|
end
|
126
125
|
|
127
126
|
def bind_on_upload_destroy(&block)
|
128
|
-
bind_on(
|
129
|
-
@entities_repo.destroy_entities(
|
127
|
+
bind_on("upload:destroy", block) do |data|
|
128
|
+
@entities_repo.destroy_entities("upload", data[:ids])
|
130
129
|
end
|
131
130
|
end
|
132
131
|
|
133
132
|
def bind_on_item_type_upsert(&block)
|
134
|
-
bind_on(
|
133
|
+
bind_on("item_type:upsert", block) do |data|
|
135
134
|
data[:ids].each do |id|
|
136
135
|
payload = client.item_types.find(id, {}, deserialize_response: false)
|
137
136
|
@entities_repo.upsert_entities(payload)
|
138
137
|
|
139
138
|
payload = client.items.all(
|
140
|
-
{
|
139
|
+
{ "filter[type]" => id },
|
141
140
|
deserialize_response: false,
|
142
|
-
all_pages: true
|
141
|
+
all_pages: true,
|
143
142
|
)
|
144
143
|
|
145
144
|
@entities_repo.upsert_entities(payload)
|
@@ -148,7 +147,7 @@ module Dato
|
|
148
147
|
end
|
149
148
|
|
150
149
|
def bind_on_item_type_destroy(&block)
|
151
|
-
bind_on(
|
150
|
+
bind_on("item_type:destroy", block) do |data|
|
152
151
|
data[:ids].each do |id|
|
153
152
|
@entities_repo.destroy_item_type(id)
|
154
153
|
end
|
@@ -174,19 +173,19 @@ module Dato
|
|
174
173
|
@pusher ||= PusherClient::Socket.new(
|
175
174
|
PUSHER_API_KEY,
|
176
175
|
secure: true,
|
177
|
-
auth_method: method(:pusher_auth_method)
|
176
|
+
auth_method: method(:pusher_auth_method),
|
178
177
|
)
|
179
178
|
end
|
180
179
|
|
181
180
|
def site
|
182
|
-
client.get(
|
181
|
+
client.get("/site", include: ["item_types", "item_types.fields"])
|
183
182
|
end
|
184
183
|
|
185
184
|
def all_items
|
186
185
|
client.items.all(
|
187
186
|
{ version: item_version },
|
188
187
|
deserialize_response: false,
|
189
|
-
all_pages: true
|
188
|
+
all_pages: true,
|
190
189
|
)
|
191
190
|
end
|
192
191
|
|
@@ -198,9 +197,9 @@ module Dato
|
|
198
197
|
|
199
198
|
def item_version
|
200
199
|
if preview_mode
|
201
|
-
|
200
|
+
"latest"
|
202
201
|
else
|
203
|
-
|
202
|
+
"published"
|
204
203
|
end
|
205
204
|
end
|
206
205
|
|
data/lib/dato/local/site.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require 'active_support/hash_with_indifferent_access'
|
6
|
-
require 'dato/utils/locale_value'
|
3
|
+
require "forwardable"
|
4
|
+
require "dato/utils/locale_value"
|
7
5
|
|
8
6
|
module Dato
|
9
7
|
module Local
|
@@ -11,6 +9,7 @@ module Dato
|
|
11
9
|
extend Forwardable
|
12
10
|
|
13
11
|
attr_reader :entity
|
12
|
+
|
14
13
|
def_delegators :entity, :id, :name, :locales, :domain,
|
15
14
|
:internal_domain, :no_index, :frontend_url
|
16
15
|
|
data/lib/dato/paginator.rb
CHANGED
@@ -12,7 +12,7 @@ module Dato
|
|
12
12
|
items_per_page = 100
|
13
13
|
|
14
14
|
base_response = @client.get(
|
15
|
-
@base_endpoint, @filters.dup.merge(
|
15
|
+
@base_endpoint, @filters.dup.merge("page[limit]" => items_per_page)
|
16
16
|
)
|
17
17
|
|
18
18
|
extra_pages = (
|
@@ -23,9 +23,9 @@ module Dato
|
|
23
23
|
base_response[:data] += @client.get(
|
24
24
|
@base_endpoint,
|
25
25
|
@filters.dup.merge(
|
26
|
-
|
27
|
-
|
28
|
-
)
|
26
|
+
"page[offset]" => items_per_page * (page + 1),
|
27
|
+
"page[limit]" => items_per_page,
|
28
|
+
),
|
29
29
|
)[:data]
|
30
30
|
end
|
31
31
|
|
data/lib/dato/repo.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "dato/json_api_serializer"
|
4
|
+
require "dato/json_api_deserializer"
|
5
|
+
require "dato/paginator"
|
6
6
|
|
7
7
|
module Dato
|
8
8
|
class Repo
|
9
9
|
attr_reader :client, :type, :schema
|
10
10
|
|
11
|
-
IDENTITY_REGEXP = /\{\(.*?definitions%2F(.*?)%2Fdefinitions%2Fidentity\)}
|
11
|
+
IDENTITY_REGEXP = /\{\(.*?definitions%2F(.*?)%2Fdefinitions%2Fidentity\)}/.freeze
|
12
12
|
|
13
13
|
METHOD_NAMES = {
|
14
|
-
|
15
|
-
|
14
|
+
"instances" => :all,
|
15
|
+
"self" => :find,
|
16
16
|
}.freeze
|
17
17
|
|
18
18
|
def initialize(client, type, schema)
|
@@ -32,23 +32,23 @@ module Dato
|
|
32
32
|
private
|
33
33
|
|
34
34
|
def method_missing(method, *args, &block)
|
35
|
-
link = schema.links.find do |
|
36
|
-
METHOD_NAMES.fetch(
|
35
|
+
link = schema.links.find do |ilink|
|
36
|
+
METHOD_NAMES.fetch(ilink.rel, ilink.rel).to_sym == method.to_sym
|
37
37
|
end
|
38
38
|
|
39
|
-
return super
|
39
|
+
return super unless link
|
40
40
|
|
41
41
|
min_arguments_count = [
|
42
42
|
link.href.scan(IDENTITY_REGEXP).size,
|
43
|
-
link.schema && link.method != :get ? 1 : 0
|
43
|
+
link.schema && link.method != :get ? 1 : 0,
|
44
44
|
].reduce(0, :+)
|
45
45
|
|
46
|
-
(args.size >= min_arguments_count)
|
47
|
-
raise
|
46
|
+
(args.size >= min_arguments_count) ||
|
47
|
+
raise(ArgumentError, "wrong number of arguments (given #{args.size}, expected #{min_arguments_count})")
|
48
48
|
|
49
49
|
placeholders = []
|
50
50
|
|
51
|
-
url = link[
|
51
|
+
url = link["href"].gsub(IDENTITY_REGEXP) do |_stuff|
|
52
52
|
placeholder = args.shift.to_s
|
53
53
|
placeholders << placeholder
|
54
54
|
placeholder
|
@@ -61,19 +61,16 @@ module Dato
|
|
61
61
|
body = link.schema ? args.shift : {}
|
62
62
|
query_string = args.shift || {}
|
63
63
|
|
64
|
-
elsif link.method
|
65
|
-
query_string = args.shift || {}
|
66
|
-
|
67
|
-
elsif link.method == :get
|
64
|
+
elsif %i[get delete].include?(link.method)
|
68
65
|
query_string = args.shift || {}
|
69
66
|
end
|
70
67
|
|
71
68
|
options = args.any? ? args.shift.symbolize_keys : {}
|
72
69
|
|
73
70
|
if link.schema && %i[post put].include?(link.method) && options.fetch(:serialize_response, true)
|
74
|
-
body = JsonApiSerializer.new(
|
71
|
+
body = JsonApiSerializer.new(link: link).serialize(
|
75
72
|
body,
|
76
|
-
link.method == :post ? nil : placeholders.last
|
73
|
+
link.method == :post ? nil : placeholders.last,
|
77
74
|
)
|
78
75
|
end
|
79
76
|
|
@@ -92,21 +89,19 @@ module Dato
|
|
92
89
|
if response && response[:data] && response[:data].is_a?(Hash) && response[:data][:type] == "job"
|
93
90
|
job_result = nil
|
94
91
|
|
95
|
-
|
92
|
+
until job_result
|
96
93
|
begin
|
97
94
|
sleep(1)
|
98
95
|
job_result = client.job_result.find(response[:data][:id])
|
99
|
-
rescue ApiError =>
|
100
|
-
if
|
101
|
-
raise error
|
102
|
-
end
|
96
|
+
rescue ApiError => e
|
97
|
+
raise e if e.response[:status] != 404
|
103
98
|
end
|
104
99
|
end
|
105
100
|
|
106
101
|
if job_result[:status] < 200 || job_result[:status] >= 300
|
107
102
|
error = ApiError.new(
|
108
103
|
status: job_result[:status],
|
109
|
-
body: JSON.dump(job_result[:payload])
|
104
|
+
body: JSON.dump(job_result[:payload]),
|
110
105
|
)
|
111
106
|
|
112
107
|
puts "===="
|
@@ -121,12 +116,10 @@ module Dato
|
|
121
116
|
else
|
122
117
|
job_result.payload
|
123
118
|
end
|
119
|
+
elsif options.fetch(:deserialize_response, true)
|
120
|
+
JsonApiDeserializer.new(link.target_schema).deserialize(response)
|
124
121
|
else
|
125
|
-
|
126
|
-
JsonApiDeserializer.new(link.target_schema).deserialize(response)
|
127
|
-
else
|
128
|
-
response
|
129
|
-
end
|
122
|
+
response
|
130
123
|
end
|
131
124
|
end
|
132
125
|
end
|
data/lib/dato/site/client.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "dato/api_client"
|
4
|
+
require "dato/upload/file"
|
5
|
+
require "dato/upload/create_upload_path"
|
6
6
|
|
7
7
|
module Dato
|
8
8
|
module Site
|
9
9
|
class Client
|
10
10
|
include ApiClient
|
11
11
|
|
12
|
-
json_schema
|
12
|
+
json_schema "site-api"
|
13
13
|
|
14
14
|
def create_upload_path(path_or_url)
|
15
15
|
file = Upload::CreateUploadPath.new(self, path_or_url)
|
@@ -30,7 +30,7 @@ module Dato
|
|
30
30
|
request(
|
31
31
|
:post,
|
32
32
|
"/pusher/authenticate",
|
33
|
-
{ socket_id: socket_id, channel_name: channel}
|
33
|
+
{ socket_id: socket_id, channel_name: channel },
|
34
34
|
)
|
35
35
|
end
|
36
36
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "mime/types"
|
4
|
+
require "tempfile"
|
5
|
+
require "addressable"
|
6
|
+
require "net/http"
|
7
7
|
|
8
8
|
module Dato
|
9
9
|
module Upload
|
@@ -19,7 +19,7 @@ module Dato
|
|
19
19
|
@file ||= if http_source?
|
20
20
|
uri = Addressable::URI.parse(source)
|
21
21
|
ext = ::File.extname(uri.path).downcase
|
22
|
-
tempfile = Tempfile.new([
|
22
|
+
tempfile = Tempfile.new(["file", ext])
|
23
23
|
tempfile.binmode
|
24
24
|
tempfile.write(download_file(source))
|
25
25
|
tempfile.rewind
|
@@ -31,7 +31,7 @@ module Dato
|
|
31
31
|
|
32
32
|
def http_source?
|
33
33
|
uri = Addressable::URI.parse(source)
|
34
|
-
uri.scheme ==
|
34
|
+
uri.scheme == "http" || uri.scheme == "https"
|
35
35
|
rescue Addressable::URI::InvalidURIError
|
36
36
|
false
|
37
37
|
end
|
@@ -51,9 +51,7 @@ module Dato
|
|
51
51
|
mime_type = MIME::Types.of(filename).first
|
52
52
|
|
53
53
|
request = Net::HTTP::Put.new(uri)
|
54
|
-
if mime_type
|
55
|
-
request.add_field("Content-Type", mime_type.to_s)
|
56
|
-
end
|
54
|
+
request.add_field("Content-Type", mime_type.to_s) if mime_type
|
57
55
|
request.body = file.read
|
58
56
|
|
59
57
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -78,4 +76,3 @@ module Dato
|
|
78
76
|
end
|
79
77
|
end
|
80
78
|
end
|
81
|
-
|
data/lib/dato/upload/file.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "dato/upload/create_upload_path"
|
4
4
|
|
5
5
|
module Dato
|
6
6
|
module Upload
|
@@ -18,14 +18,14 @@ module Dato
|
|
18
18
|
upload_path = CreateUploadPath.new(client, source).upload_path
|
19
19
|
|
20
20
|
upload = client.uploads.create(
|
21
|
-
upload_attributes.merge(path: upload_path)
|
21
|
+
upload_attributes.merge(path: upload_path),
|
22
22
|
)
|
23
23
|
|
24
24
|
{
|
25
25
|
alt: nil,
|
26
26
|
title: nil,
|
27
27
|
custom_data: {},
|
28
|
-
}.merge(field_attributes).merge(upload_id: upload[
|
28
|
+
}.merge(field_attributes).merge(upload_id: upload["id"])
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/lib/dato/upload/image.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "dato/json_api_serializer"
|
4
4
|
|
5
5
|
module Dato
|
6
6
|
module Utils
|
7
7
|
module BuildModularBlock
|
8
8
|
def self.build(unserialized_body)
|
9
|
-
json_api_serializer = JsonApiSerializer.new(
|
9
|
+
json_api_serializer = JsonApiSerializer.new(type: "item")
|
10
10
|
attributes = json_api_serializer.serialized_attributes(unserialized_body)
|
11
11
|
|
12
12
|
payload = {
|
13
|
-
type:
|
13
|
+
type: "item",
|
14
14
|
attributes: attributes,
|
15
15
|
relationships: {
|
16
16
|
item_type: {
|
17
17
|
data: {
|
18
18
|
id: unserialized_body[:item_type],
|
19
|
-
type:
|
19
|
+
type: "item_type",
|
20
20
|
},
|
21
21
|
},
|
22
22
|
},
|
@@ -20,7 +20,7 @@ module Dato
|
|
20
20
|
build_apple_icon_tags,
|
21
21
|
build_windows_tags,
|
22
22
|
build_color_tags,
|
23
|
-
build_app_name_tag
|
23
|
+
build_app_name_tag,
|
24
24
|
].flatten.compact
|
25
25
|
end
|
26
26
|
|
@@ -29,9 +29,9 @@ module Dato
|
|
29
29
|
|
30
30
|
APPLE_TOUCH_ICON_SIZES.map do |size|
|
31
31
|
link_tag(
|
32
|
-
|
32
|
+
"apple-touch-icon",
|
33
33
|
url(size),
|
34
|
-
sizes: "#{size}x#{size}"
|
34
|
+
sizes: "#{size}x#{size}",
|
35
35
|
)
|
36
36
|
end
|
37
37
|
end
|
@@ -41,10 +41,10 @@ module Dato
|
|
41
41
|
|
42
42
|
ICON_SIZES.map do |size|
|
43
43
|
link_tag(
|
44
|
-
|
44
|
+
"icon",
|
45
45
|
url(size),
|
46
46
|
sizes: "#{size}x#{size}",
|
47
|
-
type: "image/#{site.favicon.format}"
|
47
|
+
type: "image/#{site.favicon.format}",
|
48
48
|
)
|
49
49
|
end
|
50
50
|
end
|
@@ -58,15 +58,15 @@ module Dato
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def build_app_name_tag
|
61
|
-
meta_tag(
|
61
|
+
meta_tag("application-name", site.name)
|
62
62
|
end
|
63
63
|
|
64
64
|
def build_color_tags
|
65
65
|
return unless theme_color
|
66
66
|
|
67
67
|
[
|
68
|
-
meta_tag(
|
69
|
-
meta_tag(
|
68
|
+
meta_tag("theme-color", theme_color),
|
69
|
+
meta_tag("msapplication-TileColor", theme_color),
|
70
70
|
]
|
71
71
|
end
|
72
72
|
|
@@ -75,11 +75,11 @@ module Dato
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def meta_tag(name, value)
|
78
|
-
{ tag_name:
|
78
|
+
{ tag_name: "meta", attributes: { name: name, content: value } }
|
79
79
|
end
|
80
80
|
|
81
81
|
def link_tag(rel, href, attrs = {})
|
82
|
-
{ tag_name:
|
82
|
+
{ tag_name: "link", attributes: attrs.merge(rel: rel, href: href) }
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "dato/utils/meta_tags/base"
|
4
|
+
require "time"
|
5
5
|
|
6
6
|
module Dato
|
7
7
|
module Utils
|
8
8
|
module MetaTags
|
9
9
|
class ArticleModifiedTime < Base
|
10
10
|
def build
|
11
|
-
og_tag(
|
11
|
+
og_tag("article:modified_time", item.updated_at.iso8601) if item
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "dato/utils/meta_tags/base"
|
4
4
|
|
5
5
|
module Dato
|
6
6
|
module Utils
|
7
7
|
module MetaTags
|
8
8
|
class ArticlePublisher < Base
|
9
9
|
def build
|
10
|
-
og_tag(
|
10
|
+
og_tag("article:publisher", facebook_page_url) if facebook_page_url
|
11
11
|
end
|
12
12
|
|
13
13
|
def facebook_page_url
|
@@ -1,8 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require 'active_support/core_ext/object/blank'
|
3
|
+
require "forwardable"
|
4
|
+
require "dato/local/field_type/seo"
|
6
5
|
|
7
6
|
module Dato
|
8
7
|
module Utils
|
@@ -19,7 +18,7 @@ module Dato
|
|
19
18
|
fallback_seo = site.global_seo && site.global_seo.fallback_seo
|
20
19
|
|
21
20
|
seo_field = item &&
|
22
|
-
item.fields.detect { |f| f.field_type ==
|
21
|
+
item.fields.detect { |f| f.field_type == "seo" }
|
23
22
|
|
24
23
|
item_seo_value = seo_field &&
|
25
24
|
item[seo_field.api_key] &&
|
@@ -36,11 +35,11 @@ module Dato
|
|
36
35
|
end
|
37
36
|
|
38
37
|
def meta_tag(name, content)
|
39
|
-
tag(
|
38
|
+
tag("meta", name: name, content: content)
|
40
39
|
end
|
41
40
|
|
42
41
|
def og_tag(property, content)
|
43
|
-
tag(
|
42
|
+
tag("meta", property: property, content: content)
|
44
43
|
end
|
45
44
|
|
46
45
|
def card_tag(name, content)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "dato/utils/meta_tags/base"
|
4
4
|
|
5
5
|
module Dato
|
6
6
|
module Utils
|
@@ -10,9 +10,9 @@ module Dato
|
|
10
10
|
return unless description.present?
|
11
11
|
|
12
12
|
[
|
13
|
-
meta_tag(
|
14
|
-
og_tag(
|
15
|
-
card_tag(
|
13
|
+
meta_tag("description", description),
|
14
|
+
og_tag("og:description", description),
|
15
|
+
card_tag("twitter:description", description),
|
16
16
|
]
|
17
17
|
end
|
18
18
|
|