article_json 0.4.0 → 0.4.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 +4 -4
- data/CHANGELOG.md +30 -1
- data/README.md +30 -18
- data/bin/update_reference_document.sh +0 -4
- data/lib/article_json/article.rb +0 -12
- data/lib/article_json/configuration.rb +4 -4
- data/lib/article_json/elements/heading.rb +0 -1
- data/lib/article_json/elements/image.rb +0 -1
- data/lib/article_json/elements/list.rb +0 -1
- data/lib/article_json/elements/paragraph.rb +1 -1
- data/lib/article_json/elements/quote.rb +0 -1
- data/lib/article_json/elements/text.rb +1 -1
- data/lib/article_json/elements/text_box.rb +0 -1
- data/lib/article_json/export/amp/custom_element_library_resolver.rb +0 -1
- data/lib/article_json/export/amp/elements/embed.rb +42 -30
- data/lib/article_json/export/amp/elements/image.rb +7 -5
- data/lib/article_json/export/amp/exporter.rb +4 -2
- data/lib/article_json/export/apple_news/elements/embed.rb +1 -1
- data/lib/article_json/export/apple_news/elements/image.rb +2 -1
- data/lib/article_json/export/apple_news/elements/paragraph.rb +1 -1
- data/lib/article_json/export/apple_news/elements/text.rb +15 -2
- data/lib/article_json/export/apple_news/exporter.rb +1 -1
- data/lib/article_json/export/common/html/elements/embed.rb +2 -1
- data/lib/article_json/export/common/html/elements/image.rb +2 -1
- data/lib/article_json/export/common/html/elements/text.rb +2 -0
- data/lib/article_json/import/google_doc/html/embedded_parser.rb +1 -0
- data/lib/article_json/import/google_doc/html/heading_parser.rb +5 -5
- data/lib/article_json/import/google_doc/html/image_parser.rb +2 -0
- data/lib/article_json/import/google_doc/html/list_parser.rb +2 -2
- data/lib/article_json/import/google_doc/html/node_analyzer.rb +14 -2
- data/lib/article_json/import/google_doc/html/parser.rb +1 -0
- data/lib/article_json/import/google_doc/html/shared/caption.rb +1 -0
- data/lib/article_json/import/google_doc/html/shared/float.rb +2 -0
- data/lib/article_json/import/google_doc/html/text_box_parser.rb +2 -1
- data/lib/article_json/import/google_doc/html/text_parser.rb +2 -0
- data/lib/article_json/utils/additional_element_placer.rb +2 -0
- data/lib/article_json/utils/o_embed_resolver/base.rb +14 -4
- data/lib/article_json/utils/o_embed_resolver/facebook_video.rb +1 -1
- data/lib/article_json/utils/o_embed_resolver/slideshare.rb +2 -2
- data/lib/article_json/utils/o_embed_resolver/youtube_video.rb +13 -0
- data/lib/article_json/version.rb +1 -1
- data/lib/article_json.rb +0 -11
- metadata +3 -18
- data/bin/article_json_export_facebook.rb +0 -16
- data/lib/article_json/export/facebook_instant_article/elements/base.rb +0 -30
- data/lib/article_json/export/facebook_instant_article/elements/embed.rb +0 -44
- data/lib/article_json/export/facebook_instant_article/elements/heading.rb +0 -11
- data/lib/article_json/export/facebook_instant_article/elements/image.rb +0 -11
- data/lib/article_json/export/facebook_instant_article/elements/list.rb +0 -11
- data/lib/article_json/export/facebook_instant_article/elements/paragraph.rb +0 -11
- data/lib/article_json/export/facebook_instant_article/elements/quote.rb +0 -30
- data/lib/article_json/export/facebook_instant_article/elements/text.rb +0 -11
- data/lib/article_json/export/facebook_instant_article/elements/text_box.rb +0 -40
- data/lib/article_json/export/facebook_instant_article/exporter.rb +0 -17
|
@@ -20,7 +20,7 @@ module ArticleJSON
|
|
|
20
20
|
private
|
|
21
21
|
|
|
22
22
|
def embed_node
|
|
23
|
-
type = @element.embed_type.to_s.tr('_','-')
|
|
23
|
+
type = @element.embed_type.to_s.tr('_', '-')
|
|
24
24
|
create_element(:div, class: "embed #{type}") do |div|
|
|
25
25
|
div.add_child(embedded_object)
|
|
26
26
|
end
|
|
@@ -28,6 +28,7 @@ module ArticleJSON
|
|
|
28
28
|
|
|
29
29
|
def embedded_object
|
|
30
30
|
return unavailable_node unless @element.oembed_data
|
|
31
|
+
|
|
31
32
|
Nokogiri::HTML.fragment(@element.oembed_data[:html])
|
|
32
33
|
end
|
|
33
34
|
|
|
@@ -19,7 +19,7 @@ module ArticleJSON
|
|
|
19
19
|
# @return [Nokogiri::XML::NodeSet]
|
|
20
20
|
def figure_node
|
|
21
21
|
create_element(:figure, node_opts) do |figure|
|
|
22
|
-
node =
|
|
22
|
+
node = @element&.href ? href_node : image_node
|
|
23
23
|
figure.add_child(node)
|
|
24
24
|
if @element.caption&.any?
|
|
25
25
|
figure.add_child(caption_node(:figcaption))
|
|
@@ -42,6 +42,7 @@ module ArticleJSON
|
|
|
42
42
|
# @return [Hash]
|
|
43
43
|
def node_opts
|
|
44
44
|
return if floating_class.nil?
|
|
45
|
+
|
|
45
46
|
{ class: floating_class }
|
|
46
47
|
end
|
|
47
48
|
end
|
|
@@ -11,6 +11,7 @@ module ArticleJSON
|
|
|
11
11
|
return bold_and_italic_node if @element.bold && @element.italic
|
|
12
12
|
return bold_node if @element.bold
|
|
13
13
|
return italic_node if @element.italic
|
|
14
|
+
|
|
14
15
|
content_node
|
|
15
16
|
end
|
|
16
17
|
|
|
@@ -38,6 +39,7 @@ module ArticleJSON
|
|
|
38
39
|
# @return [Nokogiri::XML::NodeSet]
|
|
39
40
|
def content_node
|
|
40
41
|
return create_text_nodes(@element.content) if @element.href.nil?
|
|
42
|
+
|
|
41
43
|
create_element(:a, href: @element.href) do |a|
|
|
42
44
|
a.add_child(create_text_nodes(@element.content))
|
|
43
45
|
end
|
|
@@ -19,11 +19,11 @@ module ArticleJSON
|
|
|
19
19
|
# @return [Integer]
|
|
20
20
|
def level
|
|
21
21
|
case @node.name
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
when 'h1' then 1
|
|
23
|
+
when 'h2' then 2
|
|
24
|
+
when 'h3' then 3
|
|
25
|
+
when 'h4' then 4
|
|
26
|
+
when 'h5' then 5
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -31,6 +31,7 @@ module ArticleJSON
|
|
|
31
31
|
# @return [Boolean]
|
|
32
32
|
def empty?
|
|
33
33
|
return @is_empty if defined? @is_empty
|
|
34
|
+
|
|
34
35
|
@is_empty = node.inner_text.strip.empty? && !image? && !hr? && !br?
|
|
35
36
|
end
|
|
36
37
|
|
|
@@ -38,6 +39,7 @@ module ArticleJSON
|
|
|
38
39
|
# @return [Boolean]
|
|
39
40
|
def heading?
|
|
40
41
|
return @is_heading if defined? @is_heading
|
|
42
|
+
|
|
41
43
|
@is_heading =
|
|
42
44
|
!quote? && !text_box? && %w(h1 h2 h3 h4 h5).include?(node.name)
|
|
43
45
|
end
|
|
@@ -52,6 +54,7 @@ module ArticleJSON
|
|
|
52
54
|
# @return [Boolean]
|
|
53
55
|
def paragraph?
|
|
54
56
|
return @is_paragraph if defined? @is_paragraph
|
|
57
|
+
|
|
55
58
|
@is_paragraph =
|
|
56
59
|
node.name == 'p' &&
|
|
57
60
|
!empty? &&
|
|
@@ -65,7 +68,8 @@ module ArticleJSON
|
|
|
65
68
|
# @return [Boolean]
|
|
66
69
|
def list?
|
|
67
70
|
return @is_list if defined? @is_list
|
|
68
|
-
|
|
71
|
+
|
|
72
|
+
@is_list = %w[ul ol].include?(node.name)
|
|
69
73
|
end
|
|
70
74
|
|
|
71
75
|
# Check if the node starts a text box
|
|
@@ -73,6 +77,7 @@ module ArticleJSON
|
|
|
73
77
|
# @return [Boolean]
|
|
74
78
|
def text_box?
|
|
75
79
|
return @is_text_box if defined? @is_text_box
|
|
80
|
+
|
|
76
81
|
@is_text_box = begins_with?('textbox:') || begins_with?('highlight:')
|
|
77
82
|
end
|
|
78
83
|
|
|
@@ -81,6 +86,7 @@ module ArticleJSON
|
|
|
81
86
|
# @return [Boolean]
|
|
82
87
|
def quote?
|
|
83
88
|
return @is_quote if defined? @is_quote
|
|
89
|
+
|
|
84
90
|
@is_quote = has_text?('quote:')
|
|
85
91
|
end
|
|
86
92
|
|
|
@@ -88,6 +94,7 @@ module ArticleJSON
|
|
|
88
94
|
# @return [Boolean]
|
|
89
95
|
def image?
|
|
90
96
|
return @is_image if defined? @is_image
|
|
97
|
+
|
|
91
98
|
@is_image = image_url? || node.xpath('.//img').length > 0
|
|
92
99
|
end
|
|
93
100
|
|
|
@@ -105,6 +112,7 @@ module ArticleJSON
|
|
|
105
112
|
# @return [Boolean]
|
|
106
113
|
def embed?
|
|
107
114
|
return @is_embed if defined? @is_embed
|
|
115
|
+
|
|
108
116
|
@is_embed = EmbeddedParser.supported?(node)
|
|
109
117
|
end
|
|
110
118
|
|
|
@@ -113,6 +121,7 @@ module ArticleJSON
|
|
|
113
121
|
# @return [Boolean]
|
|
114
122
|
def br?
|
|
115
123
|
return @is_br if defined? @is_br
|
|
124
|
+
|
|
116
125
|
@is_br = node.name == 'br' || only_includes_brs?
|
|
117
126
|
end
|
|
118
127
|
|
|
@@ -129,6 +138,7 @@ module ArticleJSON
|
|
|
129
138
|
return :quote if quote?
|
|
130
139
|
return :image if image?
|
|
131
140
|
return :embed if embed?
|
|
141
|
+
|
|
132
142
|
:unknown
|
|
133
143
|
end
|
|
134
144
|
|
|
@@ -138,9 +148,11 @@ module ArticleJSON
|
|
|
138
148
|
# @return [Boolean]
|
|
139
149
|
def only_includes_brs?
|
|
140
150
|
return false unless node.inner_text.strip.empty?
|
|
151
|
+
|
|
141
152
|
tags = node.children.map(&:name)
|
|
142
153
|
# Check if it only contains <br> and text nodes
|
|
143
|
-
return false unless tags.all? { |tag| %w
|
|
154
|
+
return false unless tags.all? { |tag| %w[br text].include? tag }
|
|
155
|
+
|
|
144
156
|
# Check if at least one is a `<br>` node
|
|
145
157
|
tags.include?('br')
|
|
146
158
|
end
|
|
@@ -8,9 +8,11 @@ module ArticleJSON
|
|
|
8
8
|
# @return [Symbol]
|
|
9
9
|
def float
|
|
10
10
|
return unless @float_node.has_attribute?('class')
|
|
11
|
+
|
|
11
12
|
node_class = @float_node.attribute('class').value || ''
|
|
12
13
|
return :right if @css_analyzer.right_aligned?(node_class)
|
|
13
14
|
return :left if @css_analyzer.left_aligned?(node_class)
|
|
15
|
+
|
|
14
16
|
nil
|
|
15
17
|
end
|
|
16
18
|
end
|
|
@@ -10,7 +10,7 @@ module ArticleJSON
|
|
|
10
10
|
# May contain tags, too.
|
|
11
11
|
# @param [Array[Nokogiri::HTML::Node]] nodes
|
|
12
12
|
# @param [ArticleJSON::Import::GoogleDoc::HTML::CSSAnalyzer] css_analyzer
|
|
13
|
-
def initialize(type_node
|
|
13
|
+
def initialize(type_node:, nodes:, css_analyzer:)
|
|
14
14
|
@nodes = nodes.reject { |node| NodeAnalyzer.new(node).empty? }
|
|
15
15
|
@css_analyzer = css_analyzer
|
|
16
16
|
|
|
@@ -32,6 +32,7 @@ module ArticleJSON
|
|
|
32
32
|
match = /(.*?)[\s\u00A0]+\[(?<tags>.*)\]/
|
|
33
33
|
.match(@type_node.inner_text)
|
|
34
34
|
return [] unless match
|
|
35
|
+
|
|
35
36
|
match[:tags].split(' ')
|
|
36
37
|
end
|
|
37
38
|
|
|
@@ -43,6 +43,7 @@ module ArticleJSON
|
|
|
43
43
|
if @node.name == 'span' &&
|
|
44
44
|
@node.first_element_child&.name == 'a' &&
|
|
45
45
|
@node.first_element_child&.has_attribute?('href')
|
|
46
|
+
|
|
46
47
|
strip_google_redirect(
|
|
47
48
|
@node.first_element_child.attribute('href').value
|
|
48
49
|
)
|
|
@@ -68,6 +69,7 @@ module ArticleJSON
|
|
|
68
69
|
def extract(node:, css_analyzer:)
|
|
69
70
|
node.children.map do |child_node|
|
|
70
71
|
next if NodeAnalyzer.new(child_node).empty?
|
|
72
|
+
|
|
71
73
|
new(node: child_node, css_analyzer: css_analyzer).element
|
|
72
74
|
end.compact
|
|
73
75
|
end
|
|
@@ -40,6 +40,7 @@ module ArticleJSON
|
|
|
40
40
|
# @return [Array[ArticleJSON::Elements::Base|Object]]
|
|
41
41
|
def merge_elements
|
|
42
42
|
return @additional_elements if @elements.nil? || @elements.empty?
|
|
43
|
+
|
|
43
44
|
remaining_elements = @additional_elements.dup
|
|
44
45
|
next_in = insert_next_element_in(0, remaining_elements)
|
|
45
46
|
characters_passed = 0
|
|
@@ -48,6 +49,7 @@ module ArticleJSON
|
|
|
48
49
|
.each_with_object([]) do |(element, next_element), result|
|
|
49
50
|
result << element
|
|
50
51
|
next if remaining_elements.empty?
|
|
52
|
+
|
|
51
53
|
if element.respond_to?(:length)
|
|
52
54
|
characters_passed += element.length
|
|
53
55
|
next_in -= element.length
|
|
@@ -23,8 +23,10 @@ module ArticleJSON
|
|
|
23
23
|
def unavailable_message
|
|
24
24
|
[
|
|
25
25
|
ArticleJSON::Elements::Text.new(content: "The #{name} "),
|
|
26
|
-
ArticleJSON::Elements::Text.new(
|
|
27
|
-
|
|
26
|
+
ArticleJSON::Elements::Text.new(
|
|
27
|
+
content: source_url,
|
|
28
|
+
href: source_url
|
|
29
|
+
),
|
|
28
30
|
ArticleJSON::Elements::Text.new(content: ' is not available.'),
|
|
29
31
|
]
|
|
30
32
|
end
|
|
@@ -44,19 +46,27 @@ module ArticleJSON
|
|
|
44
46
|
# @return [Hash|nil]
|
|
45
47
|
def parsed_api_response
|
|
46
48
|
return @api_response if defined? @api_response
|
|
49
|
+
|
|
47
50
|
@api_response = begin
|
|
48
51
|
uri = URI.parse(oembed_url)
|
|
49
52
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
50
53
|
http.use_ssl = (uri.scheme == 'https')
|
|
51
54
|
response = http.request(Net::HTTP::Get.new(uri, http_headers))
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
|
|
56
|
+
if response.is_a? Net::HTTPSuccess
|
|
57
|
+
data = JSON.parse(response.body, symbolize_names: true)
|
|
58
|
+
transform_api_response(data)
|
|
54
59
|
end
|
|
55
60
|
rescue Net::ProtocolError, JSON::ParserError
|
|
56
61
|
nil
|
|
57
62
|
end
|
|
58
63
|
end
|
|
59
64
|
|
|
65
|
+
# @return [Hash]
|
|
66
|
+
def transform_api_response(data)
|
|
67
|
+
data
|
|
68
|
+
end
|
|
69
|
+
|
|
60
70
|
# @return [Hash]
|
|
61
71
|
def http_headers
|
|
62
72
|
headers = { 'Content-Type' => 'application/json' }
|
|
@@ -11,8 +11,8 @@ module ArticleJSON
|
|
|
11
11
|
# The URL for the oembed API call
|
|
12
12
|
# @return [String]
|
|
13
13
|
def oembed_url
|
|
14
|
-
'https://www.slideshare.net/api/oembed/2?format=json&url='\
|
|
15
|
-
|
|
14
|
+
'https://www.slideshare.net/api/oembed/2?format=json&url=' \
|
|
15
|
+
"#{source_url}"
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
# The URL of the slideshow
|
|
@@ -19,6 +19,19 @@ module ArticleJSON
|
|
|
19
19
|
def source_url
|
|
20
20
|
"https://www.youtube.com/watch?v=#{@element.embed_id}"
|
|
21
21
|
end
|
|
22
|
+
|
|
23
|
+
protected
|
|
24
|
+
|
|
25
|
+
# @param [Hash] data
|
|
26
|
+
# @return [Hash]
|
|
27
|
+
def transform_api_response(data)
|
|
28
|
+
return data unless data&.dig(:thumbnail_url)
|
|
29
|
+
|
|
30
|
+
# Replace the default YouTube thumbnail with the max resolution version
|
|
31
|
+
data.merge(
|
|
32
|
+
thumbnail_url: data[:thumbnail_url].sub(%r{hqdefault\.jpg$}, 'maxresdefault.jpg')
|
|
33
|
+
)
|
|
34
|
+
end
|
|
22
35
|
end
|
|
23
36
|
end
|
|
24
37
|
end
|
data/lib/article_json/version.rb
CHANGED
data/lib/article_json.rb
CHANGED
|
@@ -100,15 +100,4 @@ require_relative 'article_json/export/amp/elements/embed'
|
|
|
100
100
|
require_relative 'article_json/export/amp/custom_element_library_resolver'
|
|
101
101
|
require_relative 'article_json/export/amp/exporter'
|
|
102
102
|
|
|
103
|
-
require_relative 'article_json/export/facebook_instant_article/elements/base'
|
|
104
|
-
require_relative 'article_json/export/facebook_instant_article/elements/text'
|
|
105
|
-
require_relative 'article_json/export/facebook_instant_article/elements/paragraph'
|
|
106
|
-
require_relative 'article_json/export/facebook_instant_article/elements/list'
|
|
107
|
-
require_relative 'article_json/export/facebook_instant_article/elements/heading'
|
|
108
|
-
require_relative 'article_json/export/facebook_instant_article/elements/quote'
|
|
109
|
-
require_relative 'article_json/export/facebook_instant_article/elements/text_box'
|
|
110
|
-
require_relative 'article_json/export/facebook_instant_article/elements/image'
|
|
111
|
-
require_relative 'article_json/export/facebook_instant_article/elements/embed'
|
|
112
|
-
require_relative 'article_json/export/facebook_instant_article/exporter'
|
|
113
|
-
|
|
114
103
|
require_relative 'article_json/article'
|
metadata
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: article_json
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Sager
|
|
8
8
|
- Manu Campos
|
|
9
9
|
- Nicolas Fricke
|
|
10
10
|
- Damien Dillon
|
|
11
|
-
autorequire:
|
|
12
11
|
bindir: bin
|
|
13
12
|
cert_chain: []
|
|
14
|
-
date:
|
|
13
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
15
14
|
dependencies:
|
|
16
15
|
- !ruby/object:Gem::Dependency
|
|
17
16
|
name: nokogiri
|
|
@@ -105,7 +104,6 @@ description: |2
|
|
|
105
104
|
- simple HTML format
|
|
106
105
|
- AMP format
|
|
107
106
|
- Apple News Format (ANF)
|
|
108
|
-
- Facebook Instant Article HTML
|
|
109
107
|
- plain text
|
|
110
108
|
- JSON
|
|
111
109
|
email: info@devex.com
|
|
@@ -119,7 +117,6 @@ files:
|
|
|
119
117
|
- README.md
|
|
120
118
|
- bin/article_json_export_amp.rb
|
|
121
119
|
- bin/article_json_export_apple_news.rb
|
|
122
|
-
- bin/article_json_export_facebook.rb
|
|
123
120
|
- bin/article_json_export_google_doc.rb
|
|
124
121
|
- bin/article_json_export_html.rb
|
|
125
122
|
- bin/article_json_export_plain_text.rb
|
|
@@ -173,16 +170,6 @@ files:
|
|
|
173
170
|
- lib/article_json/export/common/html/elements/text.rb
|
|
174
171
|
- lib/article_json/export/common/html/elements/text_box.rb
|
|
175
172
|
- lib/article_json/export/common/html/exporter.rb
|
|
176
|
-
- lib/article_json/export/facebook_instant_article/elements/base.rb
|
|
177
|
-
- lib/article_json/export/facebook_instant_article/elements/embed.rb
|
|
178
|
-
- lib/article_json/export/facebook_instant_article/elements/heading.rb
|
|
179
|
-
- lib/article_json/export/facebook_instant_article/elements/image.rb
|
|
180
|
-
- lib/article_json/export/facebook_instant_article/elements/list.rb
|
|
181
|
-
- lib/article_json/export/facebook_instant_article/elements/paragraph.rb
|
|
182
|
-
- lib/article_json/export/facebook_instant_article/elements/quote.rb
|
|
183
|
-
- lib/article_json/export/facebook_instant_article/elements/text.rb
|
|
184
|
-
- lib/article_json/export/facebook_instant_article/elements/text_box.rb
|
|
185
|
-
- lib/article_json/export/facebook_instant_article/exporter.rb
|
|
186
173
|
- lib/article_json/export/html/elements/base.rb
|
|
187
174
|
- lib/article_json/export/html/elements/embed.rb
|
|
188
175
|
- lib/article_json/export/html/elements/heading.rb
|
|
@@ -236,7 +223,6 @@ homepage: https://github.com/Devex/article_json
|
|
|
236
223
|
licenses:
|
|
237
224
|
- MIT
|
|
238
225
|
metadata: {}
|
|
239
|
-
post_install_message:
|
|
240
226
|
rdoc_options: []
|
|
241
227
|
require_paths:
|
|
242
228
|
- lib
|
|
@@ -251,8 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
251
237
|
- !ruby/object:Gem::Version
|
|
252
238
|
version: '0'
|
|
253
239
|
requirements: []
|
|
254
|
-
rubygems_version: 3.
|
|
255
|
-
signing_key:
|
|
240
|
+
rubygems_version: 3.6.9
|
|
256
241
|
specification_version: 4
|
|
257
242
|
summary: JSON Format for News Articles & Ruby Gem
|
|
258
243
|
test_files: []
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
4
|
-
#
|
|
5
|
-
# Simple script to read a JSON document and export it to Facebook Instant
|
|
6
|
-
# Article.
|
|
7
|
-
#
|
|
8
|
-
# Usage:
|
|
9
|
-
#
|
|
10
|
-
# ./bin/article_json_export_facebook.rb < my_document.json
|
|
11
|
-
#
|
|
12
|
-
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
13
|
-
|
|
14
|
-
require 'bundler/setup'
|
|
15
|
-
require_relative '../lib/article_json'
|
|
16
|
-
puts ArticleJSON::Article.from_json(ARGF.read).to_facebook_instant_article
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
module ArticleJSON
|
|
2
|
-
module Export
|
|
3
|
-
module FacebookInstantArticle
|
|
4
|
-
module Elements
|
|
5
|
-
class Base
|
|
6
|
-
include ArticleJSON::Export::Common::HTML::Elements::Base
|
|
7
|
-
|
|
8
|
-
class << self
|
|
9
|
-
# Return the module namespace this class and its subclasses are
|
|
10
|
-
# nested in
|
|
11
|
-
# @return [Module]
|
|
12
|
-
def namespace
|
|
13
|
-
ArticleJSON::Export::FacebookInstantArticle::Elements
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
# The format this exporter is returning. This is used to determine
|
|
19
|
-
# which custom element exporters should be applied from the
|
|
20
|
-
# configuration.
|
|
21
|
-
# @return [Symbol]
|
|
22
|
-
def export_format
|
|
23
|
-
:facebook_instant_article
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
module ArticleJSON
|
|
2
|
-
module Export
|
|
3
|
-
module FacebookInstantArticle
|
|
4
|
-
module Elements
|
|
5
|
-
class Embed < Base
|
|
6
|
-
include ArticleJSON::Export::Common::HTML::Elements::Shared::Caption
|
|
7
|
-
|
|
8
|
-
# Generate the embedded element node
|
|
9
|
-
# @return [Nokogiri::XML::NodeSet]
|
|
10
|
-
def export
|
|
11
|
-
create_element(:figure, class: 'op-interactive') do |figure|
|
|
12
|
-
figure.add_child(embed_node)
|
|
13
|
-
if @element.caption&.any?
|
|
14
|
-
figure.add_child(caption_node(:figcaption))
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
# Type specific object that should be embedded
|
|
22
|
-
# @return [Nokogiri::XML::Element]
|
|
23
|
-
def embed_node
|
|
24
|
-
if %i(facebook_video tweet).include? @element.embed_type.to_sym
|
|
25
|
-
iframe_node
|
|
26
|
-
else
|
|
27
|
-
embedded_object
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def iframe_node
|
|
32
|
-
create_element(:iframe) do |div|
|
|
33
|
-
div.add_child(embedded_object)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def embedded_object
|
|
38
|
-
Nokogiri::HTML.fragment(@element.oembed_data[:html])
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
module ArticleJSON
|
|
2
|
-
module Export
|
|
3
|
-
module FacebookInstantArticle
|
|
4
|
-
module Elements
|
|
5
|
-
class Quote < Base
|
|
6
|
-
include ArticleJSON::Export::Common::HTML::Elements::Quote
|
|
7
|
-
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
-
# @return [Hash]
|
|
11
|
-
def node_opts
|
|
12
|
-
{}
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# HTML tag for the wrapping node
|
|
16
|
-
# @return [Symbol]
|
|
17
|
-
def quote_tag
|
|
18
|
-
:aside
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# HTML tag for the node containing the caption
|
|
22
|
-
# @return [Symbol]
|
|
23
|
-
def caption_tag
|
|
24
|
-
:cite
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|