blog-generator 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/blog-generator/post.rb +20 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45917f716b8adb235bd224c77de901117a168a69
|
4
|
+
data.tar.gz: df11142024e55d3e0e8874fadac2ef5111e7236f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05c7bf751d666aadd87c34f28ac9b028b4538b1fdbe13911e0e6eeb7907374c5f323c2b3b20b91f5ee15f6bbf1c7e67fddaa36478e42cb9dccc73edc8f698668
|
7
|
+
data.tar.gz: db8081ab2a337d2a8659570f069bac6bf1fe9e835d9c55a95bbfc53b5d369d3bc39e0211da40d65604a7878fb01d67daa6246a606486c88ae787268f17fe80c0
|
data/README.md
CHANGED
@@ -44,6 +44,10 @@ tags: ['Hello world', 'Test']
|
|
44
44
|
<p>
|
45
45
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Soluta quibusdam necessitatibus tempore ullam incidunt amet omnis, veritatis dicta quisquam accusamus at provident vel facere corporis sed fugiat cumque. Consequuntur, necessitatibus!
|
46
46
|
</p>
|
47
|
+
|
48
|
+
<!-- This assumes assets/hello-world/hello-kitty.png -->
|
49
|
+
<img src="/assets/hello-world/hello-kitty.png" />
|
50
|
+
<caption>Hello kitty!</caption>
|
47
51
|
```
|
48
52
|
|
49
53
|
## Assumptions
|
data/lib/blog-generator/post.rb
CHANGED
@@ -73,10 +73,29 @@ module BlogGenerator
|
|
73
73
|
@body ||= begin
|
74
74
|
document = nokogiri_raw_document.dup
|
75
75
|
document.css('#excerpt').remove
|
76
|
+
document.css('img[src^="/assets/"]').each do |img|
|
77
|
+
absolute_url = img.attribute('src').value
|
78
|
+
asset_path = "..#{absolute_url}" # This is extremely shakey, it depends on us being in api.botanicus.me.
|
79
|
+
if File.exists?(asset_path)
|
80
|
+
img['src'] = image_binary_data(asset_path)
|
81
|
+
else
|
82
|
+
raise "Asset #{asset_path} doesn't exist."
|
83
|
+
end
|
84
|
+
end
|
76
85
|
document.css('body').inner_html.strip
|
77
86
|
end
|
78
87
|
end
|
79
88
|
|
89
|
+
def image_binary_data(asset_path)
|
90
|
+
require 'base64'
|
91
|
+
|
92
|
+
extension = File.extname(asset_path)[1..-1]
|
93
|
+
binary_data = File.read(asset_path)
|
94
|
+
encoded_data = Base64.encode64(binary_data)
|
95
|
+
|
96
|
+
"data:image/#{extension};base64,#{encoded_data}"
|
97
|
+
end
|
98
|
+
|
80
99
|
def excerpt
|
81
100
|
@excerpt ||= begin
|
82
101
|
document = nokogiri_raw_document.dup
|
@@ -85,7 +104,7 @@ module BlogGenerator
|
|
85
104
|
end
|
86
105
|
|
87
106
|
def as_json
|
88
|
-
@metadata.merge(body: body).tap do |metadata|
|
107
|
+
@metadata.merge(body: self.body).tap do |metadata|
|
89
108
|
metadata[:published_at] && metadata[:published_at] = DateTime.parse(metadata[:published_at])
|
90
109
|
metadata[:updated_at] && metadata[:updated_at] = DateTime.parse(metadata[:updated_at])
|
91
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blog-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James C Russell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|